Fix Crystal Chest's crashing clients with ArrayIndexOutOfBoundsException due to two different items having two 64 stacks in the chest, also Items will now render if there is more than one item stack, but only one will be rendered. (Before it wouldn't render any items being in the chest) Closes #90

This commit is contained in:
alexbegt 2017-05-17 15:12:21 -04:00
parent 9515e682ef
commit 82f9d7cf8f
4 changed files with 38 additions and 23 deletions

View File

@ -202,7 +202,7 @@ public enum IronChestType implements IStringSerializable
{ {
if (this == DIRTCHEST9000) if (this == DIRTCHEST9000)
{ {
return itemstack == ItemStack.EMPTY || itemstack.getItem() == DIRT_ITEM; return itemstack.isEmpty() || itemstack.getItem() == DIRT_ITEM;
} }
return true; return true;

View File

@ -42,7 +42,7 @@ public class TileEntityDirtChest extends TileEntityIronChest
@Override @Override
public void removeAdornments() public void removeAdornments()
{ {
if (this.getItems().get(0) != ItemStack.EMPTY && this.getItems().get(0).isItemEqual(dirtChest9000GuideBook)) if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).isItemEqual(dirtChest9000GuideBook))
{ {
this.getItems().set(0, ItemStack.EMPTY); this.getItems().set(0, ItemStack.EMPTY);
} }

View File

@ -153,22 +153,31 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
int compressedIdx = 0; int compressedIdx = 0;
mainLoop: mainLoop: for (int i = 0; i < this.getSizeInventory(); i++)
for (int i = 0; i < this.getSizeInventory(); i++)
{ {
if (this.getItems().get(i) != ItemStack.EMPTY) ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty())
{ {
for (int j = 0; j < compressedIdx; j++) for (int j = 0; j < compressedIdx; j++)
{ {
if (tempCopy.get(j).isItemEqual(this.getItems().get(i))) ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqual(tempCopyStack, itemStack))
{ {
tempCopy.get(j).grow(this.getItems().get(i).getCount()); if (itemStack.getCount() != tempCopyStack.getCount())
{
tempCopyStack.grow(itemStack.getCount());
}
continue mainLoop; continue mainLoop;
} }
} }
tempCopy.set(compressedIdx++, this.getItems().get(i).copy()); tempCopy.set(compressedIdx, itemStack.copy());
compressedIdx++;
hasStuff = true; hasStuff = true;
} }
} }
@ -185,6 +194,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
if (this.world != null) if (this.world != null)
{ {
IBlockState iblockstate = this.world.getBlockState(this.pos); IBlockState iblockstate = this.world.getBlockState(this.pos);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
} }
@ -193,16 +203,15 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.hadStuff = true; this.hadStuff = true;
Collections.sort(tempCopy, new Comparator<ItemStack>() Collections.sort(tempCopy, new Comparator<ItemStack>() {
{
@Override @Override
public int compare(ItemStack stack1, ItemStack stack2) public int compare(ItemStack stack1, ItemStack stack2)
{ {
if (stack1 == ItemStack.EMPTY) if (stack1.isEmpty())
{ {
return 1; return 1;
} }
else if (stack2 == ItemStack.EMPTY) else if (stack2.isEmpty())
{ {
return -1; return -1;
} }
@ -217,14 +226,16 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
for (ItemStack element : tempCopy) for (ItemStack element : tempCopy)
{ {
if (element != ItemStack.EMPTY && element.getCount() > 0) if (!element.isEmpty() && element.getCount() > 0)
{ {
this.getTopItems().set(p++, element);
if (p == this.getTopItems().size()) if (p == this.getTopItems().size())
{ {
break; break;
} }
this.getTopItems().set(p, element);
p++;
} }
} }
@ -327,13 +338,15 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public void update() public void update()
{ {
// Resynchronizes clients with the server state // Resynchronizes clients with the server state
if (this.world != null && !this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0) if (this.world != null && !this.world.isRemote && this.numPlayersUsing != 0
&& (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0)
{ {
this.numPlayersUsing = 0; this.numPlayersUsing = 0;
float f = 5.0F; float f = 5.0F;
for (EntityPlayer player : this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - f, this.pos.getY() - f, this.pos.getZ() - f, this.pos.getX() + 1 + f, this.pos.getY() + 1 + f, this.pos.getZ() + 1 + f))) for (EntityPlayer player : this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - f, this.pos.getY() - f,
this.pos.getZ() - f, this.pos.getX() + 1 + f, this.pos.getY() + 1 + f, this.pos.getZ() + 1 + f)))
{ {
if (player.openContainer instanceof ContainerIronChest) if (player.openContainer instanceof ContainerIronChest)
{ {
@ -504,7 +517,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
for (int i = 0; i < this.getTopItems().size(); i++) for (int i = 0; i < this.getTopItems().size(); i++)
{ {
if (stacks.get(pos) != ItemStack.EMPTY) if (!stacks.get(pos).isEmpty())
{ {
this.getTopItems().set(i, stacks.get(pos)); this.getTopItems().set(i, stacks.get(pos));
} }
@ -529,14 +542,16 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
for (ItemStack is : this.topStacks) for (ItemStack is : this.topStacks)
{ {
if (is != null) if (!is.isEmpty())
{ {
sortList.set(pos++, is); sortList.set(pos, is);
} }
else else
{ {
sortList.set(pos++, ItemStack.EMPTY); sortList.set(pos, ItemStack.EMPTY);
} }
pos++;
} }
return sortList; return sortList;

View File

@ -37,7 +37,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
private ModelChest model; private ModelChest model;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F }, private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
{ 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, }; { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F } };
private static EntityItem customitem = new EntityItem(null); private static EntityItem customitem = new EntityItem(null);
@ -183,7 +183,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
break; break;
} }
if (item == ItemStack.EMPTY) if (item.isEmpty())
{ {
shift++; shift++;
continue; continue;