2014-03-31 10:36:27 +02:00
|
|
|
package baubles.common.container;
|
|
|
|
|
|
|
|
|
|
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.InventoryCraftResult;
|
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.inventory.SlotCrafting;
|
2021-11-03 05:13:32 -04:00
|
|
|
import net.minecraft.item.Item;
|
2014-03-31 10:36:27 +02:00
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
|
import baubles.api.BaubleType;
|
|
|
|
|
import baubles.api.IBauble;
|
2021-11-03 05:13:32 -04:00
|
|
|
import baubles.api.expanded.BaubleExpandedSlots;
|
2014-03-31 22:59:38 +02:00
|
|
|
import baubles.common.lib.PlayerHandler;
|
2014-03-31 10:36:27 +02:00
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
public class ContainerPlayerExpanded extends Container {
|
2014-03-31 10:36:27 +02:00
|
|
|
public IInventory craftResult = new InventoryCraftResult();
|
|
|
|
|
public InventoryBaubles baubles;
|
2021-11-03 05:13:32 -04:00
|
|
|
|
2014-03-31 10:36:27 +02:00
|
|
|
private final EntityPlayer thePlayer;
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player) {
|
2014-03-31 10:36:27 +02:00
|
|
|
this.thePlayer = player;
|
|
|
|
|
baubles = new InventoryBaubles(player);
|
|
|
|
|
baubles.setEventHandler(this);
|
|
|
|
|
if (!player.worldObj.isRemote) {
|
2014-03-31 22:59:38 +02:00
|
|
|
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
|
2014-03-31 10:36:27 +02:00
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
//armor
|
|
|
|
|
for (i = 0; i < 4; ++i) {
|
2014-03-31 10:36:27 +02:00
|
|
|
final int k = i;
|
2021-11-03 05:13:32 -04:00
|
|
|
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
|
2014-03-31 10:36:27 +02:00
|
|
|
@Override
|
|
|
|
|
public int getSlotStackLimit() { return 1; }
|
|
|
|
|
@Override
|
2021-11-03 05:13:32 -04:00
|
|
|
public boolean isItemValid(ItemStack itemStack) {
|
|
|
|
|
if (itemStack == null) return false;
|
|
|
|
|
return itemStack.getItem().isValidArmor(itemStack, k, thePlayer);
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
final int slotOffset = 18;
|
|
|
|
|
final int slotStartX = 80;
|
|
|
|
|
final int slotStartY = 8;
|
|
|
|
|
final int baubleSlots = BaubleExpandedSlots.getTotalSlots();
|
2014-08-07 09:30:13 +02:00
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
//bauble slots
|
|
|
|
|
for(i = 0; i < baubleSlots; i++) {
|
|
|
|
|
addSlotToContainer(new SlotBauble(baubles, BaubleExpandedSlots.getTypeInSlot(i), i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4))));
|
|
|
|
|
}
|
2014-03-31 10:36:27 +02:00
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
//inventory slots
|
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
|
for (j = 0; j < 9; ++j) {
|
|
|
|
|
addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
//hotbar slots
|
|
|
|
|
for (i = 0; i < 9; ++i) {
|
|
|
|
|
addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-11-03 05:13:32 -04:00
|
|
|
public boolean canInteractWith(EntityPlayer player) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2021-11-03 05:13:32 -04:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
2014-03-31 10:36:27 +02:00
|
|
|
ItemStack itemstack = null;
|
2021-11-03 05:13:32 -04:00
|
|
|
Slot slot = (Slot)inventorySlots.get(slotIndex);
|
|
|
|
|
final int baubleSlots = BaubleExpandedSlots.getTotalSlots();
|
2014-03-31 10:36:27 +02:00
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
2014-03-31 10:36:27 +02:00
|
|
|
ItemStack itemstack1 = slot.getStack();
|
|
|
|
|
itemstack = itemstack1.copy();
|
2021-11-03 05:13:32 -04:00
|
|
|
Item item = itemstack.getItem();
|
|
|
|
|
|
|
|
|
|
if (slotIndex >= 5 && slotIndex < 4) {
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) {
|
|
|
|
|
int j = ((ItemArmor)item).armorType;
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
//TODO: rewrite bauble shift clicking
|
|
|
|
|
} else if (item instanceof IBauble &&
|
|
|
|
|
((IBauble)item).getBaubleType(itemstack)==BaubleType.AMULET &&
|
|
|
|
|
((IBauble)item).canEquip(itemstack, thePlayer) &&
|
|
|
|
|
!((Slot)this.inventorySlots.get(4)).getHasStack())
|
2014-03-31 10:36:27 +02:00
|
|
|
{
|
2021-11-03 05:13:32 -04:00
|
|
|
int j = 4;
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (slotIndex>11 && item instanceof IBauble &&
|
|
|
|
|
((IBauble)item).getBaubleType(itemstack)==BaubleType.RING &&
|
|
|
|
|
((IBauble)item).canEquip(itemstack, thePlayer) &&
|
|
|
|
|
!((Slot)this.inventorySlots.get(5)).getHasStack()) {
|
|
|
|
|
int j = 5;
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (slotIndex>11 && item instanceof IBauble &&
|
|
|
|
|
((IBauble)item).getBaubleType(itemstack)==BaubleType.RING &&
|
|
|
|
|
((IBauble)item).canEquip(itemstack, thePlayer) &&
|
|
|
|
|
!((Slot)this.inventorySlots.get(6)).getHasStack()) {
|
|
|
|
|
int j = 6;
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (item instanceof IBauble &&
|
|
|
|
|
((IBauble)item).getBaubleType(itemstack)==BaubleType.BELT &&
|
|
|
|
|
((IBauble)item).canEquip(itemstack, thePlayer) &&
|
|
|
|
|
!((Slot)this.inventorySlots.get(7)).getHasStack()) {
|
|
|
|
|
int j = 7;
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (slotIndex >= 4 + baubleSlots && slotIndex < 31 + baubleSlots) {
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, 31 + baubleSlots, 40 + baubleSlots, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (slotIndex >= 31 + baubleSlots && slotIndex < 40 + baubleSlots) {
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 31 + baubleSlots, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false, slot)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemstack1.stackSize == 0) {
|
2014-03-31 10:36:27 +02:00
|
|
|
slot.putStack((ItemStack)null);
|
2021-11-03 05:13:32 -04:00
|
|
|
} else {
|
2014-03-31 10:36:27 +02:00
|
|
|
slot.onSlotChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemstack1.stackSize == itemstack.stackSize) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
slot.onPickupFromSlot(player, itemstack1);
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
|
}
|
2014-04-01 19:54:04 +02:00
|
|
|
|
|
|
|
|
private void unequipBauble(ItemStack stack) {
|
2014-08-20 10:52:59 +02:00
|
|
|
// if (stack.getItem() instanceof IBauble) {
|
|
|
|
|
// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer);
|
|
|
|
|
// }
|
2014-04-01 19:54:04 +02:00
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
|
2014-08-07 09:30:13 +02:00
|
|
|
@Override
|
|
|
|
|
public void putStacksInSlots(ItemStack[] p_75131_1_) {
|
|
|
|
|
baubles.blockEvents=true;
|
|
|
|
|
super.putStacksInSlots(p_75131_1_);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
protected boolean mergeItemStack(ItemStack itemStack, int par2, int par3, boolean par4, Slot ss) {
|
2014-04-01 19:54:04 +02:00
|
|
|
boolean flag1 = false;
|
|
|
|
|
int k = par2;
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (par4) {
|
2014-04-01 19:54:04 +02:00
|
|
|
k = par3 - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Slot slot;
|
|
|
|
|
ItemStack itemstack1;
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemStack.isStackable()) {
|
|
|
|
|
while (itemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) {
|
2014-04-01 19:54:04 +02:00
|
|
|
slot = (Slot)this.inventorySlots.get(k);
|
|
|
|
|
itemstack1 = slot.getStack();
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemstack1 != null && itemstack1.getItem() == itemStack.getItem() && (!itemStack.getHasSubtypes() || itemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemStack, itemstack1)) {
|
|
|
|
|
int l = itemstack1.stackSize + itemStack.stackSize;
|
|
|
|
|
if (l <= itemStack.getMaxStackSize()) {
|
|
|
|
|
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
|
|
|
|
itemStack.stackSize = 0;
|
2014-04-01 19:54:04 +02:00
|
|
|
itemstack1.stackSize = l;
|
|
|
|
|
slot.onSlotChanged();
|
|
|
|
|
flag1 = true;
|
2021-11-03 05:13:32 -04:00
|
|
|
} else if (itemstack1.stackSize < itemStack.getMaxStackSize()) {
|
|
|
|
|
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
|
|
|
|
itemStack.stackSize -= itemStack.getMaxStackSize() - itemstack1.stackSize;
|
|
|
|
|
itemstack1.stackSize = itemStack.getMaxStackSize();
|
2014-04-01 19:54:04 +02:00
|
|
|
slot.onSlotChanged();
|
|
|
|
|
flag1 = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (par4) {
|
2014-04-01 19:54:04 +02:00
|
|
|
--k;
|
2021-11-03 05:13:32 -04:00
|
|
|
} else {
|
2014-04-01 19:54:04 +02:00
|
|
|
++k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemStack.stackSize > 0) {
|
|
|
|
|
if (par4) {
|
2014-04-01 19:54:04 +02:00
|
|
|
k = par3 - 1;
|
2021-11-03 05:13:32 -04:00
|
|
|
} else {
|
2014-04-01 19:54:04 +02:00
|
|
|
k = par2;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
while (!par4 && k < par3 || par4 && k >= par2) {
|
2014-04-01 19:54:04 +02:00
|
|
|
slot = (Slot)this.inventorySlots.get(k);
|
|
|
|
|
itemstack1 = slot.getStack();
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemstack1 == null) {
|
|
|
|
|
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
|
|
|
|
slot.putStack(itemStack.copy());
|
2014-04-01 19:54:04 +02:00
|
|
|
slot.onSlotChanged();
|
2021-11-03 05:13:32 -04:00
|
|
|
itemStack.stackSize = 0;
|
2014-04-01 19:54:04 +02:00
|
|
|
flag1 = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (par4) {
|
2014-04-01 19:54:04 +02:00
|
|
|
--k;
|
2021-11-03 05:13:32 -04:00
|
|
|
} else {
|
2014-04-01 19:54:04 +02:00
|
|
|
++k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return flag1;
|
|
|
|
|
}
|
2014-03-31 10:36:27 +02:00
|
|
|
|
|
|
|
|
@Override
|
2021-11-03 05:13:32 -04:00
|
|
|
public boolean func_94530_a(ItemStack itemStack, Slot slot) {
|
|
|
|
|
return slot.inventory != this.craftResult && super.func_94530_a(itemStack, slot);
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|