Skip to content

Commit 32c89d3

Browse files
Copilotrubensworks
andauthored
Fix large Dark Tank drop capped at base 16,000mB instead of actual capacity (#1198)
* Fix Dark Tank loot function: set capacity before inserting fluid, add game tests Agent-Logs-Url: https://github.com/CyclopsMC/EvilCraft/sessions/b8e2ebee-6bde-4d7e-9591-545b7042754d Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com> * Fix game tests: use Block.getDrops instead of destroyBlock to test loot function Agent-Logs-Url: https://github.com/CyclopsMC/EvilCraft/sessions/0e0c650c-06ef-470f-84b6-587ad8f27679 Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
1 parent 607161b commit 32c89d3

3 files changed

Lines changed: 94 additions & 4 deletions

File tree

src/main/java/org/cyclops/evilcraft/EvilCraft.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public Class<?>[] getGameTestClasses() {
470470
GameTestsBlockEternalWater.class,
471471
GameTestsBloodChest.class,
472472
GameTestsBloodInfuser.class,
473+
GameTestsDarkTank.class,
473474
GameTestsEntangledChalice.class,
474475
GameTestsItemEternalWater.class,
475476
GameTestsItemStacking.class,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.cyclops.evilcraft.gametest;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.gametest.framework.GameTestHelper;
5+
import net.minecraft.network.chat.Component;
6+
import net.minecraft.world.item.ItemStack;
7+
import net.minecraft.world.level.block.Block;
8+
import net.neoforged.neoforge.capabilities.Capabilities;
9+
import net.neoforged.neoforge.fluids.FluidStack;
10+
import net.neoforged.neoforge.transfer.ResourceHandler;
11+
import net.neoforged.neoforge.transfer.access.ItemAccess;
12+
import net.neoforged.neoforge.transfer.fluid.FluidResource;
13+
import org.cyclops.cyclopscore.gametest.GameTest;
14+
import org.cyclops.evilcraft.Reference;
15+
import org.cyclops.evilcraft.RegistryEntries;
16+
import org.cyclops.evilcraft.blockentity.BlockEntityDarkTank;
17+
18+
import java.util.List;
19+
20+
public class GameTestsDarkTank {
21+
22+
public static final String TEMPLATE_EMPTY = Reference.MOD_ID + ":empty10";
23+
public static final BlockPos POS = BlockPos.ZERO.offset(2, 1, 2);
24+
25+
/**
26+
* Tests that breaking a large Dark Tank (144,000mB capacity) drops an item that preserves
27+
* the full capacity and fluid amount, not just the base 16,000mB capacity.
28+
*/
29+
@GameTest(template = TEMPLATE_EMPTY)
30+
public void testBreakLargeDarkTankFullPreservesCapacityAndFluid(GameTestHelper helper) {
31+
int largeCapacity = BlockEntityDarkTank.BASE_CAPACITY * 9;
32+
33+
// Place a Dark Tank
34+
helper.setBlock(POS, RegistryEntries.BLOCK_DARK_TANK.get());
35+
BlockEntityDarkTank tank = helper.getBlockEntity(POS, BlockEntityDarkTank.class);
36+
37+
// Set up as a large tank filled with blood
38+
tank.getTank().setCapacity(largeCapacity);
39+
tank.getTank().setFluid(new FluidStack(RegistryEntries.FLUID_BLOOD, largeCapacity));
40+
41+
// Get the drops via the loot table (which invokes LootFunctionCopyTankData)
42+
BlockPos absPos = helper.absolutePos(POS);
43+
List<ItemStack> drops = Block.getDrops(helper.getBlockState(POS), helper.getLevel(), absPos, tank);
44+
45+
helper.assertTrue(!drops.isEmpty(), Component.literal("Breaking a Dark Tank should produce drops"));
46+
ItemStack result = drops.get(0);
47+
helper.assertValueEqual(result.getItem(), RegistryEntries.ITEM_DARK_TANK.get(), Component.literal("Dropped item should be a Dark Tank"));
48+
49+
ItemAccess itemAccess = ItemAccess.forStack(result);
50+
ResourceHandler<FluidResource> fluidHandler = result.getCapability(Capabilities.Fluid.ITEM, itemAccess);
51+
helper.assertTrue(fluidHandler != null, Component.literal("Dropped Dark Tank should have a fluid handler"));
52+
helper.assertValueEqual(fluidHandler.getCapacityAsInt(0, FluidResource.EMPTY), largeCapacity, Component.literal("Dropped Dark Tank should have large capacity"));
53+
helper.assertValueEqual(fluidHandler.getAmountAsInt(0), largeCapacity, Component.literal("Dropped Dark Tank should contain all fluid"));
54+
55+
helper.succeed();
56+
}
57+
58+
/**
59+
* Tests that breaking an empty large Dark Tank preserves the large capacity.
60+
*/
61+
@GameTest(template = TEMPLATE_EMPTY)
62+
public void testBreakEmptyLargeDarkTankPreservesCapacity(GameTestHelper helper) {
63+
int largeCapacity = BlockEntityDarkTank.BASE_CAPACITY * 9;
64+
65+
// Place a Dark Tank
66+
helper.setBlock(POS, RegistryEntries.BLOCK_DARK_TANK.get());
67+
BlockEntityDarkTank tank = helper.getBlockEntity(POS, BlockEntityDarkTank.class);
68+
69+
// Set up as a large tank with no fluid
70+
tank.getTank().setCapacity(largeCapacity);
71+
72+
// Get the drops via the loot table (which invokes LootFunctionCopyTankData)
73+
BlockPos absPos = helper.absolutePos(POS);
74+
List<ItemStack> drops = Block.getDrops(helper.getBlockState(POS), helper.getLevel(), absPos, tank);
75+
76+
helper.assertTrue(!drops.isEmpty(), Component.literal("Breaking a Dark Tank should produce drops"));
77+
ItemStack result = drops.get(0);
78+
helper.assertValueEqual(result.getItem(), RegistryEntries.ITEM_DARK_TANK.get(), Component.literal("Dropped item should be a Dark Tank"));
79+
80+
ItemAccess itemAccess = ItemAccess.forStack(result);
81+
ResourceHandler<FluidResource> fluidHandler = result.getCapability(Capabilities.Fluid.ITEM, itemAccess);
82+
helper.assertTrue(fluidHandler != null, Component.literal("Dropped Dark Tank should have a fluid handler"));
83+
helper.assertValueEqual(fluidHandler.getCapacityAsInt(0, FluidResource.EMPTY), largeCapacity, Component.literal("Empty dropped Dark Tank should preserve large capacity"));
84+
helper.assertValueEqual(fluidHandler.getAmountAsInt(0), 0, Component.literal("Dropped Dark Tank should be empty"));
85+
86+
helper.succeed();
87+
}
88+
89+
}

src/main/java/org/cyclops/evilcraft/loot/functions/LootFunctionCopyTankData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public ItemStack run(ItemStack itemStack, LootContext lootContext) {
3939
return Optional.ofNullable(itemAccess.getCapability(Capabilities.Fluid.ITEM))
4040
.map(fluidHandlerItem -> {
4141
try (var tx = Transaction.openRoot()) {
42+
if (fluidHandlerItem instanceof IFluidHandlerCapacity) {
43+
((IFluidHandlerCapacity) fluidHandlerItem).setTankCapacity(0, fluidHandlerTile.getTankCapacity(0), tx);
44+
}
4245
FluidResource resource = fluidHandlerTile.getResource(0);
4346
if (!resource.isEmpty()) {
4447
fluidHandlerItem.insert(resource, fluidHandlerTile.getFluidAmount(), tx);
45-
if (fluidHandlerItem instanceof IFluidHandlerCapacity) {
46-
((IFluidHandlerCapacity) fluidHandlerItem).setTankCapacity(0, fluidHandlerTile.getTankCapacity(0), tx);
47-
}
48-
tx.commit();
4948
}
49+
tx.commit();
5050
}
5151
return itemAccess.getResource().toStack(itemAccess.getAmount());
5252
}).orElse(itemStack);

0 commit comments

Comments
 (0)