Skip to content
This repository was archived by the owner on May 26, 2024. It is now read-only.

Commit bf44090

Browse files
authored
Make sure the backpack is properly secured while it's open (#627)
1 parent aefb6dc commit bf44090

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/main/java/gtPlusPlus/core/container/Container_BackpackBase.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.item.ItemStack;
88

99
import gtPlusPlus.core.inventories.BaseInventoryBackpack;
10+
import gtPlusPlus.core.slots.SlotBlockedInv;
1011
import gtPlusPlus.core.slots.SlotItemBackpackInv;
1112

1213
public class Container_BackpackBase extends Container {
@@ -63,7 +64,11 @@ public Container_BackpackBase(final EntityPlayer par1Player, final InventoryPlay
6364

6465
// PLAYER ACTION BAR - uses default locations for standard action bar texture file
6566
for (i = 0; i < 9; ++i) {
66-
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + (i * 18), 142));
67+
if (i == par1Player.inventory.currentItem) {
68+
this.addSlotToContainer(new SlotBlockedInv(inventoryPlayer, i, 8 + (i * 18), 142));
69+
} else {
70+
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + (i * 18), 142));
71+
}
6772
}
6873
}
6974

@@ -164,6 +169,16 @@ public ItemStack slotClick(final int slot, final int button, final int flag, fin
164169
if ((slot >= 0) && (this.getSlot(slot) != null) && (this.getSlot(slot).getStack() == player.getHeldItem())) {
165170
return null;
166171
}
172+
173+
// Keybind for moving from hotbar slot to hovered slot, make we don't move the currently held backpack.
174+
if (flag == 2 && button >= 0 && button < 9) {
175+
int hotbarIndex = HOTBAR_START + button;
176+
Slot hotbarSlot = getSlot(hotbarIndex);
177+
if (hotbarSlot instanceof SlotBlockedInv) {
178+
return null;
179+
}
180+
}
181+
167182
return super.slotClick(slot, button, flag, player);
168183
}
169184
}

src/main/java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BaseInventoryBackpack implements IInventory {
2828
protected String uniqueID;
2929

3030
/**
31-
* @param itemstack - the ItemStack to which this inventory belongs
31+
* @param stack - the ItemStack to which this inventory belongs
3232
*/
3333
public BaseInventoryBackpack(final ItemStack stack) {
3434
this.invItem = stack;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package gtPlusPlus.core.slots;
2+
3+
import net.minecraft.entity.player.EntityPlayer;
4+
import net.minecraft.inventory.IInventory;
5+
import net.minecraft.inventory.Slot;
6+
import net.minecraft.item.ItemStack;
7+
8+
public class SlotBlockedInv extends Slot {
9+
10+
public SlotBlockedInv(IInventory inv, int index, int xPos, int yPos) {
11+
super(inv, index, xPos, yPos);
12+
}
13+
14+
@Override
15+
public boolean isItemValid(ItemStack stack) {
16+
return false;
17+
}
18+
19+
@Override
20+
public boolean canTakeStack(EntityPlayer player) {
21+
return false;
22+
}
23+
24+
@Override
25+
public void putStack(ItemStack itemStack) {}
26+
27+
@Override
28+
public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) {}
29+
30+
@Override
31+
public boolean getHasStack() {
32+
return false;
33+
}
34+
35+
@Override
36+
public ItemStack decrStackSize(int i) {
37+
return null;
38+
}
39+
}

0 commit comments

Comments
 (0)