2014-03-31 10:36:27 +02:00
|
|
|
package baubles.common.container;
|
|
|
|
|
|
2021-11-21 23:28:57 -05:00
|
|
|
import baubles.api.IBauble;
|
|
|
|
|
import baubles.api.expanded.BaubleExpandedSlots;
|
|
|
|
|
import baubles.api.expanded.IBaubleExpanded;
|
|
|
|
|
import baubles.common.BaublesConfig;
|
|
|
|
|
import baubles.common.lib.PlayerHandler;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-03-31 10:36:27 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
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;
|
2021-11-03 19:19:12 -04:00
|
|
|
import net.minecraft.util.IIcon;
|
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 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) {
|
2021-11-03 19:19:12 -04: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; }
|
2021-11-03 19:19:12 -04:00
|
|
|
|
2014-03-31 10:36:27 +02:00
|
|
|
@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 19:19:12 -04:00
|
|
|
|
2021-11-04 23:36:02 -04:00
|
|
|
@Override
|
2021-11-03 19:19:12 -04:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public IIcon getBackgroundIconIndex() {
|
|
|
|
|
return ItemArmor.func_94602_b(k);
|
|
|
|
|
}
|
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;
|
2014-08-07 09:30:13 +02:00
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
//bauble slots
|
2021-11-21 23:28:57 -05:00
|
|
|
for(i = 0; i < BaubleExpandedSlots.slotLimit; i++) {
|
|
|
|
|
String slotType = BaubleExpandedSlots.getSlotType(i);
|
2023-01-29 20:17:33 -05:00
|
|
|
if(BaublesConfig.showUnusedSlots || !slotType.equals(BaubleExpandedSlots.unknownType)) {
|
|
|
|
|
addSlotToContainer(new SlotBauble(baubles, slotType, i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4))));
|
2021-11-21 23:28:57 -05:00
|
|
|
}
|
2021-11-03 05:13:32 -04:00
|
|
|
}
|
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);
|
2021-11-21 23:28:57 -05:00
|
|
|
final int visibleBaubleSlots = BaublesConfig.showUnusedSlots ? BaubleExpandedSlots.slotLimit : BaubleExpandedSlots.slotsCurrentlyUsed();
|
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();
|
|
|
|
|
|
2021-11-03 19:19:12 -04:00
|
|
|
if (item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) {
|
2021-11-03 05:13:32 -04:00
|
|
|
int j = ((ItemArmor)item).armorType;
|
2021-11-03 19:19:12 -04:00
|
|
|
if (!mergeItemStack(itemstack1, j, j + 1, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-21 23:28:57 -05:00
|
|
|
} else if (slotIndex >= 4 + visibleBaubleSlots && item instanceof IBauble && ((IBauble)item).canEquip(itemstack, thePlayer)) {
|
|
|
|
|
for(int baubleSlot = 4; baubleSlot < 4 + visibleBaubleSlots; baubleSlot++) {
|
2021-11-03 19:19:12 -04:00
|
|
|
if(!((Slot)inventorySlots.get(baubleSlot)).getHasStack()) {
|
|
|
|
|
String[] types;
|
|
|
|
|
if(item instanceof IBaubleExpanded) {
|
|
|
|
|
types = ((IBaubleExpanded)item).getBaubleTypes(itemstack);
|
|
|
|
|
} else {
|
2021-11-05 04:30:05 -04:00
|
|
|
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(((IBauble)item).getBaubleType(itemstack))};
|
2021-11-03 19:19:12 -04:00
|
|
|
}
|
|
|
|
|
for(String type : types) {
|
|
|
|
|
if(type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4)) && !mergeItemStack(itemstack1, baubleSlot, baubleSlot + 1, false)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-31 10:36:27 +02:00
|
|
|
}
|
2021-11-21 23:28:57 -05:00
|
|
|
} else if (slotIndex >= 4 + visibleBaubleSlots && slotIndex < 31 + visibleBaubleSlots) {
|
|
|
|
|
if (!mergeItemStack(itemstack1, 31 + visibleBaubleSlots, 40 + visibleBaubleSlots, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-21 23:28:57 -05:00
|
|
|
} else if (slotIndex >= 31 + visibleBaubleSlots && slotIndex < 40 + visibleBaubleSlots) {
|
|
|
|
|
if (!mergeItemStack(itemstack1, 4 + visibleBaubleSlots, 31 + visibleBaubleSlots, false)) {
|
2014-03-31 10:36:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2021-11-21 23:28:57 -05:00
|
|
|
} else if (!mergeItemStack(itemstack1, 4 + visibleBaubleSlots, 40 + visibleBaubleSlots, 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) {
|
2021-11-03 19:19:12 -04: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
|
2021-11-03 19:19:12 -04:00
|
|
|
public void putStacksInSlots(ItemStack[] p_75131_1_) {
|
|
|
|
|
baubles.blockEvents=true;
|
|
|
|
|
super.putStacksInSlots(p_75131_1_);
|
|
|
|
|
}
|
2014-08-07 09:30:13 +02:00
|
|
|
|
2021-11-03 19:19:12 -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)) {
|
2021-11-03 19:19:12 -04:00
|
|
|
slot = (Slot)inventorySlots.get(k);
|
2014-04-01 19:54:04 +02:00
|
|
|
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()) {
|
2021-11-03 19:19:12 -04:00
|
|
|
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()) {
|
2021-11-03 19:19:12 -04:00
|
|
|
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
2021-11-03 05:13:32 -04:00
|
|
|
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) {
|
2021-11-03 19:19:12 -04:00
|
|
|
slot = (Slot)inventorySlots.get(k);
|
2014-04-01 19:54:04 +02:00
|
|
|
itemstack1 = slot.getStack();
|
|
|
|
|
|
2021-11-03 05:13:32 -04:00
|
|
|
if (itemstack1 == null) {
|
2021-11-03 19:19:12 -04:00
|
|
|
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
2021-11-03 05:13:32 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|