mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 00:07:37 +00:00
Fixes #109 Shift clicking not working in auto chisel
This commit is contained in:
1 parent
452b471c8d
commit
ad0b94384d
2 files changed
+109
-23
No files matched your search
@@ -13,7 +13,6 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
|
||||
import com.cricketcraft.chisel.inventory.ContainerAutoChisel.SlotAutoChisel;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -37,8 +36,8 @@ public class GuiAutoChisel extends GuiContainer {
|
||||
int y = (this.height - this.ySize) / 2;
|
||||
|
||||
for (Slot slot : (List<Slot>) inventorySlots.inventorySlots) {
|
||||
if (mouseInside(slot, mouseX - x, mouseY - y)) {
|
||||
if (slot instanceof SlotAutoChisel) {
|
||||
if (!slot.getHasStack() && mouseInside(slot, mouseX - x, mouseY - y)) {
|
||||
if (slot.slotNumber < autochisel.getSizeInventory()) {
|
||||
String tt = autochisel.getSlotTooltipUnloc(slot.slotNumber);
|
||||
if (!Strings.isNullOrEmpty(tt)) {
|
||||
this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal(tt)), mouseX - x, mouseY - y);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.cricketcraft.chisel.inventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -10,18 +11,6 @@ import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
|
||||
public class ContainerAutoChisel extends Container {
|
||||
|
||||
public static class SlotAutoChisel extends Slot {
|
||||
|
||||
public SlotAutoChisel(TileEntityAutoChisel inv, int id, int x, int y) {
|
||||
super(inv, id, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return inventory.isItemValidForSlot(slotNumber, stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static TileEntityAutoChisel autoChisel;
|
||||
public static EntityPlayer player;
|
||||
|
||||
@@ -30,17 +19,27 @@ public class ContainerAutoChisel extends Container {
|
||||
ContainerAutoChisel.player = player.player;
|
||||
autoChisel = tileEntityAutoChisel;
|
||||
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 0, 53, 15));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 1, 78, 51));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 2, 103, 15));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 3, 8, 62));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 4, 151, 11));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 5, 151, 31));
|
||||
addSlotToContainer(new SlotAutoChisel(tileEntityAutoChisel, 6, 151, 51));
|
||||
addSlot(tileEntityAutoChisel, 0, 53, 15);
|
||||
addSlot(tileEntityAutoChisel, 1, 78, 51);
|
||||
addSlot(tileEntityAutoChisel, 2, 103, 15);
|
||||
addSlot(tileEntityAutoChisel, 3, 8, 62);
|
||||
addSlot(tileEntityAutoChisel, 4, 151, 11);
|
||||
addSlot(tileEntityAutoChisel, 5, 151, 31);
|
||||
addSlot(tileEntityAutoChisel, 6, 151, 51);
|
||||
|
||||
bindPlayerInventory(player);
|
||||
}
|
||||
|
||||
private void addSlot(IInventory inv, final int id, int x, int y) {
|
||||
addSlotToContainer(new Slot(inv, id, x, y) {
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack arg0) {
|
||||
return inventory.isItemValidForSlot(id, arg0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void bindPlayerInventory(InventoryPlayer invPlayer) {
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
@@ -62,7 +61,8 @@ public class ContainerAutoChisel extends Container {
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
|
||||
System.out.println(slotNumber);
|
||||
System.out.println("World.isRemote: " + player.worldObj.isRemote);
|
||||
System.out.println("Shift Clicked Slot:" + slotNumber);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemStack1 = slot.getStack();
|
||||
@@ -93,4 +93,91 @@ public class ContainerAutoChisel extends Container {
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*
|
||||
* @author CrazyPants
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
|
||||
boolean result = false;
|
||||
int checkIndex = fromIndex;
|
||||
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
|
||||
if (par1ItemStack.isStackable()) {
|
||||
|
||||
while (par1ItemStack.stackSize > 0 && (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack)) {
|
||||
|
||||
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
|
||||
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (mergedSize <= maxStackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
itemstack1.stackSize = mergedSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
} else if (itemstack1.stackSize < maxStackSize) {
|
||||
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
|
||||
itemstack1.stackSize = maxStackSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (par1ItemStack.stackSize > 0) {
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
} else {
|
||||
checkIndex = fromIndex;
|
||||
}
|
||||
|
||||
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 == null && slot.isItemValid(par1ItemStack)) {
|
||||
ItemStack in = par1ItemStack.copy();
|
||||
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
|
||||
|
||||
slot.putStack(in);
|
||||
slot.onSlotChanged();
|
||||
if (in.stackSize >= par1ItemStack.stackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
} else {
|
||||
par1ItemStack.stackSize -= in.stackSize;
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user