Actually 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) (pulled from 1.11.2) #89
This commit is contained in:
parent
3561fb4bca
commit
276859566e
|
|
@ -37,16 +37,35 @@ import net.minecraftforge.common.util.Constants;
|
|||
|
||||
public class TileEntityIronChest extends TileEntityLockableLoot implements ITickable, IInventory
|
||||
{
|
||||
private int ticksSinceSync = -1;
|
||||
public float prevLidAngle;
|
||||
public float lidAngle;
|
||||
private int numPlayersUsing;
|
||||
/** Chest Contents */
|
||||
public ItemStack[] chestContents;
|
||||
|
||||
/** Crystal chest top stacks */
|
||||
private ItemStack[] topStacks;
|
||||
|
||||
/** The current angle of the lid (between 0 and 1) */
|
||||
public float lidAngle;
|
||||
|
||||
/** The angle of the lid last tick */
|
||||
public float prevLidAngle;
|
||||
|
||||
/** The number of players currently using this chest */
|
||||
public int numPlayersUsing;
|
||||
|
||||
/** Server sync counter (once per 20 ticks) */
|
||||
private int ticksSinceSync;
|
||||
|
||||
/** Direction chest is facing */
|
||||
private EnumFacing facing;
|
||||
|
||||
/** If the inventory got touched */
|
||||
private boolean inventoryTouched;
|
||||
|
||||
/** If the inventory had items */
|
||||
private boolean hadStuff;
|
||||
|
||||
private String customName;
|
||||
|
||||
private IronChestType chestType;
|
||||
|
||||
public TileEntityIronChest()
|
||||
|
|
@ -139,17 +158,29 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
|
||||
mainLoop: for (int i = 0; i < this.getSizeInventory(); i++)
|
||||
{
|
||||
if (this.chestContents[i] != null)
|
||||
ItemStack itemStack = this.chestContents[i];
|
||||
|
||||
if (itemStack != null)
|
||||
{
|
||||
for (int j = 0; j < compressedIdx; j++)
|
||||
{
|
||||
if (tempCopy[j].isItemEqual(this.chestContents[i]))
|
||||
ItemStack tempCopyStack = tempCopy[j];
|
||||
|
||||
if (ItemStack.areItemsEqual(tempCopyStack, itemStack))
|
||||
{
|
||||
tempCopy[j].stackSize += this.chestContents[i].stackSize;
|
||||
if (itemStack.stackSize != tempCopyStack.stackSize)
|
||||
{
|
||||
tempCopyStack.stackSize += this.chestContents[i].stackSize;
|
||||
}
|
||||
|
||||
continue mainLoop;
|
||||
}
|
||||
}
|
||||
tempCopy[compressedIdx++] = this.chestContents[i].copy();
|
||||
|
||||
tempCopy[compressedIdx] = itemStack.copy();
|
||||
|
||||
compressedIdx++;
|
||||
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -166,6 +197,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
if (this.worldObj != null)
|
||||
{
|
||||
IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
|
||||
|
||||
this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
|
||||
}
|
||||
|
||||
|
|
@ -199,12 +231,14 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
{
|
||||
if (element != null && element.stackSize > 0)
|
||||
{
|
||||
this.topStacks[p++] = element;
|
||||
|
||||
if (p == this.topStacks.length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.topStacks[p] = element;
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -408,9 +442,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
double y = this.pos.getY() + 0.5D;
|
||||
double z = this.pos.getZ() + 0.5D;
|
||||
|
||||
//@formatter:off
|
||||
this.worldObj.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
|
||||
|
|
@ -439,9 +471,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
double y = this.pos.getY() + 0.5D;
|
||||
double z = this.pos.getZ() + 0.5D;
|
||||
|
||||
//@formatter:off
|
||||
this.worldObj.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
if (this.lidAngle < 0.0F)
|
||||
|
|
@ -613,12 +643,14 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
|
|||
{
|
||||
if (is != null)
|
||||
{
|
||||
sortList[pos++] = is;
|
||||
sortList[pos] = is;
|
||||
}
|
||||
else
|
||||
{
|
||||
sortList[pos++] = null;
|
||||
sortList[pos] = null;
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
return sortList;
|
||||
|
|
|
|||
|
|
@ -31,12 +31,16 @@ import net.minecraft.util.EnumFacing;
|
|||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileEntityIronChest>
|
||||
{
|
||||
private Random random;
|
||||
|
||||
private RenderEntityItem itemRenderer;
|
||||
|
||||
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 },
|
||||
{ 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 float halfPI = (float) (Math.PI / 2D);
|
||||
|
||||
public TileEntityIronChestRenderer()
|
||||
|
|
@ -46,26 +50,26 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
|
||||
public void renderTileEntityAt(TileEntityIronChest te, double x, double y, double z, float partialTicks, int destroyStage)
|
||||
{
|
||||
if (tile == null || tile.isInvalid())
|
||||
if (te == null || te.isInvalid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnumFacing facing = EnumFacing.SOUTH;
|
||||
IronChestType type = tile.getType();
|
||||
IronChestType type = te.getType();
|
||||
|
||||
if (tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock)
|
||||
if (te.hasWorldObj() && te.getWorld().getBlockState(te.getPos()).getBlock() == IronChest.ironChestBlock)
|
||||
{
|
||||
facing = tile.getFacing();
|
||||
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
|
||||
facing = te.getFacing();
|
||||
IBlockState state = te.getWorld().getBlockState(te.getPos());
|
||||
type = state.getValue(BlockIronChest.VARIANT_PROP);
|
||||
}
|
||||
|
||||
if (breakStage >= 0)
|
||||
if (destroyStage >= 0)
|
||||
{
|
||||
this.bindTexture(DESTROY_STAGES[breakStage]);
|
||||
this.bindTexture(DESTROY_STAGES[destroyStage]);
|
||||
GlStateManager.matrixMode(5890);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(4F, 4F, 1F);
|
||||
|
|
@ -76,11 +80,14 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
|
|||
{
|
||||
this.bindTexture(type.modelTexture);
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
if (type == IronChestType.CRYSTAL)
|
||||
{
|
||||
GlStateManager.disableCull();
|
||||
}
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
GlStateManager.translate((float) x, (float) y + 1F, (float) z + 1F);
|
||||
GlStateManager.scale(1F, -1F, -1F);
|
||||
|
|
@ -116,7 +123,9 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
|
|||
}
|
||||
|
||||
GlStateManager.translate(-0.5F, -0.5F, -0.5F);
|
||||
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
|
||||
|
||||
float lidangle = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks;
|
||||
|
||||
lidangle = 1F - lidangle;
|
||||
lidangle = 1F - lidangle * lidangle * lidangle;
|
||||
|
||||
|
|
@ -128,63 +137,74 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
|
|||
this.model.chestLid.rotateAngleX = -lidangle * halfPI;
|
||||
// Render the chest itself
|
||||
this.model.renderAll();
|
||||
if (breakStage >= 0)
|
||||
|
||||
if (destroyStage >= 0)
|
||||
{
|
||||
GlStateManager.matrixMode(5890);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.matrixMode(5888);
|
||||
}
|
||||
|
||||
if (type == IronChestType.CRYSTAL)
|
||||
{
|
||||
GlStateManager.enableCull();
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
|
||||
if (type.isTransparent()
|
||||
&& tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d)
|
||||
if (type.isTransparent() && te.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d)
|
||||
{
|
||||
this.random.setSeed(254L);
|
||||
|
||||
float shiftX;
|
||||
float shiftY;
|
||||
float shiftZ;
|
||||
int shift = 0;
|
||||
float blockScale = 0.70F;
|
||||
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTick;
|
||||
if (tile.getTopItemStacks()[1] == null)
|
||||
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
|
||||
|
||||
if (te.getTopItemStacks()[1] == null)
|
||||
{
|
||||
shift = 8;
|
||||
blockScale = 0.85F;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float) x, (float) y, (float) z);
|
||||
|
||||
customitem.setWorld(this.getWorld());
|
||||
customitem.hoverStart = 0F;
|
||||
for (ItemStack item : tile.getTopItemStacks())
|
||||
|
||||
for (ItemStack item : te.getTopItemStacks())
|
||||
{
|
||||
if (shift > shifts.length - 1)
|
||||
if (shift > shifts.length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
shift++;
|
||||
continue;
|
||||
}
|
||||
|
||||
shiftX = shifts[shift][0];
|
||||
shiftY = shifts[shift][1];
|
||||
shiftZ = shifts[shift][2];
|
||||
shift++;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(shiftX, shiftY, shiftZ);
|
||||
GlStateManager.rotate(timeD, 0F, 1F, 0F);
|
||||
GlStateManager.scale(blockScale, blockScale, blockScale);
|
||||
|
||||
customitem.setEntityItemStack(item);
|
||||
|
||||
if (this.itemRenderer == null)
|
||||
{
|
||||
this.itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem()) {
|
||||
this.itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem())
|
||||
{
|
||||
@Override
|
||||
public int getModelCount(ItemStack stack)
|
||||
{
|
||||
|
|
@ -205,7 +225,8 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
|
|||
};
|
||||
}
|
||||
|
||||
this.itemRenderer.doRender(customitem, 0D, 0D, 0D, 0F, partialTick);
|
||||
this.itemRenderer.doRender(customitem, 0D, 0D, 0D, 0F, partialTicks);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue