Posted September 4, 201312 yr Yeah i have a big problem. its just visuell. What it exactly is i can not discribe it. if my integer (MaxStackSize) is above a Short.MaxValue. than it turns it into a Short.MinValue. here my code: package speiger.src.tinychest.common.tileentity.tinychest; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ISidedInventory; import speiger.src.api.common.tile.TileFacing; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TransDimensionaleTinyChest extends TileFacing implements IInventory, ISidedInventory { public ItemStack[] chest; public String invName; public int facing = 0; public int[] storedItemStackSize = new int[9]; public ItemStack[] ID = new ItemStack[9]; public int sizes; public int MaxStackSize = 64; public boolean update = false; public TransDimensionaleTinyChest(String name, int size) { chest = new ItemStack[(size*3)]; invName = name; sizes = size; } public int getInventorySizes() { return sizes; } @SideOnly(Side.CLIENT) public int getStorage(int par1) { return (int)storedItemStackSize[par1]; } @Override public int getSizeInventory() { return chest.length; } public ItemStack getStackInSlot(int par1) { return this.chest[par1]; } public ItemStack decrStackSize(int par1, int par2) { if (this.chest[par1] != null) { ItemStack var3; if (this.chest[par1].stackSize <= par2) { var3 = this.chest[par1]; this.chest[par1] = null; return var3; } else { var3 = this.chest[par1].splitStack(par2); if (this.chest[par1].stackSize == 0) { this.chest[par1] = null; } return var3; } } else { return null; } } public ItemStack getStackInSlotOnClosing(int par1) { if (this.chest[par1] != null) { ItemStack var2 = this.chest[par1]; this.chest[par1] = null; return var2; } else { return null; } } public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { this.chest[par1] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } } public String getInvName() { return invName; } public boolean isUseableByPlayer(EntityPlayer var1) { return true; } public void openChest() { } @Override public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); NBTTagList var5 = par1NBTTagCompound.getTagList("Items2"); this.ID = new ItemStack[this.getSizeInventory()]; for (int var6 = 0; var6 < var5.tagCount(); ++var6) { NBTTagCompound var7 = (NBTTagCompound)var5.tagAt(var6); byte var8 = var7.getByte("Slot2"); if (var8 >= 0 && var8 < this.ID.length) { this.ID[var8] = ItemStack.loadItemStackFromNBT(var7); } } NBTTagList var2 = par1NBTTagCompound.getTagList("Items"); this.chest = new ItemStack[this.getSizeInventory()]; for (int var3 = 0; var3 < var2.tagCount(); ++var3) { NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3); byte var6 = var4.getByte("Slot"); if (var6 >= 0 && var6 < this.chest.length) { this.chest[var6] = ItemStack.loadItemStackFromNBT(var4); } } for(int i = 0;i<this.storedItemStackSize.length;i++) { this.storedItemStackSize[i] = par1NBTTagCompound.getInteger("StoredItems"+i); } facing = par1NBTTagCompound.getInteger("faceing"); MaxStackSize = par1NBTTagCompound.getInteger("MaxStackSizes"); } /** * Writes a tile entity to NBT. */ @Override public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); NBTTagList var5 = new NBTTagList(); for (int var6 = 0; var6 < this.ID.length; ++var6) { if (this.ID[var6] != null) { NBTTagCompound var7 = new NBTTagCompound(); var7.setByte("Slot2", (byte)var6); this.ID[var6].writeToNBT(var7); var5.appendTag(var7); } } par1NBTTagCompound.setTag("Items2", var5); NBTTagList var2 = new NBTTagList(); for (int var3 = 0; var3 < this.chest.length; ++var3) { if (this.chest[var3] != null) { NBTTagCompound var4 = new NBTTagCompound(); var4.setByte("Slot", (byte)var3); this.chest[var3].writeToNBT(var4); var2.appendTag(var4); } } par1NBTTagCompound.setTag("Items", var2); for(int i = 0;i<this.storedItemStackSize.length;i++) { par1NBTTagCompound.setInteger("StoredItems"+i, this.storedItemStackSize[i]); } par1NBTTagCompound.setInteger("faceing", facing); par1NBTTagCompound.setInteger("MaxStackSizes", MaxStackSize); } public void closeChest() { } @Override public int getInventoryStackLimit() { return 64; } @Override public Packet getDescriptionPacket() { NBTTagCompound var1 = new NBTTagCompound(); super.writeToNBT(var1); var1.setInteger("faceing", facing); for(int i = 0;i<this.storedItemStackSize.length;i++) { var1.setInteger("StoredItems"+i, this.storedItemStackSize[i]); } this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, var1); } @Override public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) { this.readFromNBT(pkt.customParam1); } public void updateBlock() { int var1 = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord); markBlockDirty(this.worldObj, this.xCoord, this.yCoord, this.zCoord); } public void markBlockDirty(World var0, int var1, int var2, int var3) { if (var0.blockExists(var1, var2, var3)) { var0.getChunkFromBlockCoords(var1, var3).setChunkModified(); } } @Override public void updateEntity() { super.updateEntity(); updateBlock(); addItems(); eatItems(); if(update) { update = false; this.onInventoryChanged(); } } public void shootoutEntitys(World par0, int par1, int par2, int par3, ItemStack outputed) { float f = par0.rand.nextFloat() * 0.8F + 0.1F; float f1 = par0.rand.nextFloat() * 0.8F + 0.1F; float f2 = par0.rand.nextFloat() * 0.8F + 0.1F; EntityItem entityitem = new EntityItem(par0, par1 + f, par2 + f1 + 0.5F, par3 + f2, outputed); entityitem.delayBeforeCanPickup = 10; float f3 = 0.05F; entityitem.motionX = (float) par0.rand.nextGaussian() * f3; entityitem.motionY = (float) par0.rand.nextGaussian() * f3 + 1.0F; entityitem.motionZ = (float) par0.rand.nextGaussian() * f3; par0.spawnEntityInWorld(entityitem); } public void eatItems() { for(int i = 0; i<sizes;i++) { if(chest[i] != null && chest[i].hasTagCompound()) { shootoutEntitys(worldObj, xCoord, yCoord, zCoord, chest[i]); chest[i] = null; } if(storedItemStackSize[i] < MaxStackSize) { ItemStack current = ID[i]; if(chest[i] != null) { if(current != null && chest[i].itemID == current.itemID && chest[i].getItemDamage() == current.getItemDamage()) { if(storedItemStackSize[i] + 1 <= MaxStackSize) { storedItemStackSize[i]+=1; chest[i].stackSize--; update = true; if(chest[i].stackSize <= 0) { chest[i] = null; update = true; } } } else if(current == null) { ID[i] = new ItemStack(chest[i].getItem(), 1, chest[i].getItemDamage()); storedItemStackSize[i]+=1; chest[i+(sizes*2)] = new ItemStack(chest[i].itemID, 1, chest[i].getItemDamage()); chest[i].stackSize--; update = true; if(chest[i].stackSize <= 0) { chest[i] = null; update = true; } } } } } } public void addItems() { for(int i = 0; i<sizes;i++) { ItemStack current = ID[i]; if(current != null) { if(this.storedItemStackSize[i] > 0) { if(chest[i+sizes] != null && chest[i+sizes].itemID == current.itemID && chest[i+sizes].getItemDamage() == current.getItemDamage()) { if(chest[i+sizes].stackSize + 1 <= 64 && chest[i+sizes].stackSize + 1 <= chest[i+sizes].getMaxStackSize()) { chest[i+sizes].stackSize++; this.storedItemStackSize[i]-=1; update = true; if(this.storedItemStackSize[i] <= 0) { ID[i] = null; chest[i+(sizes*2)] = null; update = true; } } } else if(chest[i+sizes] == null) { chest[i+sizes] = new ItemStack(current.itemID, 1, current.getItemDamage()); this.storedItemStackSize[i]-=1; update = true; if(this.storedItemStackSize[i] <= 0) { ID[i] = null; chest[i+(sizes*2)] = null; update = true; } } } } } } public void addStorage(int storage) { int between = 64; between *= storage; int secand = between / sizes; this.MaxStackSize += secand; } @Override public int getStartInventorySide(ForgeDirection side) { if(side == ForgeDirection.UP) { return 0; } if(side == ForgeDirection.DOWN) { return sizes; } return 0; } @Override public int getSizeInventorySide(ForgeDirection side) { if(side == ForgeDirection.UP) { return sizes; } if(side == ForgeDirection.DOWN) { return sizes; } return 0; } } Here a video so you can see it: Do you know what the trouble is? Its also a bug on 1.6. this code here is more stable. i am still on the update at 1.6
September 5, 201312 yr if my integer (MaxStackSize) is above a Short.MaxValue. than it turns it into a Short.MinValue. Uhm and this ever becomes a problem for you? I don't see why you would ever encounter that problem with Stack Size being higher than Short.MaxValue From oracle's java documentation: short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). Edit: Oh I see, I misunderstood completely due to the name of the variable I thought it was about ItemStack's stack size or how many you could have in a slot. After watching the video I understand what ya mean I'm on way to bed so I can't look more into it, It's an interesting problem though If you guys dont get it.. then well ya.. try harder...
September 5, 201312 yr Author Sorry to say. i figuret out from alone. And you did not read my source. Because then you would see that i never used if(world.isRemote). But thanks for reading^^"
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.