Updated how the Glass Bell renders its inventory in the TESR

This commit is contained in:
pahimar 2014-02-01 15:22:39 -05:00
parent 1e67db9399
commit 3e2a9e3883
3 changed files with 36 additions and 17 deletions

View file

@ -26,13 +26,11 @@ import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
{
private final ModelGlassBell modelGlassBell = new ModelGlassBell();
private final RenderItem customRenderItem;
public TileEntityGlassBellRenderer()
{
customRenderItem = new RenderItem()
{
@Override
@ -49,7 +47,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick)
{
if (tileEntity instanceof TileGlassBell)
{
TileGlassBell tileGlassBell = (TileGlassBell) tileEntity;
@ -77,15 +74,14 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
*/
GL11.glPushMatrix();
if (tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX) != null)
if (tileGlassBell.outputItemStack != null)
{
float scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX));
float scaleFactor = getGhostItemScaleFactor(tileGlassBell.outputItemStack);
float rotationAngle = (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj);
ghostEntityItem.hoverStart = 0.0F;
ghostEntityItem.setEntityItemStack(tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX));
ghostEntityItem.setEntityItemStack(tileGlassBell.outputItemStack);
translateGhostItemByOrientation(ghostEntityItem.getEntityItem(), x, y, z, tileGlassBell.getOrientation());
GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
@ -103,7 +99,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
private void renderGlassBellByOrientation(double x, double y, double z, ForgeDirection forgeDirection)
{
switch (forgeDirection)
{
case DOWN:
@ -161,7 +156,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
private void translateGhostItemByOrientation(ItemStack ghostItemStack, double x, double y, double z, ForgeDirection forgeDirection)
{
if (ghostItemStack != null)
{
if (ghostItemStack.getItem() instanceof ItemBlock)
@ -255,7 +249,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer
private float getGhostItemScaleFactor(ItemStack itemStack)
{
float scaleFactor = 1.0F;
if (itemStack != null)

View file

@ -136,13 +136,17 @@ public class ClientProxy extends CommonProxy
if (tileEntity instanceof TileGlassBell)
{
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
ItemStack itemStack = null;
if (itemID != -1)
{
ItemHelper.setColor(itemStack, color);
itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
{
ItemHelper.setColor(itemStack, color);
}
}
((TileGlassBell) tileEntity).setInventorySlotContents(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, itemStack);
((TileGlassBell) tileEntity).outputItemStack = itemStack;
world.updateAllLightTypes(x, y, z);
}
else if (tileEntity instanceof TileAludel)

View file

@ -4,6 +4,7 @@ import com.pahimar.ee3.helper.ItemHelper;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.network.PacketTypeHandler;
import com.pahimar.ee3.network.packet.PacketTileWithItemUpdate;
import cpw.mods.fml.common.network.PacketDispatcher;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -12,6 +13,11 @@ import net.minecraft.network.packet.Packet;
public class TileGlassBell extends TileEE implements IInventory
{
/**
* Server sync counter (once per 20 ticks)
*/
private int ticksSinceSync;
/**
* The ItemStacks that hold the items currently being used in the Glass Bell
*/
@ -21,6 +27,8 @@ public class TileGlassBell extends TileEE implements IInventory
public static final int DISPLAY_SLOT_INVENTORY_INDEX = 0;
public ItemStack outputItemStack;
public TileGlassBell()
{
inventory = new ItemStack[INVENTORY_SIZE];
@ -29,7 +37,6 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public int getSizeInventory()
{
return inventory.length;
}
@ -158,10 +165,25 @@ public class TileGlassBell extends TileEE implements IInventory
return true;
}
@Override
public void updateEntity()
{
super.updateEntity();
ItemStack displayStack = this.inventory[DISPLAY_SLOT_INVENTORY_INDEX];
if (!this.worldObj.isRemote)
{
if (++ticksSinceSync % 20 == 0)
{
PacketDispatcher.sendPacketToAllAround(this.xCoord, this.yCoord, this.zCoord, 128d, this.worldObj.provider.dimensionId, getDescriptionPacket());
}
}
}
@Override
public Packet getDescriptionPacket()
{
ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX);
ItemStack itemStack = this.inventory[DISPLAY_SLOT_INVENTORY_INDEX];
if (itemStack != null && itemStack.stackSize > 0)
{
@ -169,7 +191,7 @@ public class TileGlassBell extends TileEE implements IInventory
}
else
{
return super.getDescriptionPacket();
return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, -1, 0, 0, 0));
}
}