|
| 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 | +} |
0 commit comments