|
48 | 48 | import net.minecraft.nbt.CompoundTag; |
49 | 49 | import net.minecraft.tags.TagKey; |
50 | 50 | import net.minecraft.world.item.Item; |
| 51 | +import net.minecraft.world.item.ItemStack; |
51 | 52 | import net.neoforged.neoforge.capabilities.Capabilities; |
52 | 53 | import net.neoforged.neoforge.fluids.FluidType; |
53 | 54 |
|
@@ -113,24 +114,42 @@ protected MachineModelClientData getMachineModelData() { |
113 | 114 | return data; |
114 | 115 | } |
115 | 116 |
|
116 | | - public boolean replicationStep(boolean simulate) { |
| 117 | + private static boolean canReplicate(ItemStack stack) { |
| 118 | + if (stack.is(BLACKLISTED)) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + // Containers are only allowed if they are empty. |
| 123 | + var itemHandler = stack.getCapability(Capabilities.ItemHandler.ITEM); |
| 124 | + if (itemHandler != null) { |
| 125 | + int slots = itemHandler.getSlots(); |
| 126 | + for (int i = 0; i < slots; ++i) { |
| 127 | + if (!itemHandler.getStackInSlot(i).isEmpty()) { |
| 128 | + return false; |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + // Disallow anything that contains UU Matter |
| 134 | + var fluidItem = stack.getCapability(Capabilities.FluidHandler.ITEM); |
| 135 | + if (fluidItem != null) { |
| 136 | + for (int tank = 0; tank < fluidItem.getTanks(); ++tank) { |
| 137 | + if (fluidItem.getFluidInTank(tank).getFluid() == MIFluids.UU_MATER.asFluid()) { |
| 138 | + return false; |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + return true; |
| 144 | + } |
117 | 145 |
|
| 146 | + public boolean replicationStep(boolean simulate) { |
118 | 147 | ItemVariant itemVariant = inventoryComponent.getItemInputs().get(0).getResource(); |
119 | 148 |
|
120 | 149 | if (!itemVariant.isBlank()) { |
121 | | - // check blacklist |
122 | | - if (itemVariant.toStack().is(BLACKLISTED)) { |
| 150 | + if (!canReplicate(itemVariant.toStack())) { |
123 | 151 | return false; |
124 | 152 | } |
125 | | - // check that the item doesn't contain uu matter |
126 | | - var fluidItem = itemVariant.toStack().getCapability(Capabilities.FluidHandler.ITEM); |
127 | | - if (fluidItem != null) { |
128 | | - for (int tank = 0; tank < fluidItem.getTanks(); ++tank) { |
129 | | - if (fluidItem.getFluidInTank(tank).getFluid() == MIFluids.UU_MATER.asFluid()) { |
130 | | - return false; |
131 | | - } |
132 | | - } |
133 | | - } |
134 | 153 |
|
135 | 154 | try (Transaction tx = Transaction.openOuter()) { |
136 | 155 | MIItemStorage itemStorage = new MIItemStorage(inventoryComponent.getItemOutputs()); |
|
0 commit comments