|
10 | 10 | import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachmentType;
|
11 | 11 | import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RedstoneMode;
|
12 | 12 | import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RoutingMode;
|
| 13 | +import com.raoulvdberge.refinedpipes.util.FluidUtil; |
13 | 14 | import net.minecraft.entity.player.PlayerEntity;
|
| 15 | +import net.minecraft.inventory.container.Slot; |
| 16 | +import net.minecraft.item.ItemStack; |
14 | 17 | import net.minecraft.util.Direction;
|
15 | 18 | import net.minecraft.util.math.BlockPos;
|
| 19 | +import net.minecraftforge.fluids.FluidStack; |
| 20 | +import net.minecraftforge.items.ItemHandlerHelper; |
16 | 21 | import net.minecraftforge.items.ItemStackHandler;
|
| 22 | +import net.minecraftforge.items.SlotItemHandler; |
17 | 23 |
|
18 | 24 | public class ExtractorAttachmentContainer extends BaseContainer {
|
19 | 25 | private final BlockPos pos;
|
@@ -131,4 +137,60 @@ public void setExactMode(boolean exactMode) {
|
131 | 137 |
|
132 | 138 | RefinedPipes.NETWORK.sendToServer(new ChangeExactModeMessage(pos, dir, exactMode));
|
133 | 139 | }
|
| 140 | + |
| 141 | + @Override |
| 142 | + public ItemStack transferStackInSlot(PlayerEntity player, int index) { |
| 143 | + Slot slot = inventorySlots.get(index); |
| 144 | + if (slot != null && slot.getHasStack() && index < 9 * 4) { |
| 145 | + for (int i = 9 * 4; i < inventorySlots.size(); ++i) { |
| 146 | + Slot filterSlot = inventorySlots.get(i); |
| 147 | + |
| 148 | + if (filterSlot instanceof FluidFilterSlot) { |
| 149 | + FluidFilterSlot fluidSlot = (FluidFilterSlot) filterSlot; |
| 150 | + |
| 151 | + if (fluidSlot.getFluidInventory().getFluid(fluidSlot.getSlotIndex()).isEmpty()) { |
| 152 | + FluidStack toInsert = FluidUtil.getFromStack(slot.getStack(), true).getValue(); |
| 153 | + |
| 154 | + boolean foundExistingFluid = false; |
| 155 | + |
| 156 | + for (int j = 0; j < fluidSlot.getFluidInventory().getSlots(); ++j) { |
| 157 | + if (fluidSlot.getFluidInventory().getFluid(j).isFluidEqual(toInsert)) { |
| 158 | + foundExistingFluid = true; |
| 159 | + break; |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + if (!foundExistingFluid) { |
| 164 | + fluidSlot.onContainerClicked(slot.getStack()); |
| 165 | + } |
| 166 | + |
| 167 | + break; |
| 168 | + } |
| 169 | + } else if (filterSlot instanceof SlotItemHandler) { |
| 170 | + SlotItemHandler itemSlot = (SlotItemHandler) filterSlot; |
| 171 | + |
| 172 | + if (!itemSlot.getHasStack()) { |
| 173 | + ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot.getStack(), 1); |
| 174 | + |
| 175 | + boolean foundExistingItem = false; |
| 176 | + |
| 177 | + for (int j = 0; j < itemSlot.getItemHandler().getSlots(); ++j) { |
| 178 | + if (ItemStack.areItemStacksEqual(itemSlot.getItemHandler().getStackInSlot(j), toInsert)) { |
| 179 | + foundExistingItem = true; |
| 180 | + break; |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + if (!foundExistingItem) { |
| 185 | + itemSlot.putStack(toInsert); |
| 186 | + } |
| 187 | + |
| 188 | + break; |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + return ItemStack.EMPTY; |
| 195 | + } |
134 | 196 | }
|
0 commit comments