diff --git a/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java b/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java index 75970fb..587abac 100644 --- a/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java +++ b/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java @@ -1,20 +1,33 @@ package baubles.api.expanded; +import baubles.api.BaubleType; + public class BaubleExpandedSlots { public static final int slotLimit = 20; private static String[] slots = new String[slotLimit]; private static int newSlotsRemaining = slotLimit; - + + public static final String ringType = "ring"; + public static final String amuletType = "amulet"; + public static final String beltType = "belt"; + static { - requestAddSlot("AMULET"); - requestAddSlot("RING"); - requestAddSlot("RING"); - requestAddSlot("BELT"); + tryAddSlot(amuletType); + tryAddSlot(ringType); + tryAddSlot(ringType); + tryAddSlot(beltType); + + tryAddSlot(ringType); + tryAddSlot(ringType); + tryAddSlot(ringType); + tryAddSlot(ringType); + tryAddSlot(ringType); + tryAddSlot(ringType); } - - public static boolean requestAddSlot(String type) { + + public static boolean tryAddSlot(String type) { //TODO: block after GUI init if(newSlotsRemaining >= 1) { slots[slotLimit - newSlotsRemaining] = type; @@ -25,7 +38,7 @@ public class BaubleExpandedSlots { return false; } - public static boolean requestRemoveSlot(String type) { + public static boolean tryRemoveSlot(String type) { //TODO: block after GUI init for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) { if(slots[slotToCheck].equals(type)) { @@ -39,8 +52,8 @@ public class BaubleExpandedSlots { } return false; } - - public static int totalCurrentSlotsForType(String type) { + + public static int totalCurrentSlotsOfType(String type) { int total = 0; for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) { if(slots[slotToCheck].equals(type)) { @@ -49,12 +62,12 @@ public class BaubleExpandedSlots { } return total; } - + public static int getTotalSlots() { return slotLimit - newSlotsRemaining; } - - public static String getTypeInSlot(int slot) { + + public static String getSlotType(int slot) { if (slot > 0 & slot < slotLimit) { return slots[slot]; } else { @@ -62,4 +75,16 @@ public class BaubleExpandedSlots { } } + public static String getTypeStringFromBaubleType(BaubleType type) { + switch(type) { + case RING: + return ringType; + case AMULET: + return amuletType; + case BELT: + return beltType; + } + return "unknown"; + } + } diff --git a/src/main/java/baubles/api/expanded/IBaubleExpanded.java b/src/main/java/baubles/api/expanded/IBaubleExpanded.java index 0c330d3..5437c94 100644 --- a/src/main/java/baubles/api/expanded/IBaubleExpanded.java +++ b/src/main/java/baubles/api/expanded/IBaubleExpanded.java @@ -3,9 +3,7 @@ package baubles.api.expanded; import baubles.api.IBauble; import net.minecraft.item.ItemStack; - /** - * * This interface should be extended by items that can be worn in bauble slots. * Supports multiple original and expanded slot types. * diff --git a/src/main/java/baubles/client/gui/GuiPlayerExpanded.java b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java index dba459f..8293f3c 100644 --- a/src/main/java/baubles/client/gui/GuiPlayerExpanded.java +++ b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java @@ -16,6 +16,7 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; +import baubles.api.expanded.BaubleExpandedSlots; import baubles.common.Baubles; import baubles.common.container.ContainerPlayerExpanded; @@ -56,15 +57,6 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer { super.initGui(); } - /** - * Draw the foreground layer for the GuiContainer (everything in front of the items) - */ - /*@Override - protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) - { - this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 104, 7, 4210752);//106 -> 104, 16 -> 7 - }*/ - /** * Draws the screen and all the components in it. */ @@ -80,12 +72,10 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(background); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); - - for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) { + + for (int i1 = 4; i1 < BaubleExpandedSlots.getTotalSlots() + 4; ++i1) { Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1); - if (slot.getHasStack() && slot.getSlotStackLimit() == 1) { - this.drawTexturedModalRect(guiLeft + slot.xDisplayPosition, guiTop + slot.yDisplayPosition, 200, 0, 16, 16); - } + this.drawTexturedModalRect(guiLeft + slot.xDisplayPosition - 1, guiTop + slot.yDisplayPosition - 1, 200, 0, 18, 18); } drawPlayerModel(guiLeft + 51, guiTop + 75, 30, (float)(guiLeft + 51) - this.xSizeFloat, (float)(guiTop + 75 - 50) - this.ySizeFloat, this.mc.thePlayer); } diff --git a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java index 7d81eb3..dd96262 100644 --- a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java +++ b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java @@ -12,13 +12,16 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.util.IIcon; import baubles.api.BaubleType; import baubles.api.IBauble; import baubles.api.expanded.BaubleExpandedSlots; +import baubles.api.expanded.IBaubleExpanded; import baubles.common.lib.PlayerHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class ContainerPlayerExpanded extends Container { - public IInventory craftResult = new InventoryCraftResult(); public InventoryBaubles baubles; private final EntityPlayer thePlayer; @@ -28,7 +31,7 @@ public class ContainerPlayerExpanded extends Container { baubles = new InventoryBaubles(player); baubles.setEventHandler(this); if (!player.worldObj.isRemote) { - baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList; + baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList; } int i; @@ -40,22 +43,28 @@ public class ContainerPlayerExpanded extends Container { this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) { @Override public int getSlotStackLimit() { return 1; } + @Override public boolean isItemValid(ItemStack itemStack) { if (itemStack == null) return false; return itemStack.getItem().isValidArmor(itemStack, k, thePlayer); } + + @SideOnly(Side.CLIENT) + public IIcon getBackgroundIconIndex() { + return ItemArmor.func_94602_b(k); + } }); } final int slotOffset = 18; final int slotStartX = 80; final int slotStartY = 8; - final int baubleSlots = BaubleExpandedSlots.getTotalSlots(); + final int totalBaubleSlots = BaubleExpandedSlots.getTotalSlots(); //bauble slots - for(i = 0; i < baubleSlots; i++) { - addSlotToContainer(new SlotBauble(baubles, BaubleExpandedSlots.getTypeInSlot(i), i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4)))); + for(i = 0; i < totalBaubleSlots; i++) { + addSlotToContainer(new SlotBauble(baubles, BaubleExpandedSlots.getSlotType(i), i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4)))); } //inventory slots @@ -84,65 +93,44 @@ public class ContainerPlayerExpanded extends Container { public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { ItemStack itemstack = null; Slot slot = (Slot)inventorySlots.get(slotIndex); - final int baubleSlots = BaubleExpandedSlots.getTotalSlots(); + final int totalBaubleSlots = BaubleExpandedSlots.getTotalSlots(); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); Item item = itemstack.getItem(); - if (slotIndex >= 5 && slotIndex < 4) { - if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false)) { - return null; - } - } else if (item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) { + if (item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) { int j = ((ItemArmor)item).armorType; - if (!this.mergeItemStack(itemstack1, j, j + 1, false)) { + if (!mergeItemStack(itemstack1, j, j + 1, false)) { return null; } - //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()) - { - int j = 4; - if (!this.mergeItemStack(itemstack1, j, j + 1, false)) { + } else if (slotIndex >= 4 + totalBaubleSlots && item instanceof IBauble && ((IBauble)item).canEquip(itemstack, thePlayer)) { + for(int baubleSlot = 4; baubleSlot < 4 + totalBaubleSlots; baubleSlot++) { + if(!((Slot)inventorySlots.get(baubleSlot)).getHasStack()) { + String[] types; + if(item instanceof IBaubleExpanded) { + types = ((IBaubleExpanded)item).getBaubleTypes(itemstack); + } else { + BaubleType legacyType = ((IBauble)item).getBaubleType(itemstack); + types = new String[] {BaubleExpandedSlots.getTypeStringFromBaubleType(legacyType)}; + } + for(String type : types) { + if(type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4)) && !mergeItemStack(itemstack1, baubleSlot, baubleSlot + 1, false)) { + return null; + } + } + } + } + } else if (slotIndex >= 4 + totalBaubleSlots && slotIndex < 31 + totalBaubleSlots) { + if (!mergeItemStack(itemstack1, 31 + totalBaubleSlots, 40 + totalBaubleSlots, false)) { return null; } - } 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)) { + } else if (slotIndex >= 31 + totalBaubleSlots && slotIndex < 40 + totalBaubleSlots) { + if (!mergeItemStack(itemstack1, 4 + totalBaubleSlots, 31 + totalBaubleSlots, false)) { return null; } - } 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)) { - return null; - } - } 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)) { - return null; - } - } else if (slotIndex >= 4 + baubleSlots && slotIndex < 31 + baubleSlots) { - if (!this.mergeItemStack(itemstack1, 31 + baubleSlots, 40 + baubleSlots, false)) { - return null; - } - } else if (slotIndex >= 31 + baubleSlots && slotIndex < 40 + baubleSlots) { - if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 31 + baubleSlots, false)) { - return null; - } - } else if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false, slot)) { + } else if (!mergeItemStack(itemstack1, 4 + totalBaubleSlots, 40 + totalBaubleSlots, false, slot)) { return null; } @@ -163,18 +151,18 @@ public class ContainerPlayerExpanded extends Container { } private void unequipBauble(ItemStack stack) { -// if (stack.getItem() instanceof IBauble) { -// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer); -// } +// if (stack.getItem() instanceof IBauble) { +// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer); +// } } @Override - public void putStacksInSlots(ItemStack[] p_75131_1_) { - baubles.blockEvents=true; - super.putStacksInSlots(p_75131_1_); - } + public void putStacksInSlots(ItemStack[] p_75131_1_) { + baubles.blockEvents=true; + super.putStacksInSlots(p_75131_1_); + } - protected boolean mergeItemStack(ItemStack itemStack, int par2, int par3, boolean par4, Slot ss) { + protected boolean mergeItemStack(ItemStack itemStack, int par2, int par3, boolean par4, Slot ss) { boolean flag1 = false; int k = par2; @@ -187,19 +175,19 @@ public class ContainerPlayerExpanded extends Container { if (itemStack.isStackable()) { while (itemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) { - slot = (Slot)this.inventorySlots.get(k); + slot = (Slot)inventorySlots.get(k); itemstack1 = slot.getStack(); 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; + if (ss instanceof SlotBauble) unequipBauble(itemStack); + itemStack.stackSize = 0; itemstack1.stackSize = l; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < itemStack.getMaxStackSize()) { - if (ss instanceof SlotBauble) unequipBauble(itemStack); + if (ss instanceof SlotBauble) unequipBauble(itemStack); itemStack.stackSize -= itemStack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = itemStack.getMaxStackSize(); slot.onSlotChanged(); @@ -223,11 +211,11 @@ public class ContainerPlayerExpanded extends Container { } while (!par4 && k < par3 || par4 && k >= par2) { - slot = (Slot)this.inventorySlots.get(k); + slot = (Slot)inventorySlots.get(k); itemstack1 = slot.getStack(); if (itemstack1 == null) { - if (ss instanceof SlotBauble) unequipBauble(itemStack); + if (ss instanceof SlotBauble) unequipBauble(itemStack); slot.putStack(itemStack.copy()); slot.onSlotChanged(); itemStack.stackSize = 0; @@ -245,9 +233,4 @@ public class ContainerPlayerExpanded extends Container { return flag1; } - @Override - public boolean func_94530_a(ItemStack itemStack, Slot slot) { - return slot.inventory != this.craftResult && super.func_94530_a(itemStack, slot); - } - } diff --git a/src/main/java/baubles/common/container/InventoryBaubles.java b/src/main/java/baubles/common/container/InventoryBaubles.java index bd2b12b..79eb6cd 100644 --- a/src/main/java/baubles/common/container/InventoryBaubles.java +++ b/src/main/java/baubles/common/container/InventoryBaubles.java @@ -138,7 +138,7 @@ public class InventoryBaubles implements IInventory { @Override public void setInventorySlotContents(int slot, ItemStack stack) { if(!blockEvents && this.stackList[slot] != null) { - ((IBauble)stackList[slot].getItem()).onUnequipped(stackList[slot], player.get()); + ((IBauble)stackList[slot].getItem()).onUnequipped(stackList[slot], player.get()); } this.stackList[slot] = stack; if (!blockEvents && stack != null && stack.getItem() instanceof IBauble) { @@ -195,7 +195,7 @@ public class InventoryBaubles implements IInventory { */ @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { - String slotType = BaubleExpandedSlots.getTypeInSlot(slot); + String slotType = BaubleExpandedSlots.getSlotType(slot); if (stack == null || slotType == null) { return false; } @@ -210,21 +210,7 @@ public class InventoryBaubles implements IInventory { types = ((IBaubleExpanded)item).getBaubleTypes(stack); } else { BaubleType legacyType = ((IBauble)item).getBaubleType(stack); - String type; - switch(legacyType) { - case RING: - type = "RING"; - break; - case AMULET: - type = "AMULET"; - break; - case BELT: - type = "BELT"; - break; - default: - type = "UNKNOWN"; - } - types = new String[] {type}; + types = new String[] {BaubleExpandedSlots.getTypeStringFromBaubleType(legacyType)}; } for(String type : types) { diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java index 7af0b63..65023db 100644 --- a/src/main/java/baubles/common/container/SlotBauble.java +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -4,36 +4,30 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; import baubles.api.BaubleType; import baubles.api.IBauble; +import baubles.api.expanded.BaubleExpandedSlots; import baubles.api.expanded.IBaubleExpanded; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class SlotBauble extends Slot { - String slotType; + private final String slotType; @Deprecated public SlotBauble(IInventory inventory, BaubleType legacyType, int slot, int x, int y) { super(inventory, slot, x, y); - switch(legacyType) { - case RING: - slotType = "RING"; - break; - case AMULET: - slotType = "AMULET"; - break; - case BELT: - slotType = "BELT"; - break; - default: - slotType = "UNKNOWN"; - } + slotType = BaubleExpandedSlots.getTypeStringFromBaubleType(legacyType); + } public SlotBauble(IInventory inventory, String type, int slot, int x, int y) { super(inventory, slot, x, y); - this.slotType = type; + slotType = type; } /** @@ -46,7 +40,7 @@ public class SlotBauble extends Slot { } Item item = stack.getItem(); - if(!(item instanceof IBauble) || !((IBauble) item).canEquip(stack, ((InventoryBaubles)inventory).player.get())) { + if(!(item instanceof IBauble) || !((IBauble)item).canEquip(stack, ((InventoryBaubles)inventory).player.get())) { return false; } @@ -55,21 +49,7 @@ public class SlotBauble extends Slot { types = ((IBaubleExpanded)item).getBaubleTypes(stack); } else { BaubleType legacyType = ((IBauble)item).getBaubleType(stack); - String type; - switch(legacyType) { - case RING: - type = "RING"; - break; - case AMULET: - type = "AMULET"; - break; - case BELT: - type = "BELT"; - break; - default: - type = "UNKNOWN"; - } - types = new String[] {type}; + types = new String[] {BaubleExpandedSlots.getTypeStringFromBaubleType(legacyType)}; } for(String type : types) { @@ -83,12 +63,18 @@ public class SlotBauble extends Slot { @Override public boolean canTakeStack(EntityPlayer player) { - return this.getStack()!=null && ((IBauble)this.getStack().getItem()).canUnequip(this.getStack(), player); + ItemStack itemStack = getStack(); + return itemStack != null && ((IBauble)itemStack.getItem()).canUnequip(itemStack, player); } @Override public int getSlotStackLimit() { return 1; } + + /*@SideOnly(Side.CLIENT) + public IIcon getBackgroundIconIndex() { + return null; + }*/ } diff --git a/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png b/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png index a00dbd1..1e12770 100644 Binary files a/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png and b/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png differ