Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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 {
Expand All @@ -56,17 +55,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,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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ public List<EnergyComponent> 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);
}
}
}

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

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,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);
}
}
}
}
Expand Down
Loading
Loading