Skip to content

Commit

Permalink
Allow View Cells to be shift-clicked into place (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
trittimo authored May 24, 2024
1 parent 07eb6c1 commit a65b501
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import appeng.client.gui.implementations.GuiMEMonitorable;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
Expand All @@ -60,9 +63,11 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.items.IItemHandler;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand Down Expand Up @@ -161,6 +166,51 @@ protected ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost m
}
}

@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}

// Below logic is all about handling shift click for view cells
if (!(this.host instanceof IViewCellStorage)) {
return super.transferStackInSlot(p, idx);
}

// Is it a view cell?
final Slot clickSlot = this.inventorySlots.get(idx);
ItemStack itemStack = clickSlot.getStack();
if (!AEApi.instance().definitions().items().viewCell().isSameAs(itemStack)) {
return super.transferStackInSlot(p, idx);
}

// Are we clicking from the player's inventory?
final boolean isPlayerInventorySlot = this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar;
if (!isPlayerInventorySlot) {
return super.transferStackInSlot(p, idx);
}

// Attempt to move the item into the view cell storage
final IItemHandler viewCellInv = ((IViewCellStorage) this.host).getViewCellStorage();
for (int slot = 0; slot < viewCellInv.getSlots(); slot++) {
if (viewCellInv.isItemValid(slot, itemStack) && viewCellInv.getStackInSlot(slot).isEmpty()) {
ItemStack remainder = viewCellInv.insertItem(slot, itemStack, true);
if (!remainder.isEmpty()) { // That slot can't take the item
continue;
}
remainder = viewCellInv.insertItem(slot, itemStack, false);
clickSlot.putStack(remainder);
this.detectAndSendChanges();
if (!remainder.isEmpty()) {
// How??
return super.transferStackInSlot(p, idx);
}
return ItemStack.EMPTY;
}
}
return super.transferStackInSlot(p, idx);
}

public IGridNode getNetworkNode() {
return this.networkNode;
}
Expand Down

0 comments on commit a65b501

Please sign in to comment.