Skip to content

Commit 013ba88

Browse files
Fix pattern buffer test (#4562)
Co-authored-by: Gustavo <77560533+gustovafing@users.noreply.github.com>
1 parent 963d514 commit 013ba88

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import lombok.Setter;
7070
import org.jetbrains.annotations.Nullable;
7171
import org.jetbrains.annotations.UnmodifiableView;
72+
import org.jetbrains.annotations.VisibleForTesting;
7273

7374
import java.util.ArrayList;
7475
import java.util.Collections;
@@ -249,7 +250,8 @@ private void refundAll(ClickData clickData) {
249250
}
250251
}
251252

252-
private void onPatternChange(int index) {
253+
@VisibleForTesting
254+
public void onPatternChange(int index) {
253255
if (isRemote()) return;
254256

255257
// remove old if applicable

src/test/java/com/gregtechceu/gtceu/common/cover/AdvancedDetectorCoverTest.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22

33
import com.gregtechceu.gtceu.GTCEu;
44
import com.gregtechceu.gtceu.api.capability.IWorkable;
5+
import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability;
6+
import com.gregtechceu.gtceu.api.capability.recipe.IO;
57
import com.gregtechceu.gtceu.api.machine.MetaMachine;
8+
import com.gregtechceu.gtceu.api.machine.SimpleTieredMachine;
9+
import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank;
610
import com.gregtechceu.gtceu.common.cover.detector.AdvancedFluidDetectorCover;
711
import com.gregtechceu.gtceu.common.cover.detector.AdvancedItemDetectorCover;
812
import com.gregtechceu.gtceu.common.data.GTItems;
913
import com.gregtechceu.gtceu.gametest.util.TestUtils;
14+
import com.gregtechceu.gtceu.utils.RedstoneUtil;
1015

1116
import net.minecraft.core.BlockPos;
1217
import net.minecraft.core.Direction;
1318
import net.minecraft.gametest.framework.GameTest;
1419
import net.minecraft.gametest.framework.GameTestHelper;
1520
import net.minecraft.world.item.ItemStack;
1621
import net.minecraft.world.item.Items;
22+
import net.minecraftforge.fluids.FluidStack;
1723
import net.minecraftforge.gametest.GameTestHolder;
1824
import net.minecraftforge.gametest.PrefixGameTestTemplate;
1925

@@ -52,13 +58,20 @@ public static void testAdvancedActivityDetectorCoverWithActivity(GameTestHelper
5258
@GameTest(template = "electrolyzer", batch = "coverTests")
5359
public static void testAdvancedActivityDetectorCoverWithoutActivity(GameTestHelper helper) {
5460
helper.pullLever(new BlockPos(2, 2, 2));
55-
MetaMachine machine = ((MetaMachine) helper.getBlockEntity(new BlockPos(1, 2, 1)));
61+
SimpleTieredMachine machine = ((SimpleTieredMachine) helper.getBlockEntity(new BlockPos(1, 2, 1)));
5662
TestUtils.placeCover(helper, machine, GTItems.COVER_ACTIVITY_DETECTOR_ADVANCED.asStack(), Direction.WEST);
57-
helper.runAtTickTime(20 - machine.getOffsetTimer() % 20, () -> helper.pullLever(2, 2, 2));
58-
helper.runAtTickTime(45 - machine.getOffsetTimer() % 20, () -> {
59-
TestUtils.assertLampOff(helper, new BlockPos(0, 2, 1));
60-
helper.succeed();
63+
int offset = (int) (machine.getOffsetTimer() % 20L);
64+
helper.runAtTickTime(20 - offset, () -> {
65+
// Stop the fluid input
66+
helper.pullLever(2, 2, 2);
67+
// Also clear out the tank
68+
NotifiableFluidTank tank = (NotifiableFluidTank) machine
69+
.getCapabilitiesFlat(IO.IN, FluidRecipeCapability.CAP).get(0);
70+
tank.setFluidInTank(0, FluidStack.EMPTY);
6171
});
72+
// 20 ticks for the cover to update, 11 ticks for the recipe to finish, 1 tick for the cover to update
73+
helper.runAtTickTime(52 - offset,
74+
() -> helper.succeedWhen(() -> TestUtils.assertLampOff(helper, new BlockPos(0, 2, 1))));
6275
}
6376

6477
@GameTest(template = "electrolyzer", batch = "coverTests")
@@ -70,10 +83,25 @@ public static void testAdvancedFluidDetectorCover(GameTestHelper helper) {
7083
cover.setMaxValue(100000);
7184
cover.setMinValue(1);
7285
cover.setLatched(false);
73-
// At t=80, 21k will be inside, giving a redstone value of 2 or 3
74-
helper.runAtTickTime(81, () -> {
75-
TestUtils.assertRedstone(helper, new BlockPos(0, 2, 1), 2, 3);
76-
TestUtils.assertLampOn(helper, new BlockPos(0, 2, 1));
86+
MutableInt expected = new MutableInt();
87+
int offset = (int) (machine.getOffsetTimer() % 20L);
88+
helper.runAtTickTime(80 - offset, () -> {
89+
// Actually pull in the value at the time, since offset might change the amount
90+
var handler = machine.getFluidHandlerCap(null, false);
91+
long storedFluid = 0;
92+
for (int tank = 0; tank < handler.getTanks(); tank++) {
93+
storedFluid += handler.getFluidInTank(tank).getAmount();
94+
}
95+
expected.setValue(RedstoneUtil.computeRedstoneBetweenValues(storedFluid,
96+
cover.getMaxValue(), cover.getMinValue(), cover.isInverted()));
97+
});
98+
99+
helper.runAtTickTime(81 - offset, () -> {
100+
int value = expected.intValue();
101+
TestUtils.assertRedstoneEither(helper, new BlockPos(0, 2, 1),
102+
value,
103+
Math.max(0, value - 1),
104+
Math.min(15, value + 1));
77105
helper.succeed();
78106
});
79107
}

src/test/java/com/gregtechceu/gtceu/integration/ae2/machine/PatternBufferTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ private static BusHolder getBussesAndForm(GameTestHelper helper) {
8383
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
8484
public static void patternBufferNormalInputBusTest(GameTestHelper helper) {
8585
BusHolder busHolder = getBussesAndForm(helper);
86+
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
87+
// placement structure bug
8688
busHolder.inputBus1.getInventory().setStackInSlot(0, new ItemStack(Blocks.COBBLESTONE));
8789
helper.succeedWhen(() -> {
8890
helper.assertTrue(
@@ -97,6 +99,8 @@ public static void patternBufferNormalInputBusTest(GameTestHelper helper) {
9799
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
98100
public static void patternBufferBasicRequestTest(GameTestHelper helper) {
99101
BusHolder busHolder = getBussesAndForm(helper);
102+
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
103+
// placement structure bug
100104

101105
IGrid grid = busHolder.patternBuffer.getGrid();
102106

@@ -139,6 +143,8 @@ public static void patternBufferBasicRequestTest(GameTestHelper helper) {
139143
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
140144
public static void patternBufferDistinctDoesNothingTest(GameTestHelper helper) {
141145
BusHolder busHolder = getBussesAndForm(helper);
146+
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
147+
// placement structure bug
142148
busHolder.patternBuffer.setDistinct(true);
143149

144150
IGrid grid = busHolder.patternBuffer.getGrid();
@@ -182,6 +188,8 @@ public static void patternBufferDistinctDoesNothingTest(GameTestHelper helper) {
182188
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
183189
public static void patternBufferDyeingDoesNothingTest(GameTestHelper helper) {
184190
BusHolder busHolder = getBussesAndForm(helper);
191+
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
192+
// placement structure bug
185193
busHolder.patternBuffer.setPaintingColor(0xff);
186194

187195
IGrid grid = busHolder.patternBuffer.getGrid();
63 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)