Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
import aztech.modern_industrialization.machines.models.MachineModelClientData;
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
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 {
Expand All @@ -56,17 +54,13 @@ 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;
protected final MultiblockInventoryComponent inventory;
protected final CrafterComponent crafter;
private final IsActiveComponent isActive;

protected abstract void onSuccessfulMatch(ShapeMatcher shapeMatcher);

public ShapeTemplate getActiveShape() {
return activeShape.getActiveShape();
}
Expand Down Expand Up @@ -121,37 +115,15 @@ 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
protected void onRematch() {
operatingState = OperatingState.NOT_MATCHED;
}

@Override
public final void unlink() {
if (shapeMatcher != null) {
shapeMatcher.unlinkHatches();
shapeMatcher.unregisterListeners(level);
shapeMatcher = null;
}
protected void onMatchSuccessful() {
inventory.rebuild(shapeMatcher);
operatingState = OperatingState.TRYING_TO_RESUME;
}

private enum OperatingState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import aztech.modern_industrialization.machines.components.*;
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
import aztech.modern_industrialization.util.Simulation;
import java.util.ArrayList;
Expand Down Expand Up @@ -62,7 +61,9 @@ public List<EnergyComponent> getEnergyComponents() {
}

@Override
protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) {
protected void onMatchSuccessful() {
super.onMatchSuccessful();

energyInputs.clear();
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
hatch.appendEnergyInputs(energyInputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
import aztech.modern_industrialization.machines.models.MachineModelClientData;
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
import aztech.modern_industrialization.util.Simulation;
import aztech.modern_industrialization.util.Tickable;
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 {
Expand All @@ -64,8 +62,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;
Expand All @@ -89,13 +85,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;
Expand Down Expand Up @@ -143,36 +132,19 @@ 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
protected void onRematch() {
allowNormalOperation = false;
}

@Override
public final void unlink() {
if (shapeMatcher != null) {
shapeMatcher.unlinkHatches();
shapeMatcher.unregisterListeners(level);
shapeMatcher = null;
protected void onMatchSuccessful() {
inventory.rebuild(shapeMatcher);
allowNormalOperation = true;

energyOutputs.clear();
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
hatch.appendEnergyOutputs(energyOutputs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -275,7 +242,8 @@ public static long getCapacityFromComponents(int xIndex, int yIndex, int zIndex)
return volume * BUCKET_PER_STRUCTURE_BLOCK * FluidType.BUCKET_VOLUME;
}

private void onMatchSuccessful() {
@Override
protected void onMatchSuccessful() {
int index = activeShape.getActiveShapeIndex();
long capacity = getCapacityFromComponents(getXComponent(index), getYComponent(index), getZComponent(index));
fluidStorage.setCapacity(capacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NuclearReactorGui.Data> dataSupplier;
Expand Down Expand Up @@ -125,7 +124,18 @@ public void tick() {
}
}

protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) {
@Override
public ShapeTemplate getActiveShape() {
return activeShape.getActiveShape();
}

@Override
protected void onRematch() {
nuclearGrid = null;
}

@Override
protected void onMatchSuccessful() {
shapeValid.shapeValid = true;
int size = gridLayout[activeShape.getActiveShapeIndex()].length;
NuclearHatch[][] hatchesGrid = new NuclearHatch[size][size];
Expand Down Expand Up @@ -174,41 +184,6 @@ protected void onSuccessfulMatch(ShapeMatcher shapeMatcher) {
};
}

@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;
}
}

public static void registerReiShapes() {
for (int i = 0; i < shapeTemplates.length; ++i) {
ReiMachineRecipes.registerMultiblockShape("nuclear_reactor", shapeTemplates[i], "" + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import aztech.modern_industrialization.machines.guicomponents.TemperatureBar;
import aztech.modern_industrialization.machines.models.MachineModelClientData;
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
import aztech.modern_industrialization.util.Tickable;
import java.util.List;
Expand All @@ -44,7 +43,6 @@

public class SteamBoilerMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable {

private ShapeMatcher shapeMatcher;
private final ShapeTemplate shapeTemplate;
private final IsActiveComponent isActiveComponent;
private final RedstoneControlComponent redstoneControl;
Expand Down Expand Up @@ -81,33 +79,9 @@ 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 onMatchSuccessful() {
inventory.rebuild(shapeMatcher);
}

@Override
Expand Down
Loading
Loading