mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-20 04:09:49 +00:00
Add double-right-click behavior to drawers
This commit is contained in:
1 parent
35e565ab5a
commit
87f24867e8
2 files changed
+43
-13
No files matched your search
@@ -154,29 +154,28 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null || item.getItem() == null)
|
||||
return false;
|
||||
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
|
||||
if (item.getItem() == ModItems.upgrade) {
|
||||
tileDrawers.setLevel(item.getItemDamage());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
if (item != null && item.getItem() != null) {
|
||||
if (item.getItem() == ModItems.upgrade) {
|
||||
tileDrawers.setLevel(item.getItemDamage());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
|
||||
if (player != null && !player.capabilities.isCreativeMode) {
|
||||
if (--item.stackSize <= 0)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
if (player != null && !player.capabilities.isCreativeMode) {
|
||||
if (--item.stackSize <= 0)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tileDrawers.getDirection() != side)
|
||||
return false;
|
||||
|
||||
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
|
||||
int countAdded = tileDrawers.putItemsIntoSlot(slot, item, item.stackSize);
|
||||
int countAdded = tileDrawers.interactPutItemsIntoSlot(slot, player);
|
||||
|
||||
//if (countAdded > 0)
|
||||
// world.markBlockForUpdate(x, y, z);
|
||||
|
||||
@@ -14,6 +14,8 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
{
|
||||
private class DrawerData {
|
||||
@@ -101,6 +103,9 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
|
||||
private int[] autoSides = new int[] { 0, 1 };
|
||||
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
|
||||
public TileEntityDrawers () {
|
||||
setDrawerCount(2);
|
||||
}
|
||||
@@ -190,6 +195,32 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int interactPutItemsIntoSlot (int slot, EntityPlayer player) {
|
||||
int count = 0;
|
||||
|
||||
ItemStack currentStack = player.inventory.getCurrentItem();
|
||||
if (currentStack != null)
|
||||
count += putItemsIntoSlot(slot, currentStack, currentStack.stackSize);
|
||||
|
||||
if (worldObj.getWorldTime() - lastClickTime < 10 && player.getPersistentID().equals(lastClickUUID)) {
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack subStack = player.inventory.getStackInSlot(i);
|
||||
if (subStack != null) {
|
||||
int subCount = putItemsIntoSlot(slot, subStack, subStack.stackSize);
|
||||
if (subCount > 0 && subStack.stackSize == 0)
|
||||
player.inventory.setInventorySlotContents(i, null);
|
||||
|
||||
count += subCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastClickTime = worldObj.getWorldTime();
|
||||
lastClickUUID = player.getPersistentID();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack, int count) {
|
||||
if (data[slot].getItem() == null) {
|
||||
data[slot].setItem(stack.getItem());
|
||||
|
||||
Reference in new issue
Block a user