diff --git a/src/main/java/com/raoulvdberge/refinedpipes/container/BaseContainer.java b/src/main/java/com/raoulvdberge/refinedpipes/container/BaseContainer.java index d1a48ea..6037314 100644 --- a/src/main/java/com/raoulvdberge/refinedpipes/container/BaseContainer.java +++ b/src/main/java/com/raoulvdberge/refinedpipes/container/BaseContainer.java @@ -29,7 +29,17 @@ protected BaseContainer(@Nullable ContainerType type, int windowId, PlayerEnt } protected void addPlayerInventory(int xInventory, int yInventory) { - int id = 0; + int id = 9; + + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 9; x++) { + addSlot(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18)); + + id++; + } + } + + id = 0; for (int i = 0; i < 9; i++) { int x = xInventory + i * 18; @@ -39,14 +49,6 @@ protected void addPlayerInventory(int xInventory, int yInventory) { id++; } - - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 9; x++) { - addSlot(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18)); - - id++; - } - } } @Override diff --git a/src/main/java/com/raoulvdberge/refinedpipes/container/ExtractorAttachmentContainer.java b/src/main/java/com/raoulvdberge/refinedpipes/container/ExtractorAttachmentContainer.java index d17f5bd..96939c2 100644 --- a/src/main/java/com/raoulvdberge/refinedpipes/container/ExtractorAttachmentContainer.java +++ b/src/main/java/com/raoulvdberge/refinedpipes/container/ExtractorAttachmentContainer.java @@ -10,10 +10,16 @@ import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachmentType; import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RedstoneMode; import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RoutingMode; +import com.raoulvdberge.refinedpipes.util.FluidUtil; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; +import net.minecraftforge.items.SlotItemHandler; public class ExtractorAttachmentContainer extends BaseContainer { private final BlockPos pos; @@ -131,4 +137,60 @@ public void setExactMode(boolean exactMode) { RefinedPipes.NETWORK.sendToServer(new ChangeExactModeMessage(pos, dir, exactMode)); } + + @Override + public ItemStack transferStackInSlot(PlayerEntity player, int index) { + Slot slot = inventorySlots.get(index); + if (slot != null && slot.getHasStack() && index < 9 * 4) { + for (int i = 9 * 4; i < inventorySlots.size(); ++i) { + Slot filterSlot = inventorySlots.get(i); + + if (filterSlot instanceof FluidFilterSlot) { + FluidFilterSlot fluidSlot = (FluidFilterSlot) filterSlot; + + if (fluidSlot.getFluidInventory().getFluid(fluidSlot.getSlotIndex()).isEmpty()) { + FluidStack toInsert = FluidUtil.getFromStack(slot.getStack(), true).getValue(); + + boolean foundExistingFluid = false; + + for (int j = 0; j < fluidSlot.getFluidInventory().getSlots(); ++j) { + if (fluidSlot.getFluidInventory().getFluid(j).isFluidEqual(toInsert)) { + foundExistingFluid = true; + break; + } + } + + if (!foundExistingFluid) { + fluidSlot.onContainerClicked(slot.getStack()); + } + + break; + } + } else if (filterSlot instanceof SlotItemHandler) { + SlotItemHandler itemSlot = (SlotItemHandler) filterSlot; + + if (!itemSlot.getHasStack()) { + ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot.getStack(), 1); + + boolean foundExistingItem = false; + + for (int j = 0; j < itemSlot.getItemHandler().getSlots(); ++j) { + if (ItemStack.areItemStacksEqual(itemSlot.getItemHandler().getStackInSlot(j), toInsert)) { + foundExistingItem = true; + break; + } + } + + if (!foundExistingItem) { + itemSlot.putStack(toInsert); + } + + break; + } + } + } + } + + return ItemStack.EMPTY; + } }