Skip to content

Commit 92c3c79

Browse files
committed
Address reviews
1 parent 70a3356 commit 92c3c79

9 files changed

+106
-113
lines changed

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
3333
import aztech.modern_industrialization.machines.models.MachineModelClientData;
3434
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
35+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3536
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
3637
import aztech.modern_industrialization.util.Tickable;
3738

@@ -116,14 +117,12 @@ public void tickExtra() {
116117
}
117118

118119
@Override
119-
protected void onRematch() {
120+
protected void onRematch(ShapeMatcher shapeMatcher) {
120121
operatingState = OperatingState.NOT_MATCHED;
121-
}
122-
123-
@Override
124-
protected void onMatchSuccessful() {
125-
inventory.rebuild(shapeMatcher);
126-
operatingState = OperatingState.TRYING_TO_RESUME;
122+
if (shapeMatcher.isMatchSuccessful()) {
123+
inventory.rebuild(shapeMatcher);
124+
operatingState = OperatingState.TRYING_TO_RESUME;
125+
}
127126
}
128127

129128
private enum OperatingState {

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import aztech.modern_industrialization.machines.components.*;
2929
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
3030
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
31+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3132
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
3233
import aztech.modern_industrialization.util.Simulation;
3334
import java.util.ArrayList;
@@ -61,12 +62,13 @@ public List<EnergyComponent> getEnergyComponents() {
6162
}
6263

6364
@Override
64-
protected void onMatchSuccessful() {
65-
super.onMatchSuccessful();
66-
67-
energyInputs.clear();
68-
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
69-
hatch.appendEnergyInputs(energyInputs);
65+
protected void onRematch(ShapeMatcher shapeMatcher) {
66+
super.onRematch(shapeMatcher);
67+
if (shapeMatcher.isMatchSuccessful()) {
68+
energyInputs.clear();
69+
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
70+
hatch.appendEnergyInputs(energyInputs);
71+
}
7072
}
7173
}
7274

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import aztech.modern_industrialization.machines.models.MachineModelClientData;
3434
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
3535
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
36+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3637
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
3738
import aztech.modern_industrialization.util.Simulation;
3839
import aztech.modern_industrialization.util.Tickable;
@@ -133,18 +134,16 @@ public long insertEnergy(long value, Simulation simulation) {
133134
}
134135

135136
@Override
136-
protected void onRematch() {
137+
protected void onRematch(ShapeMatcher shapeMatcher) {
137138
allowNormalOperation = false;
138-
}
139-
140-
@Override
141-
protected void onMatchSuccessful() {
142-
inventory.rebuild(shapeMatcher);
143-
allowNormalOperation = true;
139+
if (shapeMatcher.isMatchSuccessful()) {
140+
inventory.rebuild(shapeMatcher);
141+
allowNormalOperation = true;
144142

145-
energyOutputs.clear();
146-
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
147-
hatch.appendEnergyOutputs(energyOutputs);
143+
energyOutputs.clear();
144+
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
145+
hatch.appendEnergyOutputs(energyOutputs);
146+
}
148147
}
149148
}
150149

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,16 @@ public static long getCapacityFromComponents(int xIndex, int yIndex, int zIndex)
243243
}
244244

245245
@Override
246-
protected void onMatchSuccessful() {
247-
int index = activeShape.getActiveShapeIndex();
248-
long capacity = getCapacityFromComponents(getXComponent(index), getYComponent(index), getZComponent(index));
249-
fluidStorage.setCapacity(capacity);
250-
251-
for (var hatch : shapeMatcher.getMatchedHatches()) {
252-
if (hatch instanceof LargeTankHatch tankHatch) {
253-
tankHatch.setController(this);
246+
protected void onRematch(ShapeMatcher shapeMatcher) {
247+
if (shapeMatcher.isMatchSuccessful()) {
248+
int index = activeShape.getActiveShapeIndex();
249+
long capacity = getCapacityFromComponents(getXComponent(index), getYComponent(index), getZComponent(index));
250+
fluidStorage.setCapacity(capacity);
251+
252+
for (var hatch : shapeMatcher.getMatchedHatches()) {
253+
if (hatch instanceof LargeTankHatch tankHatch) {
254+
tankHatch.setController(this);
255+
}
254256
}
255257
}
256258
}

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -130,58 +130,56 @@ public ShapeTemplate getActiveShape() {
130130
}
131131

132132
@Override
133-
protected void onRematch() {
133+
protected void onRematch(ShapeMatcher shapeMatcher) {
134134
nuclearGrid = null;
135-
}
135+
if (shapeMatcher.isMatchSuccessful()) {
136+
shapeValid.shapeValid = true;
137+
int size = gridLayout[activeShape.getActiveShapeIndex()].length;
138+
NuclearHatch[][] hatchesGrid = new NuclearHatch[size][size];
139+
140+
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
141+
int x0 = hatch.getBlockPos().getX() - getBlockPos().getX();
142+
int z0 = hatch.getBlockPos().getZ() - getBlockPos().getZ();
143+
144+
int x, y;
145+
146+
if (orientation.facingDirection == Direction.NORTH) {
147+
x = size / 2 + x0;
148+
y = z0;
149+
} else if (orientation.facingDirection == Direction.SOUTH) {
150+
x = size / 2 - x0;
151+
y = -z0;
152+
} else if (orientation.facingDirection == Direction.EAST) {
153+
x = size / 2 + z0;
154+
y = -x0;
136155

137-
@Override
138-
protected void onMatchSuccessful() {
139-
shapeValid.shapeValid = true;
140-
int size = gridLayout[activeShape.getActiveShapeIndex()].length;
141-
NuclearHatch[][] hatchesGrid = new NuclearHatch[size][size];
142-
143-
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
144-
int x0 = hatch.getBlockPos().getX() - getBlockPos().getX();
145-
int z0 = hatch.getBlockPos().getZ() - getBlockPos().getZ();
146-
147-
int x, y;
148-
149-
if (orientation.facingDirection == Direction.NORTH) {
150-
x = size / 2 + x0;
151-
y = z0;
152-
} else if (orientation.facingDirection == Direction.SOUTH) {
153-
x = size / 2 - x0;
154-
y = -z0;
155-
} else if (orientation.facingDirection == Direction.EAST) {
156-
x = size / 2 + z0;
157-
y = -x0;
156+
} else {
157+
x = size / 2 - z0;
158+
y = x0;
159+
}
158160

159-
} else {
160-
x = size / 2 - z0;
161-
y = x0;
161+
hatchesGrid[x][y] = (NuclearHatch) hatch;
162162
}
163163

164-
hatchesGrid[x][y] = (NuclearHatch) hatch;
165-
}
166-
167-
nuclearGrid = new NuclearGrid(size, size, hatchesGrid);
164+
nuclearGrid = new NuclearGrid(size, size, hatchesGrid);
168165

169-
dataSupplier = () -> {
170-
Optional<INuclearTileData>[] tilesData = new Optional[size * size];
171-
for (int i = 0; i < size; i++) {
172-
for (int j = 0; j < size; j++) {
166+
dataSupplier = () -> {
167+
Optional<INuclearTileData>[] tilesData = new Optional[size * size];
168+
for (int i = 0; i < size; i++) {
169+
for (int j = 0; j < size; j++) {
173170

174-
final int x = size - 1 - i;
175-
final int y = size - 1 - j;
171+
final int x = size - 1 - i;
172+
final int y = size - 1 - j;
176173

177-
int index = NuclearReactorGui.Data.toIndex(i, j, size);
178-
tilesData[index] = Optional.ofNullable(hatchesGrid[x][y]);
174+
int index = NuclearReactorGui.Data.toIndex(i, j, size);
175+
tilesData[index] = Optional.ofNullable(hatchesGrid[x][y]);
176+
}
179177
}
180-
}
181-
return new NuclearReactorGui.Data(true, size, size, tilesData,
182-
efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euProduction),
183-
efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euFuelConsumption));
184-
};
178+
return new NuclearReactorGui.Data(true, size, size, tilesData,
179+
efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euProduction),
180+
efficiencyHistory.getAverage(NuclearEfficiencyHistoryComponent.Type.euFuelConsumption));
181+
};
182+
}
185183
}
186184

187185
public static void registerReiShapes() {

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import aztech.modern_industrialization.machines.guicomponents.TemperatureBar;
3636
import aztech.modern_industrialization.machines.models.MachineModelClientData;
3737
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
38+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3839
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
3940
import aztech.modern_industrialization.util.Tickable;
4041
import java.util.List;
@@ -80,8 +81,10 @@ public SteamBoilerMultiblockBlockEntity(BEP bep, ShapeTemplate shapeTemplate, St
8081
}
8182

8283
@Override
83-
protected void onMatchSuccessful() {
84-
inventory.rebuild(shapeMatcher);
84+
protected void onRematch(ShapeMatcher shapeMatcher) {
85+
if (shapeMatcher.isMatchSuccessful()) {
86+
inventory.rebuild(shapeMatcher);
87+
}
8588
}
8689

8790
@Override

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
3131
import aztech.modern_industrialization.machines.helper.SteamHelper;
3232
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
33+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3334
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
3435
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
3536
import aztech.modern_industrialization.util.Simulation;
@@ -67,14 +68,15 @@ protected CrafterComponent.Behavior getBehavior() {
6768
private boolean steelTier;
6869

6970
@Override
70-
protected void onMatchSuccessful() {
71-
super.onMatchSuccessful();
72-
73-
steelTier = false;
74-
75-
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
76-
if (hatch.upgradesToSteel()) {
77-
steelTier = true;
71+
protected void onRematch(ShapeMatcher shapeMatcher) {
72+
super.onRematch(shapeMatcher);
73+
if (shapeMatcher.isMatchSuccessful()) {
74+
steelTier = false;
75+
76+
for (HatchBlockEntity hatch : shapeMatcher.getMatchedHatches()) {
77+
if (hatch.upgradesToSteel()) {
78+
steelTier = true;
79+
}
7880
}
7981
}
8082
}

src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import net.minecraft.world.InteractionHand;
3232
import net.minecraft.world.entity.player.Player;
3333
import net.minecraft.world.phys.BlockHitResult;
34+
import org.jetbrains.annotations.Nullable;
3435

3536
public abstract class MultiblockMachineBlockEntity extends MachineBlockEntity {
36-
protected ShapeMatcher shapeMatcher;
37+
@Nullable
38+
private ShapeMatcher shapeMatcher;
3739

3840
public MultiblockMachineBlockEntity(BEP bep, MachineGuiParameters guiParams, OrientationComponent.Params orientationParams) {
3941
super(bep, guiParams, orientationParams);
@@ -47,45 +49,25 @@ public boolean isShapeValid() {
4749
return shapeValid.shapeValid;
4850
}
4951

50-
public ShapeMatcher getShapeMatcher() {
51-
return shapeMatcher;
52-
}
53-
5452
public ShapeMatcher createShapeMatcher() {
5553
return new ShapeMatcher(level, worldPosition, orientation.facingDirection, getActiveShape());
5654
}
5755

58-
protected void onLink() {
59-
}
60-
61-
protected void onUnlink() {
62-
}
63-
64-
protected void onRematch() {
65-
}
66-
67-
protected void onMatchSuccessful() {
68-
}
69-
70-
protected void onMatchFailure() {
56+
protected void onRematch(ShapeMatcher shapeMatcher) {
7157
}
7258

73-
protected void link() {
59+
protected final void link() {
7460
if (shapeMatcher == null) {
7561
shapeMatcher = createShapeMatcher();
7662
shapeMatcher.registerListeners(level);
77-
onLink();
7863
}
7964
if (shapeMatcher.needsRematch()) {
8065
shapeValid.shapeValid = false;
8166
shapeMatcher.rematch(level);
82-
onRematch();
67+
onRematch(shapeMatcher);
8368

8469
if (shapeMatcher.isMatchSuccessful()) {
85-
onMatchSuccessful();
8670
shapeValid.shapeValid = true;
87-
} else {
88-
onMatchFailure();
8971
}
9072

9173
if (shapeValid.update()) {
@@ -94,11 +76,10 @@ protected void link() {
9476
}
9577
}
9678

97-
public void unlink() {
79+
public final void unlink() {
9880
if (shapeMatcher != null) {
9981
shapeMatcher.unlinkHatches();
10082
shapeMatcher.unregisterListeners(level);
101-
onUnlink();
10283
shapeMatcher = null;
10384
}
10485
}

src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public ShapeMatcher(Level world, BlockPos controllerPos, Direction controllerDir
5252
protected final Map<BlockPos, SimpleMember> simpleMembers;
5353
protected final Map<BlockPos, HatchFlags> hatchFlags;
5454

55-
protected boolean needsRematch = true;
56-
protected boolean matchSuccessful = false;
57-
protected final List<HatchBlockEntity> matchedHatches = new ArrayList<>();
55+
private boolean needsRematch = true;
56+
private boolean matchSuccessful = false;
57+
private final List<HatchBlockEntity> matchedHatches = new ArrayList<>();
5858

5959
/**
6060
* Convert a relative position in the shape template to the real position in the
@@ -143,6 +143,10 @@ public boolean isMatchSuccessful() {
143143
return matchSuccessful && !needsRematch;
144144
}
145145

146+
protected boolean checkRematch(Level world) {
147+
return true;
148+
}
149+
146150
public void rematch(Level world) {
147151
unlinkHatches();
148152
matchSuccessful = true;
@@ -154,6 +158,9 @@ public void rematch(Level world) {
154158
matchSuccessful = false;
155159
}
156160
}
161+
if (!checkRematch(world)) {
162+
matchSuccessful = false;
163+
}
157164

158165
if (!matchSuccessful) {
159166
matchedHatches.clear();

0 commit comments

Comments
 (0)