diff --git a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java index 444552bf4..f2a990bd5 100644 --- a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java +++ b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java @@ -54,7 +54,7 @@ public void render(MultiblockMachineBlockEntity be, float tickDelta, PoseStack m boolean drawHighlights = isHoldingWrench() && !be.isShapeValid(); HatchType hatchType = getHeldHatchType(); if (drawHighlights || hatchType != null) { - ShapeMatcher matcher = new ShapeMatcher(be.getLevel(), be.getBlockPos(), be.getOrientation().facingDirection, be.getActiveShape()); + ShapeMatcher matcher = be.createShapeMatcher(); for (BlockPos pos : matcher.getPositions()) { matrices.pushPose(); diff --git a/src/main/java/aztech/modern_industrialization/debug/DebugCommands.java b/src/main/java/aztech/modern_industrialization/debug/DebugCommands.java index 6cdebe4c7..204a08ef9 100644 --- a/src/main/java/aztech/modern_industrialization/debug/DebugCommands.java +++ b/src/main/java/aztech/modern_industrialization/debug/DebugCommands.java @@ -33,7 +33,6 @@ import aztech.modern_industrialization.MIConfig; import aztech.modern_industrialization.machines.MachineBlockEntity; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; import aztech.modern_industrialization.pipes.MIPipes; import aztech.modern_industrialization.pipes.api.PipeNetworkType; import aztech.modern_industrialization.pipes.impl.PipeNetworks; @@ -175,7 +174,7 @@ private static int buildMultiblock(CommandSourceStack src, BlockPos controllerPo var be = src.getLevel().getBlockEntity(controllerPos); if (be instanceof MultiblockMachineBlockEntity multiblock) { var shape = multiblock.getActiveShape(); - var shapeMatcher = new ShapeMatcher(src.getLevel(), controllerPos, multiblock.orientation.facingDirection, shape); + var shapeMatcher = multiblock.createShapeMatcher(); int updatedBlocks = shapeMatcher.buildMultiblock(src.getLevel()); src.sendSuccess(() -> Component.literal("Successfully built multiblock at position %s. %d blocks updated.".formatted( diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java index 530d0b7ae..dc9e3440e 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java @@ -35,7 +35,6 @@ import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; import aztech.modern_industrialization.util.Tickable; -import org.jetbrains.annotations.Nullable; public abstract class AbstractCraftingMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable, MultiblockInventoryComponentHolder, CrafterComponentHolder { @@ -56,8 +55,6 @@ public AbstractCraftingMultiblockBlockEntity(BEP bep, String name, OrientationCo */ protected abstract CrafterComponent.Behavior getBehavior(); - @Nullable - private ShapeMatcher shapeMatcher = null; private OperatingState operatingState = OperatingState.NOT_MATCHED; protected final ActiveShapeComponent activeShape; @@ -65,8 +62,6 @@ public AbstractCraftingMultiblockBlockEntity(BEP bep, String name, OrientationCo protected final CrafterComponent crafter; private final IsActiveComponent isActive; - protected abstract void onSuccessfulMatch(ShapeMatcher shapeMatcher); - public ShapeTemplate getActiveShape() { return activeShape.getActiveShape(); } @@ -121,36 +116,12 @@ public void tickExtra() { } - protected final void link() { - if (shapeMatcher == null) { - shapeMatcher = new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape()); - shapeMatcher.registerListeners(level); - } - if (shapeMatcher.needsRematch()) { - operatingState = OperatingState.NOT_MATCHED; - shapeValid.shapeValid = false; - shapeMatcher.rematch(level); - - if (shapeMatcher.isMatchSuccessful()) { - inventory.rebuild(shapeMatcher); - - onSuccessfulMatch(shapeMatcher); - shapeValid.shapeValid = true; - operatingState = OperatingState.TRYING_TO_RESUME; - } - - if (shapeValid.update()) { - sync(false); - } - } - } - @Override - public final void unlink() { - if (shapeMatcher != null) { - shapeMatcher.unlinkHatches(); - shapeMatcher.unregisterListeners(level); - shapeMatcher = null; + protected void onRematch(ShapeMatcher shapeMatcher) { + operatingState = OperatingState.NOT_MATCHED; + if (shapeMatcher.isMatchSuccessful()) { + inventory.rebuild(shapeMatcher); + operatingState = OperatingState.TRYING_TO_RESUME; } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java index a586487c6..5b8a8b0b4 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java @@ -62,10 +62,13 @@ public List getEnergyComponents() { } @Override - protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) { - energyInputs.clear(); - for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { - hatch.appendEnergyInputs(energyInputs); + protected void onRematch(ShapeMatcher shapeMatcher) { + super.onRematch(shapeMatcher); + if (shapeMatcher.isMatchSuccessful()) { + energyInputs.clear(); + for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { + hatch.appendEnergyInputs(energyInputs); + } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java index 9e06f5b13..b190f1f0d 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java @@ -40,7 +40,6 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.Nullable; public class GeneratorMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable, EnergyListComponentHolder, MultiblockInventoryComponentHolder { @@ -64,8 +63,6 @@ public GeneratorMultiblockBlockEntity(BEP bep, registerGuiComponent(new SlotPanel.Server(this).withRedstoneControl(redstoneControl)); } - @Nullable - private ShapeMatcher shapeMatcher = null; private boolean allowNormalOperation = false; private final ActiveShapeComponent activeShape; @@ -89,13 +86,6 @@ public MultiblockInventoryComponent getMultiblockInventoryComponent() { return inventory; } - protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) { - energyOutputs.clear(); - for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { - hatch.appendEnergyOutputs(energyOutputs); - } - } - @Override public final MIInventory getInventory() { return MIInventory.EMPTY; @@ -141,36 +131,17 @@ public long insertEnergy(long value, Simulation simulation) { return inserted; } - protected final void link() { - if (shapeMatcher == null) { - shapeMatcher = new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape()); - shapeMatcher.registerListeners(level); - } - if (shapeMatcher.needsRematch()) { - allowNormalOperation = false; - shapeValid.shapeValid = false; - shapeMatcher.rematch(level); - - if (shapeMatcher.isMatchSuccessful()) { - inventory.rebuild(shapeMatcher); - - onSuccessfulMatch(shapeMatcher); - shapeValid.shapeValid = true; - allowNormalOperation = true; - } - - if (shapeValid.update()) { - sync(false); - } - } - } - @Override - public final void unlink() { - if (shapeMatcher != null) { - shapeMatcher.unlinkHatches(); - shapeMatcher.unregisterListeners(level); - shapeMatcher = null; + protected void onRematch(ShapeMatcher shapeMatcher) { + allowNormalOperation = false; + if (shapeMatcher.isMatchSuccessful()) { + inventory.rebuild(shapeMatcher); + allowNormalOperation = true; + + energyOutputs.clear(); + for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { + hatch.appendEnergyOutputs(energyOutputs); + } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java index b34af8ff4..c1a3d7da1 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java @@ -54,7 +54,6 @@ import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.fluids.capability.templates.EmptyFluidHandler; -import org.jetbrains.annotations.Nullable; public class LargeTankMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable, FluidStorageComponentHolder { @@ -148,9 +147,6 @@ private static ShapeTemplate buildShape(int index) { return templateBuilder.build(); } - @Nullable - private ShapeMatcher shapeMatcher = null; - private final ActiveShapeComponent activeShape; private final FluidStorageComponent fluidStorage; @@ -226,35 +222,6 @@ protected MachineModelClientData getMachineModelData() { } - protected final void link() { - if (shapeMatcher == null) { - shapeMatcher = new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape()); - shapeMatcher.registerListeners(level); - } - if (shapeMatcher.needsRematch()) { - shapeValid.shapeValid = false; - shapeMatcher.rematch(level); - - if (shapeMatcher.isMatchSuccessful()) { - shapeValid.shapeValid = true; - onMatchSuccessful(); - } - - if (shapeValid.update()) { - sync(false); - } - } - } - - @Override - public final void unlink() { - if (shapeMatcher != null) { - shapeMatcher.unlinkHatches(); - shapeMatcher.unregisterListeners(level); - shapeMatcher = null; - } - } - @Override public void tick() { if (!level.isClientSide) { @@ -275,14 +242,17 @@ public static long getCapacityFromComponents(int xIndex, int yIndex, int zIndex) return volume * BUCKET_PER_STRUCTURE_BLOCK * FluidType.BUCKET_VOLUME; } - private void onMatchSuccessful() { - int index = activeShape.getActiveShapeIndex(); - long capacity = getCapacityFromComponents(getXComponent(index), getYComponent(index), getZComponent(index)); - fluidStorage.setCapacity(capacity); - - for (var hatch : shapeMatcher.getMatchedHatches()) { - if (hatch instanceof LargeTankHatch tankHatch) { - tankHatch.setController(this); + @Override + protected void onRematch(ShapeMatcher shapeMatcher) { + if (shapeMatcher.isMatchSuccessful()) { + int index = activeShape.getActiveShapeIndex(); + long capacity = getCapacityFromComponents(getXComponent(index), getYComponent(index), getZComponent(index)); + fluidStorage.setCapacity(capacity); + + for (var hatch : shapeMatcher.getMatchedHatches()) { + if (hatch instanceof LargeTankHatch tankHatch) { + tankHatch.setController(this); + } } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java index c383de415..8f796720a 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java @@ -58,7 +58,6 @@ public class NuclearReactorMultiblockBlockEntity extends MultiblockMachineBlockE private final RedstoneControlComponent redstoneControl; private final IsActiveComponent isActive; private final NuclearEfficiencyHistoryComponent efficiencyHistory; - private ShapeMatcher shapeMatcher; private NuclearGrid nuclearGrid; private Supplier dataSupplier; @@ -125,87 +124,61 @@ public void tick() { } } - protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) { - shapeValid.shapeValid = true; - int size = gridLayout[activeShape.getActiveShapeIndex()].length; - NuclearHatch[][] hatchesGrid = new NuclearHatch[size][size]; - - for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { - int x0 = hatch.getBlockPos().getX() - getBlockPos().getX(); - int z0 = hatch.getBlockPos().getZ() - getBlockPos().getZ(); + @Override + public ShapeTemplate getActiveShape() { + return activeShape.getActiveShape(); + } - int x, y; + @Override + protected void onRematch(ShapeMatcher shapeMatcher) { + nuclearGrid = null; + if (shapeMatcher.isMatchSuccessful()) { + shapeValid.shapeValid = true; + int size = gridLayout[activeShape.getActiveShapeIndex()].length; + NuclearHatch[][] hatchesGrid = new NuclearHatch[size][size]; + + for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { + int x0 = hatch.getBlockPos().getX() - getBlockPos().getX(); + int z0 = hatch.getBlockPos().getZ() - getBlockPos().getZ(); + + int x, y; + + if (orientation.facingDirection == Direction.NORTH) { + x = size / 2 + x0; + y = z0; + } else if (orientation.facingDirection == Direction.SOUTH) { + x = size / 2 - x0; + y = -z0; + } else if (orientation.facingDirection == Direction.EAST) { + x = size / 2 + z0; + y = -x0; - if (orientation.facingDirection == Direction.NORTH) { - x = size / 2 + x0; - y = z0; - } else if (orientation.facingDirection == Direction.SOUTH) { - x = size / 2 - x0; - y = -z0; - } else if (orientation.facingDirection == Direction.EAST) { - x = size / 2 + z0; - y = -x0; + } else { + x = size / 2 - z0; + y = x0; + } - } else { - x = size / 2 - z0; - y = x0; + hatchesGrid[x][y] = (NuclearHatch) hatch; } - hatchesGrid[x][y] = (NuclearHatch) hatch; - } - - nuclearGrid = new NuclearGrid(size, size, hatchesGrid); + nuclearGrid = new NuclearGrid(size, size, hatchesGrid); - dataSupplier = () -> { - Optional[] tilesData = new Optional[size * size]; - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { + dataSupplier = () -> { + Optional[] tilesData = new Optional[size * size]; + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { - final int x = size - 1 - i; - final int y = size - 1 - j; + final int x = size - 1 - i; + final int y = size - 1 - j; - int index = NuclearReactorGui.Data.toIndex(i, j, size); - tilesData[index] = Optional.ofNullable(hatchesGrid[x][y]); + int index = NuclearReactorGui.Data.toIndex(i, j, size); + tilesData[index] = Optional.ofNullable(hatchesGrid[x][y]); + } } - } - return new NuclearReactorGui.Data(true, size, size, tilesData, - efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euProduction), - efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euFuelConsumption)); - }; - } - - @Override - public ShapeTemplate getActiveShape() { - return activeShape.getActiveShape(); - } - - protected final void link() { - if (shapeMatcher == null) { - shapeMatcher = new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape()); - shapeMatcher.registerListeners(level); - } - if (shapeMatcher.needsRematch()) { - shapeValid.shapeValid = false; - nuclearGrid = null; - shapeMatcher.rematch(level); - - if (shapeMatcher.isMatchSuccessful()) { - shapeValid.shapeValid = true; - onSuccessfulMatch(shapeMatcher); - } - - if (shapeValid.update()) { - sync(false); - } - } - } - - @Override - public final void unlink() { - if (shapeMatcher != null) { - shapeMatcher.unlinkHatches(); - shapeMatcher.unregisterListeners(level); - shapeMatcher = null; + return new NuclearReactorGui.Data(true, size, size, tilesData, + efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euProduction), + efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euFuelConsumption)); + }; } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java index 418e1ef49..51d1ec414 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java @@ -44,7 +44,6 @@ public class SteamBoilerMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable { - private ShapeMatcher shapeMatcher; private final ShapeTemplate shapeTemplate; private final IsActiveComponent isActiveComponent; private final RedstoneControlComponent redstoneControl; @@ -81,32 +80,10 @@ public SteamBoilerMultiblockBlockEntity(BEP bep, ShapeTemplate shapeTemplate, St } - protected final void link() { - if (shapeMatcher == null) { - shapeMatcher = new ShapeMatcher(level, worldPosition, orientation.facingDirection, shapeTemplate); - shapeMatcher.registerListeners(level); - } - if (shapeMatcher.needsRematch()) { - shapeValid.shapeValid = false; - shapeMatcher.rematch(level); - - if (shapeMatcher.isMatchSuccessful()) { - inventory.rebuild(shapeMatcher); - shapeValid.shapeValid = true; - } - - if (shapeValid.update()) { - sync(false); - } - } - } - @Override - public final void unlink() { - if (shapeMatcher != null) { - shapeMatcher.unlinkHatches(); - shapeMatcher.unregisterListeners(level); - shapeMatcher = null; + protected void onRematch(ShapeMatcher shapeMatcher) { + if (shapeMatcher.isMatchSuccessful()) { + inventory.rebuild(shapeMatcher); } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java index 69cf0c6aa..025d6c755 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java @@ -68,12 +68,15 @@ protected CrafterComponent.Behavior getBehavior() { private boolean steelTier; @Override - protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) { - steelTier = false; - - for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { - if (hatch.upgradesToSteel()) { - steelTier = true; + protected void onRematch(ShapeMatcher shapeMatcher) { + super.onRematch(shapeMatcher); + if (shapeMatcher.isMatchSuccessful()) { + steelTier = false; + + for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) { + if (hatch.upgradesToSteel()) { + steelTier = true; + } } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java index d68a51de4..9d5a43bf9 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java @@ -31,8 +31,12 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; public abstract class MultiblockMachineBlockEntity extends MachineBlockEntity { + @Nullable + private ShapeMatcher shapeMatcher; + public MultiblockMachineBlockEntity(BEP bep, MachineGuiParameters guiParams, OrientationComponent.Params orientationParams) { super(bep, guiParams, orientationParams); this.shapeValid = new ShapeValidComponent(); @@ -45,7 +49,40 @@ public boolean isShapeValid() { return shapeValid.shapeValid; } - public abstract void unlink(); + public ShapeMatcher createShapeMatcher() { + return new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape()); + } + + protected void onRematch(ShapeMatcher shapeMatcher) { + } + + protected final void link() { + if (shapeMatcher == null) { + shapeMatcher = createShapeMatcher(); + shapeMatcher.registerListeners(level); + } + if (shapeMatcher.needsRematch()) { + shapeValid.shapeValid = false; + shapeMatcher.rematch(level); + onRematch(shapeMatcher); + + if (shapeMatcher.isMatchSuccessful()) { + shapeValid.shapeValid = true; + } + + if (shapeValid.update()) { + sync(false); + } + } + } + + public final void unlink() { + if (shapeMatcher != null) { + shapeMatcher.unlinkHatches(); + shapeMatcher.unregisterListeners(level); + shapeMatcher = null; + } + } @Override public boolean useWrench(Player player, InteractionHand hand, BlockHitResult hitResult) { @@ -59,7 +96,7 @@ public boolean useWrench(Player player, InteractionHand hand, BlockHitResult hit } @Override - public final void setRemoved() { + public void setRemoved() { super.setRemoved(); if (!level.isClientSide) { unlink(); diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java index f8c8eae8f..23dfae24b 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java @@ -47,10 +47,10 @@ public ShapeMatcher(Level world, BlockPos controllerPos, Direction controllerDir this.hatchFlags = toWorldPos(controllerPos, controllerDirection, template.hatchFlags); } - private final BlockPos controllerPos; - private final ShapeTemplate template; - private final Map simpleMembers; - private final Map hatchFlags; + protected final BlockPos controllerPos; + protected final ShapeTemplate template; + protected final Map simpleMembers; + protected final Map hatchFlags; private boolean needsRematch = true; private boolean matchSuccessful = false; @@ -73,7 +73,7 @@ else if (controllerDirection == EAST) return rotatedPos.offset(controllerPos); } - private static Map toWorldPos(BlockPos controllerPos, Direction controllerDirection, Map templateMap) { + protected static Map toWorldPos(BlockPos controllerPos, Direction controllerDirection, Map templateMap) { Map result = new HashMap<>(); for (Map.Entry entry : templateMap.entrySet()) { result.put(toWorldPos(controllerPos, controllerDirection, entry.getKey()), entry.getValue()); @@ -143,6 +143,10 @@ public boolean isMatchSuccessful() { return matchSuccessful && !needsRematch; } + protected boolean checkRematch(Level world) { + return true; + } + public void rematch(Level world) { unlinkHatches(); matchSuccessful = true; @@ -154,6 +158,9 @@ public void rematch(Level world) { matchSuccessful = false; } } + if (!checkRematch(world)) { + matchSuccessful = false; + } if (!matchSuccessful) { matchedHatches.clear();