Skip to content

Commit

Permalink
Move Zeta-pertinent mixins, make the piston structure resolver a Zeta…
Browse files Browse the repository at this point in the history
… global
  • Loading branch information
quat1024 committed Nov 5, 2023
1 parent dd6886e commit af360dd
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 66 deletions.
14 changes: 12 additions & 2 deletions src/main/java/vazkii/quark/base/handler/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import com.google.common.collect.Lists;

import vazkii.quark.base.Quark;
import vazkii.quark.base.module.config.Config;
import vazkii.zeta.event.ZConfigChanged;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.piston.ZetaPistonStructureResolver;

public class GeneralConfig {

Expand Down Expand Up @@ -49,10 +53,10 @@ public class GeneralConfig {
public static boolean useAntiOverlap = true;

@Config(name = "Use Piston Logic Replacement",
description = "Quark replaces the Piston logic to allow for its piston features to work. If you're having troubles, try turning this off.")
description = "Enable Zeta's piston structure resolver, needed for some Quark features. If you're having troubles, try turning this off, but be aware other Zeta-using mods can enable it too.")
public static boolean usePistonLogicRepl = true;

@Config
@Config(description = "Ask Zeta to set the piston push limit. Only has an effect if Zeta's piston structure resolver is in use.")
@Config.Min(value = 0, exclusive = true)
public static int pistonPushLimit = 12;

Expand Down Expand Up @@ -122,4 +126,10 @@ public static boolean isScreenAllowed(Object screen) {
return allowedScreens.contains(clazz) != useScreenListBlacklist;
}

@LoadEvent
public static void configChanged(ZConfigChanged e) {
ZetaPistonStructureResolver.GlobalSettings.requestEnabled(Quark.MOD_ID, usePistonLogicRepl);
ZetaPistonStructureResolver.GlobalSettings.requestPushLimit(Quark.MOD_ID, pistonPushLimit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.Material;
import vazkii.quark.api.ICollateralMover;
import vazkii.zeta.api.ICollateralMover;
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.quark.base.handler.CreativeTabHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChainBlock;
import net.minecraft.world.level.block.state.BlockState;
import vazkii.quark.api.IIndirectConnector;
import vazkii.zeta.api.IIndirectConnector;
import vazkii.quark.base.module.LoadModule;
import vazkii.zeta.module.ZetaModule;
import vazkii.zeta.util.Hint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.quark.api.IIndirectConnector;
import vazkii.zeta.api.IIndirectConnector;
import vazkii.quark.api.IPistonCallback;
import vazkii.quark.api.QuarkCapabilities;
import vazkii.quark.base.Quark;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.quark.base.module.LoadModule;
import vazkii.quark.base.module.ModuleLoader;
import vazkii.zeta.module.ZetaModule;
Expand All @@ -36,6 +35,7 @@
import vazkii.zeta.event.ZRegister;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.event.bus.PlayEvent;
import vazkii.zeta.piston.ZetaPistonStructureResolver;

import javax.annotation.Nullable;
import java.util.*;
Expand Down Expand Up @@ -96,8 +96,8 @@ public void addAdditionalHints(ZGatherHints consumer) {
if(ModuleLoader.INSTANCE.isModuleEnabled(SturdyStoneModule.class))
comp = comp.append(" ").append(Component.translatable("quark.jei.hint.piston_sturdy"));

if(GeneralConfig.pistonPushLimit != 12)
comp = comp.append(" ").append(Component.translatable("quark.jei.hint.piston_max_blocks", GeneralConfig.pistonPushLimit));
if(ZetaPistonStructureResolver.GlobalSettings.getPushLimit() != 12)
comp = comp.append(" ").append(Component.translatable("quark.jei.hint.piston_max_blocks", ZetaPistonStructureResolver.GlobalSettings.getPushLimit()));

consumer.accept(Items.PISTON, comp);
consumer.accept(Items.STICKY_PISTON, comp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeatheringCopper;
import net.minecraft.world.level.block.state.BlockState;
import vazkii.quark.base.block.CustomWeatheringCopper;
import vazkii.zeta.block.CustomWeatheringCopper;
import vazkii.zeta.module.ZetaModule;

public class WeatheringCopperVerticalSlabBlock extends QuarkVerticalSlabBlock implements CustomWeatheringCopper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.quark.api.IIndirectConnector;
import vazkii.zeta.api.IIndirectConnector;
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.QuarkInheritedPaneBlock;
import vazkii.quark.base.handler.ToolInteractionHandler;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/vazkii/quark/mixin/PistonBaseBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import vazkii.quark.base.handler.QuarkPistonStructureResolver;
import vazkii.quark.content.automation.module.PistonsMoveTileEntitiesModule;
import vazkii.quark.content.experimental.module.GameNerfsModule;

Expand All @@ -33,11 +32,6 @@ private void moveBlocks(Level worldIn, BlockPos pos, Direction directionIn, bool
PistonsMoveTileEntitiesModule.detachTileEntities(worldIn, pistonBlockStructureHelper, directionIn, extending);
}

@ModifyExpressionValue(method = {"checkIfExtend", "moveBlocks"}, at = @At(value = "NEW", target = "net/minecraft/world/level/block/piston/PistonStructureResolver"))
private PistonStructureResolver transformStructureHelper(PistonStructureResolver prev) {
return new QuarkPistonStructureResolver(prev);
}

@ModifyVariable(method = "moveBlocks", at = @At(value = "STORE", ordinal = 0), index = 15, ordinal = 2, slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addDestroyBlockEffect(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V"), to = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/piston/MovingPistonBlock;newMovingBlockEntity(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;ZZ)Lnet/minecraft/world/level/block/entity/BlockEntity;")))
private BlockPos storeOldPos(BlockPos pos, @Share("oldPos") LocalRef<BlockPos> oldPos) {
oldPos.set(pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.mixin.accessor;
package vazkii.quark.mixin.zeta;

import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
Expand All @@ -11,6 +11,6 @@
public interface AccessorLootTable {

@Accessor("pools")
List<LootPool> quark$getPools();
List<LootPool> zeta$getPools();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.mixin.accessor;
package vazkii.quark.mixin.zeta;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -11,14 +11,14 @@
public interface AccessorPistonStructureResolver {

@Accessor("extending")
boolean quark$extending();
boolean zeta$extending();

@Accessor("level")
Level quark$level();
Level zeta$level();

@Accessor("pistonPos")
BlockPos quark$pistonPos();
BlockPos zeta$pistonPos();

@Accessor("pistonDirection")
Direction quark$pistonDirection();
Direction zeta$pistonDirection();
}
16 changes: 16 additions & 0 deletions src/main/java/vazkii/quark/mixin/zeta/PistonBaseBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package vazkii.quark.mixin.zeta;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.world.level.block.piston.PistonBaseBlock;
import net.minecraft.world.level.block.piston.PistonStructureResolver;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import vazkii.zeta.piston.ZetaPistonStructureResolver;

@Mixin(PistonBaseBlock.class)
public class PistonBaseBlockMixin {
@ModifyExpressionValue(method = {"checkIfExtend", "moveBlocks"}, at = @At(value = "NEW", target = "net/minecraft/world/level/block/piston/PistonStructureResolver"))
private PistonStructureResolver transformStructureHelper(PistonStructureResolver prev) {
return new ZetaPistonStructureResolver(prev);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.mixin;
package vazkii.quark.mixin.zeta_forge;

import net.minecraft.world.level.block.WeatheringCopper;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,4 +15,6 @@
})
public interface WeatheringCopperMixin {
// Delegated. Only valid because WeatheringCopper members are not refmapped.

//TODO ZETA: use a real interface mixin on Fabric
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.mixin.client.accessor;
package vazkii.quark.mixin.zeta_forge.client;

import java.util.Map;

Expand All @@ -14,6 +14,6 @@
public interface AccessorBlockColors {

@Accessor("blockColors")
Map<Reference<Block>, BlockColor> quark$getBlockColors();
Map<Reference<Block>, BlockColor> zeta$getBlockColors();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.mixin.client.accessor;
package vazkii.quark.mixin.zeta_forge.client;

import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.color.item.ItemColors;
Expand All @@ -13,6 +13,6 @@
public interface AccessorItemColors {

@Accessor("itemColors")
Map<Reference<Item>, ItemColor> quark$getItemColors();
Map<Reference<Item>, ItemColor> zeta$getItemColors();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package vazkii.quark.mixinsupport.delegates;

import net.minecraft.world.level.block.state.BlockState;
import vazkii.quark.base.block.CustomWeatheringCopper;
import vazkii.zeta.block.CustomWeatheringCopper;
import vazkii.quark.mixinsupport.DelegateInterfaceTarget;
import vazkii.quark.mixinsupport.DelegateReturnValueTarget;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/vazkii/zeta/Zeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.phys.BlockHitResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import vazkii.zeta.registry.BrewingRegistry;
Expand All @@ -40,6 +41,8 @@
* do not touch forge OR quark from this package, it will later be split off
*/
public abstract class Zeta {
public static final Logger GLOBAL_LOG = LogManager.getLogger("zeta");

public Zeta(String modid, Logger log, ZetaSide side) {
this.log = log;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.api;
package vazkii.zeta.api;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.api;
package vazkii.zeta.api;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.api;
package vazkii.zeta.api;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vazkii.quark.base.block;
package vazkii.zeta.block;

import net.minecraft.world.level.block.WeatheringCopper;
import net.minecraft.world.level.block.state.BlockState;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/vazkii/zeta/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ public ConfigManager(Zeta z, Object rootPojo) {
this.z = z;
this.cfm = new ConfigFlagManager(z);

//TODO: where to put this lol
z.loadBus.subscribe(rootPojo).subscribe(rootPojo.getClass());
z.playBus.subscribe(rootPojo).subscribe(rootPojo.getClass());

ZetaModuleManager modules = z.modules;

//all modules are enabled by default
enabledCategories.addAll(modules.getCategories());
//TODO: track module enablement too with a hashset too?

this.rootConfig = new SectionDefinition("root", List.of());

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vazkii/zeta/event/ZLootTableLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTables;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import vazkii.quark.mixin.accessor.AccessorLootTable;
import vazkii.quark.mixin.zeta.AccessorLootTable;
import vazkii.zeta.event.bus.Cancellable;
import vazkii.zeta.event.bus.IZetaPlayEvent;

Expand All @@ -19,7 +19,7 @@ public interface ZLootTableLoad extends IZetaPlayEvent, Cancellable {
default void add(LootPoolEntryContainer entry) {
LootTable table = getTable();

List<LootPool> pools = ((AccessorLootTable) table).quark$getPools();
List<LootPool> pools = ((AccessorLootTable) table).zeta$getPools();
if (pools != null && !pools.isEmpty()) {
LootPool firstPool = pools.get(0);
LootPoolEntryContainer[] entries = firstPool.entries;
Expand Down
Loading

0 comments on commit af360dd

Please sign in to comment.