22
33import com .gregtechceu .gtceu .GTCEu ;
44import com .gregtechceu .gtceu .api .capability .IWorkable ;
5+ import com .gregtechceu .gtceu .api .capability .recipe .FluidRecipeCapability ;
6+ import com .gregtechceu .gtceu .api .capability .recipe .IO ;
57import com .gregtechceu .gtceu .api .machine .MetaMachine ;
8+ import com .gregtechceu .gtceu .api .machine .SimpleTieredMachine ;
9+ import com .gregtechceu .gtceu .api .machine .trait .NotifiableFluidTank ;
610import com .gregtechceu .gtceu .common .cover .detector .AdvancedFluidDetectorCover ;
711import com .gregtechceu .gtceu .common .cover .detector .AdvancedItemDetectorCover ;
812import com .gregtechceu .gtceu .common .data .GTItems ;
913import com .gregtechceu .gtceu .gametest .util .TestUtils ;
14+ import com .gregtechceu .gtceu .utils .RedstoneUtil ;
1015
1116import net .minecraft .core .BlockPos ;
1217import net .minecraft .core .Direction ;
1318import net .minecraft .gametest .framework .GameTest ;
1419import net .minecraft .gametest .framework .GameTestHelper ;
1520import net .minecraft .world .item .ItemStack ;
1621import net .minecraft .world .item .Items ;
22+ import net .minecraftforge .fluids .FluidStack ;
1723import net .minecraftforge .gametest .GameTestHolder ;
1824import 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 }
0 commit comments