WIP API for adding new slots

Rendering needs reworked and shift-clicking needs some improvements.
This commit is contained in:
jss2a98aj committed 2021-11-03 05:13:32 -04:00
1 parent 36a332e597
commit e50c4de348
11 files changed
+393 -434

No files matched your search

+1 -5
View File
@@ -3,9 +3,5 @@ package baubles.api;
public enum BaubleType {
RING,
AMULET,
BELT,
HEAD,
BODY,
CHARM,
GAUNTLET
BELT
}
+1 -1
View File
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
public interface IBauble {
/**
* This method return the type of bauble this is.
* This method returns the type of bauble this is.
* Type is used to determine the slots it can go into.
*/
public BaubleType getBaubleType(ItemStack itemstack);
@@ -0,0 +1,65 @@
package baubles.api.expanded;
public class BaubleExpandedSlots {
public static final int slotLimit = 20;
private static String[] slots = new String[slotLimit];
private static int newSlotsRemaining = slotLimit;
static {
requestAddSlot("AMULET");
requestAddSlot("RING");
requestAddSlot("RING");
requestAddSlot("BELT");
}
public static boolean requestAddSlot(String type) {
//TODO: block after GUI init
if(newSlotsRemaining >= 1) {
slots[slotLimit - newSlotsRemaining] = type;
newSlotsRemaining--;
return true;
}
return false;
}
public static boolean requestRemoveSlot(String type) {
//TODO: block after GUI init
for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) {
if(slots[slotToCheck].equals(type)) {
for(int slotToMove = slotToCheck + 1; slotToMove < slotLimit; slotToMove++) {
slots[slotToMove - 1] = slots[slotToMove];
}
slots[slotLimit - 1] = null;
newSlotsRemaining++;
return true;
}
}
return false;
}
public static int totalCurrentSlotsForType(String type) {
int total = 0;
for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) {
if(slots[slotToCheck].equals(type)) {
total++;
}
}
return total;
}
public static int getTotalSlots() {
return slotLimit - newSlotsRemaining;
}
public static String getTypeInSlot(int slot) {
if (slot > 0 & slot < slotLimit) {
return slots[slot];
} else {
return null;
}
}
}
@@ -0,0 +1,23 @@
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.
*
* @author jss2a98aj
*/
public interface IBaubleExpanded extends IBauble {
/**
* This method returns the types of bauble slots this item can go into.
* getBaubleType is ignored when using IBaubleExpanded.
* Original slots can be used by putting "AMULET" "RING" or BELT" in the array.
*/
public String[] getBaubleTypes (ItemStack itemstack);
}
@@ -20,10 +20,9 @@ import baubles.common.Baubles;
import baubles.common.container.ContainerPlayerExpanded;
public class GuiPlayerExpanded extends InventoryEffectRenderer {
public static final ResourceLocation background =
new ResourceLocation("baubles","textures/gui/expanded_inventory.png");
public static final ResourceLocation background = new ResourceLocation("baubles","textures/gui/expanded_inventory.png");
/**
* x size of the inventory window in pixels. Defined as float, passed as int
*/
@@ -33,8 +32,7 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
*/
private float ySizeFloat;
public GuiPlayerExpanded(EntityPlayer player)
{
public GuiPlayerExpanded(EntityPlayer player) {
super(new ContainerPlayerExpanded(player.inventory, !player.worldObj.isRemote, player));
this.allowUserInput = true;
}
@@ -43,69 +41,56 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
* Called from the main game loop to update the screen.
*/
@Override
public void updateScreen()
{
public void updateScreen() {
try {
((ContainerPlayerExpanded)inventorySlots).baubles.blockEvents=false;
} catch (Exception e) { }
((ContainerPlayerExpanded)inventorySlots).baubles.blockEvents = false;
} catch (Exception e) {}
}
/**
* Adds the buttons (and other controls) to the screen in question.
*/
@Override
public void initGui()
{
public void initGui() {
this.buttonList.clear();
super.initGui();
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
@Override
/*@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.
*/
@Override
public void drawScreen(int par1, int par2, float par3)
{
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
this.xSizeFloat = (float)par1;
this.ySizeFloat = (float)par2;
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
{
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int k = this.guiLeft;
int l = this.guiTop;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize);
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
{
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
if (slot.getHasStack() && slot.getSlotStackLimit()==1)
{
this.drawTexturedModalRect(k+slot.xDisplayPosition, l+slot.yDisplayPosition, 200, 0, 16, 16);
if (slot.getHasStack() && slot.getSlotStackLimit() == 1) {
this.drawTexturedModalRect(guiLeft + slot.xDisplayPosition, guiTop + slot.yDisplayPosition, 200, 0, 16, 16);
}
}
drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSizeFloat, (float)(l + 75 - 50) - this.ySizeFloat, this.mc.thePlayer);
drawPlayerModel(guiLeft + 51, guiTop + 75, 30, (float)(guiLeft + 51) - this.xSizeFloat, (float)(guiTop + 75 - 50) - this.ySizeFloat, this.mc.thePlayer);
}
public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase playerdrawn)
{
public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase playerdrawn) {
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef((float)x, (float)y, 50.0F);
@@ -142,28 +127,20 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
}
@Override
protected void actionPerformed(GuiButton button)
{
if (button.id == 0)
{
protected void actionPerformed(GuiButton button) {
if (button.id == 0) {
this.mc.displayGuiScreen(new GuiAchievements(this, this.mc.thePlayer.getStatFileWriter()));
}
if (button.id == 1)
{
} else if (button.id == 1) {
this.mc.displayGuiScreen(new GuiStats(this, this.mc.thePlayer.getStatFileWriter()));
}
}
@Override
protected void keyTyped(char par1, int par2) {
if (par2 == Baubles.proxy.keyHandler.key.getKeyCode())
{
if (par2 == Baubles.proxy.keyHandler.key.getKeyCode()) {
this.mc.thePlayer.closeScreen();
} else
super.keyTyped(par1, par2);
}
}
@@ -8,126 +8,72 @@ import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.BaubleExpandedSlots;
import baubles.common.lib.PlayerHandler;
public class ContainerPlayerExpanded extends Container
{
/**
* The crafting matrix inventory.
*/
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
public class ContainerPlayerExpanded extends Container {
public IInventory craftResult = new InventoryCraftResult();
public InventoryBaubles baubles;
/**
* Determines if inventory manipulation should be handled.
*/
public boolean isLocalWorld;
private final EntityPlayer thePlayer;
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player)
{
this.isLocalWorld = par2;
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player) {
this.thePlayer = player;
baubles = new InventoryBaubles(player);
baubles.setEventHandler(this);
if (!player.worldObj.isRemote) {
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
}
this.addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 144, 27));//36 -> 27
int i;
int j;
for (i = 0; i < 2; ++i)
{
for (j = 0; j < 2; ++j)
{
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 106 + j * 18, 17 + i * 18));//26 -> 17
}
}
for (i = 0; i < 4; ++i)
{
//armor
for (i = 0; i < 4; ++i) {
final int k = i;
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18)
{
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
@Override
public int getSlotStackLimit() { return 1; }
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
if (par1ItemStack == null) return false;
return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, thePlayer);
public boolean isItemValid(ItemStack itemStack) {
if (itemStack == null) return false;
return itemStack.getItem().isValidArmor(itemStack, k, thePlayer);
}
});
}
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.AMULET, 0, 80, 8));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,1, 80, 8 + 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,2, 80, 8 + 2 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.BELT,3, 80, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.HEAD,4, 80 + 18, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.BODY,5, 80 + 18 * 2, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.CHARM,6, 80 + 18 * 3, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.GAUNTLET,7, 80 + 18 * 4, 8 + 3 * 18));
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
final int slotOffset = 18;
final int slotStartX = 80;
final int slotStartY = 8;
final int baubleSlots = 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))));
}
//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));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
//hotbar slots
for (i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj));
}
/**
* Called when the container is closed.
*/
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
for (int i = 0; i < 4; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
player.dropPlayerItemWithRandomChoice(itemstack, false);
}
}
this.craftResult.setInventorySlotContents(0, (ItemStack)null);
if (!player.worldObj.isRemote) {
PlayerHandler.setPlayerBaubles(player, baubles);
}
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@@ -135,171 +81,82 @@ public class ContainerPlayerExpanded extends Container
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
Slot slot = (Slot)inventorySlots.get(slotIndex);
final int baubleSlots = BaubleExpandedSlots.getTotalSlots();
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, true))
{
Item item = itemstack.getItem();
if (slotIndex >= 5 && slotIndex < 4) {
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false)) {
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 >= 1 && par2 < 5)
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false))
{
} 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)) {
return null;
}
}
else if (par2 >= 5 && par2 < 9)
//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())
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false))
{
int j = 4;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof ItemArmor &&
!((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack())
{
int j = 5 + ((ItemArmor)itemstack.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} 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)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.AMULET &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(9)).getHasStack())
{
int j = 9;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} 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 (par2>11 && itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(10)).getHasStack())
{
int j = 10;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} 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 (par2>11 && itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(11)).getHasStack())
{
int j = 11;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex >= 4 + baubleSlots && slotIndex < 31 + baubleSlots) {
if (!this.mergeItemStack(itemstack1, 31 + baubleSlots, 40 + baubleSlots, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.BELT &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(12)).getHasStack())
{
int j = 12;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex >= 31 + baubleSlots && slotIndex < 40 + baubleSlots) {
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 31 + baubleSlots, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.HEAD &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(13)).getHasStack())
{
int j = 13;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.BODY &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(14)).getHasStack())
{
int j = 14;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.CHARM &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(15)).getHasStack())
{
int j = 15;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.GAUNTLET &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(16)).getHasStack())
{
int j = 16;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (par2 >= 9+4 && par2 < 36+4)
{
if (!this.mergeItemStack(itemstack1, 36+4, 45+4, false))
{
return null;
}
}
else if (par2 >= 36+4 && par2 < 45+4)
{
if (!this.mergeItemStack(itemstack1, 9+4, 36+4, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false, slot))
{
} else if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false, slot)) {
return null;
}
if (itemstack1.stackSize == 0)
{
if (itemstack1.stackSize == 0) {
slot.putStack((ItemStack)null);
}
else
{
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
if (itemstack1.stackSize == itemstack.stackSize) {
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
@@ -310,102 +167,77 @@ public class ContainerPlayerExpanded extends Container
// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer);
// }
}
@Override
public void putStacksInSlots(ItemStack[] p_75131_1_) {
baubles.blockEvents=true;
super.putStacksInSlots(p_75131_1_);
}
protected boolean mergeItemStack(ItemStack par1ItemStack, 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;
if (par4)
{
if (par4) {
k = par3 - 1;
}
Slot slot;
ItemStack itemstack1;
if (par1ItemStack.isStackable())
{
while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2))
{
if (itemStack.isStackable()) {
while (itemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) {
slot = (Slot)this.inventorySlots.get(k);
itemstack1 = slot.getStack();
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))
{
int l = itemstack1.stackSize + par1ItemStack.stackSize;
if (l <= par1ItemStack.getMaxStackSize())
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
par1ItemStack.stackSize = 0;
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;
itemstack1.stackSize = l;
slot.onSlotChanged();
flag1 = true;
}
else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize())
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = par1ItemStack.getMaxStackSize();
} else if (itemstack1.stackSize < itemStack.getMaxStackSize()) {
if (ss instanceof SlotBauble) unequipBauble(itemStack);
itemStack.stackSize -= itemStack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = itemStack.getMaxStackSize();
slot.onSlotChanged();
flag1 = true;
}
}
if (par4)
{
if (par4) {
--k;
}
else
{
} else {
++k;
}
}
}
if (par1ItemStack.stackSize > 0)
{
if (par4)
{
if (itemStack.stackSize > 0) {
if (par4) {
k = par3 - 1;
}
else
{
} else {
k = par2;
}
while (!par4 && k < par3 || par4 && k >= par2)
{
while (!par4 && k < par3 || par4 && k >= par2) {
slot = (Slot)this.inventorySlots.get(k);
itemstack1 = slot.getStack();
if (itemstack1 == null)
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
slot.putStack(par1ItemStack.copy());
if (itemstack1 == null) {
if (ss instanceof SlotBauble) unequipBauble(itemStack);
slot.putStack(itemStack.copy());
slot.onSlotChanged();
par1ItemStack.stackSize = 0;
itemStack.stackSize = 0;
flag1 = true;
break;
}
if (par4)
{
if (par4) {
--k;
}
else
{
} else {
++k;
}
}
@@ -414,11 +246,8 @@ public class ContainerPlayerExpanded extends Container
}
@Override
public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot)
{
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
public boolean func_94530_a(ItemStack itemStack, Slot slot) {
return slot.inventory != this.craftResult && super.func_94530_a(itemStack, slot);
}
}
@@ -8,12 +8,15 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.MathHelper;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.BaubleExpandedSlots;
import baubles.api.expanded.IBaubleExpanded;
import baubles.common.Baubles;
import baubles.common.network.PacketHandler;
import baubles.common.network.PacketSyncBauble;
@@ -25,7 +28,7 @@ public class InventoryBaubles implements IInventory {
public boolean blockEvents=false;
public InventoryBaubles(EntityPlayer player) {
this.stackList = new ItemStack[8];
this.stackList = new ItemStack[BaubleExpandedSlots.slotLimit];
this.player = new WeakReference<EntityPlayer>(player);
}
@@ -49,8 +52,8 @@ public class InventoryBaubles implements IInventory {
* Returns the stack in slot i
*/
@Override
public ItemStack getStackInSlot(int par1) {
return par1 >= this.getSizeInventory() ? null : this.stackList[par1];
public ItemStack getStackInSlot(int slot) {
return slot >= this.getSizeInventory() ? null : this.stackList[slot];
}
/**
@@ -75,10 +78,10 @@ public class InventoryBaubles implements IInventory {
* GUI.
*/
@Override
public ItemStack getStackInSlotOnClosing(int par1) {
if (this.stackList[par1] != null) {
ItemStack itemstack = this.stackList[par1];
this.stackList[par1] = null;
public ItemStack getStackInSlotOnClosing(int slot) {
if (this.stackList[slot] != null) {
ItemStack itemstack = this.stackList[slot];
this.stackList[slot] = null;
return itemstack;
} else {
return null;
@@ -90,39 +93,37 @@ public class InventoryBaubles implements IInventory {
* (second arg) of items and returns them in a new stack.
*/
@Override
public ItemStack decrStackSize(int par1, int par2) {
if (this.stackList[par1] != null) {
public ItemStack decrStackSize(int slot, int par2) {
if (this.stackList[slot] != null) {
ItemStack itemstack;
if (this.stackList[par1].stackSize <= par2) {
itemstack = this.stackList[par1];
if (this.stackList[slot].stackSize <= par2) {
itemstack = this.stackList[slot];
if (itemstack != null && itemstack.getItem() instanceof IBauble) {
((IBauble) itemstack.getItem()).onUnequipped(itemstack,
player.get());
((IBauble) itemstack.getItem()).onUnequipped(itemstack, player.get());
}
this.stackList[par1] = null;
this.stackList[slot] = null;
if (eventHandler != null)
this.eventHandler.onCraftMatrixChanged(this);
syncSlotToClients(par1);
syncSlotToClients(slot);
return itemstack;
} else {
itemstack = this.stackList[par1].splitStack(par2);
itemstack = this.stackList[slot].splitStack(par2);
if (itemstack != null && itemstack.getItem() instanceof IBauble) {
((IBauble) itemstack.getItem()).onUnequipped(itemstack,
player.get());
((IBauble) itemstack.getItem()).onUnequipped(itemstack, player.get());
}
if (this.stackList[par1].stackSize == 0) {
this.stackList[par1] = null;
if (this.stackList[slot].stackSize == 0) {
this.stackList[slot] = null;
}
if (eventHandler != null)
this.eventHandler.onCraftMatrixChanged(this);
syncSlotToClients(par1);
syncSlotToClients(slot);
return itemstack;
}
} else {
@@ -135,19 +136,20 @@ public class InventoryBaubles implements IInventory {
* crafting or armor sections).
*/
@Override
public void setInventorySlotContents(int par1, ItemStack stack) {
if(!blockEvents && this.stackList[par1] != null) {
((IBauble)stackList[par1].getItem()).onUnequipped(stackList[par1], player.get());
public void setInventorySlotContents(int slot, ItemStack stack) {
if(!blockEvents && this.stackList[slot] != null) {
((IBauble)stackList[slot].getItem()).onUnequipped(stackList[slot], player.get());
}
this.stackList[par1] = stack;
this.stackList[slot] = stack;
if (!blockEvents && stack != null && stack.getItem() instanceof IBauble) {
if (player.get()!=null)
if (player.get()!=null) {
((IBauble) stack.getItem()).onEquipped(stack, player.get());
}
}
if (eventHandler != null)
if (eventHandler != null) {
this.eventHandler.onCraftMatrixChanged(this);
syncSlotToClients(par1);
}
syncSlotToClients(slot);
}
/**
@@ -175,18 +177,16 @@ public class InventoryBaubles implements IInventory {
* with Container
*/
@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) {
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
/**
@@ -194,19 +194,45 @@ public class InventoryBaubles implements IInventory {
* stack size) into the given slot.
*/
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
if (stack == null || !(stack.getItem() instanceof IBauble)
|| !((IBauble) stack.getItem()).canEquip(stack, player.get()))
public boolean isItemValidForSlot(int slot, ItemStack stack) {
String slotType = BaubleExpandedSlots.getTypeInSlot(slot);
if (stack == null || slotType == null) {
return false;
if (i == 0
&& ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.AMULET)
return true;
if ((i == 1 || i == 2)
&& ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.RING)
return true;
if (i == 3
&& ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.BELT)
return true;
}
Item item = stack.getItem();
if(!(item instanceof IBauble) || !((IBauble) item).canEquip(stack, player.get())) {
return false;
}
String[] types;
if(item instanceof IBaubleExpanded) {
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};
}
for(String type : types) {
if(type.equals(slotType)) {
return true;
}
}
return false;
}
@@ -218,11 +244,11 @@ public class InventoryBaubles implements IInventory {
public void saveNBT(NBTTagCompound tags) {
NBTTagList tagList = new NBTTagList();
NBTTagCompound invSlot;
for (int i = 0; i < this.stackList.length; ++i) {
if (this.stackList[i] != null) {
for (int slot = 0; slot < stackList.length; ++slot) {
if (this.stackList[slot] != null) {
invSlot = new NBTTagCompound();
invSlot.setByte("Slot", (byte) i);
this.stackList[i].writeToNBT(invSlot);
invSlot.setByte("Slot", (byte) slot);
this.stackList[slot].writeToNBT(invSlot);
tagList.appendTag(invSlot);
}
}
@@ -237,53 +263,50 @@ public class InventoryBaubles implements IInventory {
public void readNBT(NBTTagCompound tags) {
NBTTagList tagList = tags.getTagList("Baubles.Inventory", 10);
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound nbttagcompound = (NBTTagCompound) tagList
.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack
.loadItemStackFromNBT(nbttagcompound);
NBTTagCompound nbttagcompound = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);
if (itemstack != null) {
this.stackList[j] = itemstack;
this.stackList[slot] = itemstack;
}
}
}
public void dropItems(ArrayList<EntityItem> drops) {
for (int i = 0; i < 4; ++i) {
if (this.stackList[i] != null) {
EntityItem ei = new EntityItem(player.get().worldObj,
player.get().posX, player.get().posY
+ player.get().eyeHeight, player.get().posZ,
this.stackList[i].copy());
ei.delayBeforeCanPickup = 40;
for (int slot = 0; slot < stackList.length; ++slot) {
if (this.stackList[slot] != null) {
EntityItem item = new EntityItem(player.get().worldObj,
player.get().posX,
player.get().posY + player.get().eyeHeight, player.get().posZ,
this.stackList[slot].copy());
item.delayBeforeCanPickup = 40;
float f1 = player.get().worldObj.rand.nextFloat() * 0.5F;
float f2 = player.get().worldObj.rand.nextFloat()
* (float) Math.PI * 2.0F;
ei.motionX = (double) (-MathHelper.sin(f2) * f1);
ei.motionZ = (double) (MathHelper.cos(f2) * f1);
ei.motionY = 0.20000000298023224D;
drops.add(ei);
this.stackList[i] = null;
syncSlotToClients(i);
float f2 = player.get().worldObj.rand.nextFloat() * (float) Math.PI * 2.0F;
item.motionX = (double) (-MathHelper.sin(f2) * f1);
item.motionZ = (double) (MathHelper.cos(f2) * f1);
item.motionY = 0.20000000298023224D;
drops.add(item);
this.stackList[slot] = null;
syncSlotToClients(slot);
}
}
}
public void dropItemsAt(ArrayList<EntityItem> drops, Entity e) {
for (int i = 0; i < 4; ++i) {
if (this.stackList[i] != null) {
EntityItem ei = new EntityItem(e.worldObj,
e.posX, e.posY + e.getEyeHeight(), e.posZ,
this.stackList[i].copy());
ei.delayBeforeCanPickup = 40;
float f1 = e.worldObj.rand.nextFloat() * 0.5F;
float f2 = e.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F;
ei.motionX = (double) (-MathHelper.sin(f2) * f1);
ei.motionZ = (double) (MathHelper.cos(f2) * f1);
ei.motionY = 0.20000000298023224D;
drops.add(ei);
this.stackList[i] = null;
syncSlotToClients(i);
public void dropItemsAt(ArrayList<EntityItem> drops, Entity entity) {
for (int slot = 0; slot < stackList.length; ++slot) {
if (this.stackList[slot] != null) {
EntityItem item = new EntityItem(entity.worldObj,
entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ,
this.stackList[slot].copy());
item.delayBeforeCanPickup = 40;
float f1 = entity.worldObj.rand.nextFloat() * 0.5F;
float f2 = entity.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F;
item.motionX = (double) (-MathHelper.sin(f2) * f1);
item.motionZ = (double) (MathHelper.cos(f2) * f1);
item.motionY = 0.20000000298023224D;
drops.add(item);
this.stackList[slot] = null;
syncSlotToClients(slot);
}
}
}
@@ -291,11 +314,11 @@ public class InventoryBaubles implements IInventory {
public void syncSlotToClients(int slot) {
try {
if (Baubles.proxy.getClientWorld() == null) {
PacketHandler.INSTANCE.sendToAll(new PacketSyncBauble(player
.get(), slot));
PacketHandler.INSTANCE.sendToAll(new PacketSyncBauble(player.get(), slot));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -3,46 +3,92 @@ package baubles.common.container;
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.ItemStack;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.IBaubleExpanded;
public class SlotBauble extends Slot
{
BaubleType type;
public class SlotBauble extends Slot {
public SlotBauble(IInventory par2IInventory, BaubleType type, int par3, int par4, int par5)
{
super(par2IInventory, par3, par4, par5);
this.type = type;
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";
}
}
public SlotBauble(IInventory inventory, String type, int slot, int x, int y) {
super(inventory, slot, x, y);
this.slotType = type;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack stack)
{
return stack!=null && stack.getItem() !=null &&
stack.getItem() instanceof IBauble &&
((IBauble)stack.getItem()).getBaubleType(stack)==this.type &&
((IBauble)stack.getItem()).canEquip(stack, ((InventoryBaubles)this.inventory).player.get());
public boolean isItemValid(ItemStack stack) {
if (stack == null || slotType == null) {
return false;
}
Item item = stack.getItem();
if(!(item instanceof IBauble) || !((IBauble) item).canEquip(stack, ((InventoryBaubles)inventory).player.get())) {
return false;
}
String[] types;
if(item instanceof IBaubleExpanded) {
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};
}
for(String type : types) {
if(type.equals(slotType)) {
return true;
}
}
return false;
}
@Override
public boolean canTakeStack(EntityPlayer player) {
return this.getStack()!=null &&
((IBauble)this.getStack().getItem()).canUnequip(this.getStack(), player);
return this.getStack()!=null && ((IBauble)this.getStack().getItem()).canUnequip(this.getStack(), player);
}
@Override
public int getSlotStackLimit()
{
public int getSlotStackLimit() {
return 1;
}
}