2015-08-18 20:40:55 -04:00
|
|
|
package team.chisel.inventory;
|
2014-12-15 00:11:48 +00:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2020-02-23 19:48:37 +01:00
|
|
|
import team.chisel.carving.Carving;
|
|
|
|
|
import team.chisel.item.chisel.ItemChisel;
|
|
|
|
|
import team.chisel.utils.General;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-08-18 20:40:55 -04:00
|
|
|
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public class ContainerChisel extends Container {
|
|
|
|
|
|
|
|
|
|
public final InventoryChiselSelection inventory;
|
|
|
|
|
public InventoryPlayer playerInventory;
|
2015-03-04 13:25:33 -05:00
|
|
|
int chiselSlot;
|
2015-01-07 19:50:18 -05:00
|
|
|
public ItemStack chisel;
|
|
|
|
|
public boolean finished;
|
2015-01-22 21:33:43 -05:00
|
|
|
public ICarvingRegistry carving;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public ContainerChisel(InventoryPlayer inventoryplayer, InventoryChiselSelection inv) {
|
|
|
|
|
inventory = inv;
|
|
|
|
|
playerInventory = inventoryplayer;
|
2015-03-04 13:25:33 -05:00
|
|
|
chiselSlot = playerInventory.currentItem;
|
2015-01-07 19:50:18 -05:00
|
|
|
inv.container = this;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 19:24:29 -05:00
|
|
|
int top = 8, left = 62;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 19:24:29 -05:00
|
|
|
// selection slots
|
2015-01-12 20:42:32 -05:00
|
|
|
for (int i = 0; i < InventoryChiselSelection.normalSlots; i++) {
|
2015-01-12 19:24:29 -05:00
|
|
|
addSlotToContainer(
|
|
|
|
|
new SlotChiselSelection(
|
|
|
|
|
this,
|
|
|
|
|
inventory,
|
|
|
|
|
inventory,
|
|
|
|
|
i,
|
|
|
|
|
left + ((i % 10) * 18),
|
|
|
|
|
top + ((i / 10) * 18)));
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 19:24:29 -05:00
|
|
|
// main slot
|
|
|
|
|
addSlotToContainer(new SlotChiselInput(this, inventory, InventoryChiselSelection.normalSlots, 24, 24));
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 20:42:32 -05:00
|
|
|
top += 112;
|
|
|
|
|
left += 9;
|
2015-01-12 19:24:29 -05:00
|
|
|
// main inv
|
|
|
|
|
for (int i = 0; i < 27; i++) {
|
|
|
|
|
addSlotToContainer(new Slot(inventoryplayer, i + 9, left + ((i % 9) * 18), top + (i / 9) * 18));
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 20:42:32 -05:00
|
|
|
top += 58;
|
2015-01-12 19:24:29 -05:00
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
|
addSlotToContainer(new Slot(inventoryplayer, i, left + ((i % 9) * 18), top + (i / 9) * 18));
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
chisel = inventoryplayer.getCurrentItem();
|
2015-05-28 13:42:07 -04:00
|
|
|
if (chisel != null && chisel.stackTagCompound != null) {
|
2015-01-07 19:50:18 -05:00
|
|
|
ItemStack stack = ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget"));
|
|
|
|
|
inventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, stack);
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
Item item = General.getItem(chisel);
|
|
|
|
|
carving = item instanceof ItemChisel ? ItemChisel.carving : Carving.chisel;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
inventory.updateItems();
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
|
2015-01-13 05:59:51 -05:00
|
|
|
// we need to subtract away all the other slots
|
2015-03-04 13:25:33 -05:00
|
|
|
int clickedSlot = par1 - inventory.getSizeInventory() - 27;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-03-04 13:25:33 -05:00
|
|
|
// if the player has clicked on the chisel or is trying to use a number key to force an itemstack into the slot
|
|
|
|
|
// the chisel is in
|
|
|
|
|
if (clickedSlot == chiselSlot || (par3 == 2 && par2 == chiselSlot)) return null;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
return super.slotClick(par1, par2, par3, par4EntityPlayer);
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public void onContainerClosed(EntityPlayer entityplayer) {
|
|
|
|
|
inventory.clearItems();
|
|
|
|
|
super.onContainerClosed(entityplayer);
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer) {
|
|
|
|
|
return inventory.isUseableByPlayer(entityplayer);
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
2015-01-07 21:39:51 -05:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entity, int slotIdx) {
|
|
|
|
|
ItemStack itemstack = null;
|
|
|
|
|
Slot slot = (Slot) this.inventorySlots.get(slotIdx);
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 21:39:51 -05:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
|
|
|
|
ItemStack itemstack1 = slot.getStack();
|
|
|
|
|
itemstack = itemstack1.copy();
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-14 21:03:22 -05:00
|
|
|
if (slotIdx > InventoryChiselSelection.normalSlots) {
|
2015-01-12 20:42:32 -05:00
|
|
|
if (!this.mergeItemStack(
|
|
|
|
|
itemstack1,
|
|
|
|
|
InventoryChiselSelection.normalSlots,
|
|
|
|
|
InventoryChiselSelection.normalSlots + 1,
|
|
|
|
|
false)) {
|
2015-01-07 21:39:51 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-02-23 19:48:37 +01:00
|
|
|
entity.inventory.setItemStack(itemstack1.copy());
|
|
|
|
|
slot.onPickupFromSlot(entity, itemstack1);
|
|
|
|
|
itemstack1 = entity.inventory.getItemStack();
|
|
|
|
|
entity.inventory.setItemStack(null);
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-12 20:42:32 -05:00
|
|
|
if (!this.mergeItemStack(
|
|
|
|
|
itemstack1,
|
|
|
|
|
InventoryChiselSelection.normalSlots + 1,
|
|
|
|
|
InventoryChiselSelection.normalSlots + 1 + 36,
|
|
|
|
|
false)) {
|
2022-07-30 18:48:38 +04:00
|
|
|
entity.inventory.setItemStack(itemstack1);
|
2015-01-12 20:42:32 -05:00
|
|
|
return null;
|
2015-01-07 21:39:51 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
slot.onSlotChange(itemstack1, itemstack);
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 21:39:51 -05:00
|
|
|
if (itemstack1.stackSize == 0) {
|
2020-02-23 19:48:37 +01:00
|
|
|
slot.putStack(null);
|
2015-01-07 21:39:51 -05:00
|
|
|
} else {
|
2016-03-16 20:34:00 -04:00
|
|
|
slot.putStack(itemstack1);
|
2015-01-07 21:39:51 -05:00
|
|
|
slot.onSlotChanged();
|
|
|
|
|
}
|
|
|
|
|
if (itemstack1.stackSize == itemstack.stackSize) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-01-12 20:42:32 -05:00
|
|
|
if (slotIdx >= InventoryChiselSelection.normalSlots) {
|
2015-01-07 21:39:51 -05:00
|
|
|
slot.onPickupFromSlot(entity, itemstack1);
|
|
|
|
|
}
|
|
|
|
|
if (itemstack1.stackSize == 0) {
|
|
|
|
|
slot.putStack(null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
}
|
2015-01-07 21:39:51 -05:00
|
|
|
return itemstack;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2020-02-23 19:48:37 +01:00
|
|
|
/**
|
|
|
|
|
* Added validation of slot input Only Chiselable allowed
|
|
|
|
|
*
|
|
|
|
|
* @author Léa Gris
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
|
|
|
|
return ((Slot) this.inventorySlots.get(reversOrder ? toIndex - 1 : fromIndex)).isItemValid(par1ItemStack)
|
|
|
|
|
&& super.mergeItemStack(par1ItemStack, fromIndex, toIndex, reversOrder);
|
|
|
|
|
}
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public void onChiselSlotChanged() {
|
2015-03-04 13:25:33 -05:00
|
|
|
ItemStack stack = playerInventory.mainInventory[chiselSlot];
|
2015-01-25 15:08:29 -05:00
|
|
|
if (stack == null || !stack.isItemEqual(chisel)) finished = true;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
if (finished) return;
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-01-09 02:33:03 -05:00
|
|
|
General.setChiselTarget(chisel, inventory.getStackInSpecialSlot());
|
2023-01-29 10:09:28 -08:00
|
|
|
|
2015-03-04 13:25:33 -05:00
|
|
|
playerInventory.mainInventory[chiselSlot] = chisel;
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|