Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Commit

Permalink
Add shift clicking for extractor attachment container
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Apr 10, 2020
1 parent 0871ed7 commit 97c8f24
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 97c8f24

Please sign in to comment.