Yeah my block only updated when the player opens the gui!
why does this happen?
Block:
package speiger.src.tinychest.common.blocks.tinychest;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
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.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import speiger.src.api.common.addonslib.tinychest.TinyChestIDs;
import speiger.src.api.common.addonslib.tinychest.TinyChestTextures;
import speiger.src.tinychest.TinyChest;
import speiger.src.tinychest.client.core.TinyChestClient;
import speiger.src.tinychest.common.config.TinyConfig;
import speiger.src.tinychest.common.lib.TinyFunctions;
import speiger.src.tinychest.common.tileentity.tinychest.TileEntityAdvancedTinyChest;
import speiger.src.tinychest.common.tileentity.tinychest.advanced.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockAdvTinyChest extends BlockContainer
{
private static TinyChestIDs tiny;
private static TinyChestTextures tx;
public BlockAdvTinyChest(int id)
{
super(id, Material.iron);
this.setCreativeTab(TinyChest.tinyChest);
this.setHardness(4.0F);
}
// @Override
// public String getTextureFile()
// {
// return tx.TinyChestBlocksTexturePath;
// }
// @Override
// public boolean renderAsNormalBlock() {
// return false;
// }
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
if(TinyConfig.doDrop)
{
dropInventory(par1World, par2, par3, par4);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
private void dropInventory(World world, int x, int y, int z) {
Random rand = new Random();
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
return;
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound()) {
entityItem.func_92014_d().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return TinyChestClient.advtinyID;
}
// public int getBlockTextureFromSideAndMetadata(int side, int meta)
// {
// if(side == ForgeDirection.NORTH.getOpposite().ordinal())
// if(TinyConfig.differendtextures)
// if(meta == 0)return tx.AdvTinyChestFront1;
// else if(meta == 1)return tx.AdvTinyChestFront2;
// else if(meta == 2)return tx.AdvTinyChestFront3;
// else if(meta == 3)return tx.AdvTinyChestFront4;
// else if(meta == 4)return tx.AdvTinyChestFront5;
// else if(meta == 5)return tx.AdvTinyChestFront6;
// else if(meta == 6)return tx.AdvTinyChestFront7;
// else if(meta == 7)return tx.AdvTinyChestFront8;
// else if(meta == 8)return tx.AdvTinyChestFront9;
// else return 0;
//
// else return tx.AllAdvTinyChestFront;
//
//
// else if(side == 0 || side == 1)return tx.AdvTinyChestTop;
// else return tx.AdvTinyChestSide;
// }
//
//
//
// @Override
// public int getBlockTexture(IBlockAccess world, int var1, int var2, int var3, int side)
// {
// int meta = world.getBlockMetadata(var1, var2, var3);
// TileEntityAdvancedTinyChest te = (TileEntityAdvancedTinyChest)world.getBlockTileEntity(var1, var2, var3);
//
// return te.getTexture(side, meta, te.getFacing());
//
// }
@Override
public void onBlockPlacedBy(World var1, int var2, int var3, int var4, EntityLiving var5)
{
int direction = 2;
TileEntityAdvancedTinyChest par6 = (TileEntityAdvancedTinyChest)var1.getBlockTileEntity(var2, var3, var4);
int facing = MathHelper.floor_double(var5.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (facing == 0) {
direction = ForgeDirection.NORTH.ordinal();
}
else if (facing == 1) {
direction = ForgeDirection.EAST.ordinal();
}
else if (facing == 2) {
direction = ForgeDirection.SOUTH.ordinal();
}
else if (facing == 3) {
direction = ForgeDirection.WEST.ordinal();
}
par6.setFacing(direction);
}
@Override
public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);
if(tile.isFull())return true;
else return false;
}
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3)
{
par3.add(new ItemStack(par1, 1, 0));
par3.add(new ItemStack(par1, 1, 1));
par3.add(new ItemStack(par1, 1, 2));
par3.add(new ItemStack(par1, 1, 3));
par3.add(new ItemStack(par1, 1, 4));
par3.add(new ItemStack(par1, 1, 5));
par3.add(new ItemStack(par1, 1, 6));
par3.add(new ItemStack(par1, 1, 7));
par3.add(new ItemStack(par1, 1, );
}
public boolean canProvidePower()
{
return true;
}
public boolean isProvidingStrongPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
return isPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
}
public boolean isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
return isPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
}
public boolean isPoweringTo(IBlockAccess par1, int par2, int par3, int par4, int par5)
{
TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest)par1.getBlockTileEntity(par2, par3, par4);
if(tile.isFull()) return par5 == 1;
if(tile.isEmpty()) return par5 == 0;
else return false;
}
public boolean onBlockActivated(World par1, int par2, int par3, int par4, EntityPlayer par5, int par6, float par7, float par8, float par9)
{
TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest)par1.getBlockTileEntity(par2, par3, par4);
if(par5.isSneaking())
{
if(par5.getCurrentEquippedItem() == null)
{
tile.setFacing(TinyFunctions.setNextFacing(tile.getFacing()));
par1.markBlockForUpdate(par2, par3, par4);
notifyNeighbors(par1, par2, par3, par4);
par5.addExhaustion(3);
return true;
}
}
if(!par1.isRemote)
{
int meta = par1.getBlockMetadata(par2, par3, par4);
int id = 0;
if(meta == 0)id = tiny.advtinychestguieins;
else if(meta == 1)id = tiny.advtinychestguizwei;
else if(meta == 2)id = tiny.advtinychestguidrei;
else if(meta == 3)id = tiny.advtinychestguivier;
else if(meta == 4)id = tiny.advtinychestguifunf;
else if(meta == 5)id = tiny.advtinychestguisechs;
else if(meta == 6)id = tiny.advtinychestguisieben;
else if(meta == 7)id = tiny.advtinychestguiacht;
else if(meta == 8)id = tiny.advtinychestguineun;
if(tile != null)
{
par5.openGui(TinyChest.instance, id, par1, par2, par3, par4);
return true;
}
}
return true;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return null;
}
public TileEntity createNewTileEntity(World var1, int meta)
{
if(meta == 0)
{
return new AdvancedTinyChestEins();
}
else if(meta == 1)
{
return new AdvancedTinyChestZwei();
}
else if(meta == 2)
{
return new AdvancedTinyChestDrei();
}
else if(meta == 3)
{
return new AdvancedTinyChestVier();
}
else if(meta == 4)
{
return new AdvancedTinyChestFunf();
}
else if(meta == 5)
{
return new AdvancedTinyChestSechs();
}
else if(meta == 6)
{
return new AdvancedTinyChestSieben();
}
else if(meta == 7)
{
return new AdvancedTinyChestAcht();
}
else if(meta ==
{
return new AdvancedTinyChestNeun();
}
return null;
}
public void updateTick(World world, int i, int j, int k, Random random)
{
notifyNeighbors(world, i, j, k);
world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
}
public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
{
notifyNeighbors(world, i, j, k);
}
public void notifyNeighbors(World world, int i, int j, int k)
{
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
}
public void onBlockAdded(World world, int i, int j, int k)
{
world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
}
public int tickRate()
{
return TinyConfig.tickspeed;
}
}
TileEntity:
package speiger.src.tinychest.common.tileentity.tinychest;
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.tileentity.TileEntity;
public abstract class TileEntityAdvancedTinyChest extends TileEntity implements IInventory
{
private int inventorysize;
private String inventoryName;
private ItemStack[] advTinyChest;
private int facing = 0;
private boolean isFull = false;
private boolean isEmpty = true;
private boolean[] chestfulldetect = new boolean[9];
private boolean[] chestemptydetect = new boolean[9];
public TileEntityAdvancedTinyChest(String name, int par1)
{
inventoryName = name;
advTinyChest = new ItemStack[par1];
inventorysize = par1;
}
public int getSizeInventory()
{
return this.advTinyChest.length;
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound var1 = new NBTTagCompound();
super.writeToNBT(var1);
var1.setInteger("faceing", facing);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, var1);
}
@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
this.readFromNBT(pkt.customParam1);
}
public ItemStack getStackInSlot(int par1)
{
return this.advTinyChest[par1];
}
public ItemStack decrStackSize(int par1, int par2)
{
if (this.advTinyChest[par1] != null)
{
ItemStack var3;
if (this.advTinyChest[par1].stackSize <= par2)
{
var3 = this.advTinyChest[par1];
this.advTinyChest[par1] = null;
return var3;
}
else
{
var3 = this.advTinyChest[par1].splitStack(par2);
if (this.advTinyChest[par1].stackSize == 0)
{
this.advTinyChest[par1] = null;
}
return var3;
}
}
else
{
return null;
}
}
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.advTinyChest[par1] != null)
{
ItemStack var2 = this.advTinyChest[par1];
this.advTinyChest[par1] = null;
return var2;
}
else
{
return null;
}
}
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.advTinyChest[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
}
public String getInvName()
{
return inventoryName;
}
public int getInventoryStackLimit()
{
return 64;
}
public boolean isUseableByPlayer(EntityPlayer var1)
{
return true;
}
public void openChest()
{
}
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
this.advTinyChest = new ItemStack[this.getSizeInventory()];
for (int var3 = 0; var3 < var2.tagCount(); ++var3)
{
NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
byte var5 = var4.getByte("Slot");
if (var5 >= 0 && var5 < this.advTinyChest.length)
{
this.advTinyChest[var5] = ItemStack.loadItemStackFromNBT(var4);
}
}
this.facing = par1NBTTagCompound.getInteger("faceing");
}
/**
* Writes a tile entity to NBT.
*/
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList var2 = new NBTTagList();
for (int var3 = 0; var3 < this.advTinyChest.length; ++var3)
{
if (this.advTinyChest[var3] != null)
{
NBTTagCompound var4 = new NBTTagCompound();
var4.setByte("Slot", (byte)var3);
this.advTinyChest[var3].writeToNBT(var4);
var2.appendTag(var4);
}
}
par1NBTTagCompound.setTag("Items", var2);
par1NBTTagCompound.setInteger("faceing", facing);
}
public boolean isFull()
{
return isFull;
}
public boolean isEmpty()
{
return isEmpty;
}
public void closeChest()
{
}
public void setFacing(int i)
{
facing = i;
}
public int getFacing()
{
return facing;
}
public void updateEntity()
{
for(int i = 0; i < getSizeInventory(); i++)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == Math.min(getInventoryStackLimit(), getStackInSlot(i).getMaxStackSize()))
{
this.chestfulldetect[i] = true;
}
else chestfulldetect[i] = false;
if(getStackInSlot(i) == null)
{
chestemptydetect[i] = true;
}
else
{
chestemptydetect[i] = false;
}
}
if(inventorysize == 1)
{
if(chestfulldetect[0] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 2)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 3)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 4)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 5)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 6)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 7)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize ==
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true)isEmpty = true;
else isEmpty = false;
}
else if(inventorysize == 9)
{
if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true && chestfulldetect[8] == true)isFull = true;
else isFull = false;
if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true && chestemptydetect[8] == true)isEmpty = true;
else isEmpty = false;
}
}
public int getTexture(int side, int meta, int facing2)
{
return 0;
}
}
Renderring:
package speiger.src.tinychest.client.render;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import speiger.src.tinychest.client.models.ModelAdvancedTinyChest;
import speiger.src.tinychest.common.tileentity.tinychest.TileEntityAdvancedTinyChest;
public class RenderAdvancedTinyChest extends TileEntitySpecialRenderer {
ModelAdvancedTinyChest model = new ModelAdvancedTinyChest();
@Override
public void renderTileEntityAt(TileEntity var1, double var2, double var4, double var6, float var8)
{
renderChest((TileEntityAdvancedTinyChest)var1, var2, var4, var6, var8);
}
private void renderChest(TileEntityAdvancedTinyChest var1, double var2, double var4, double var6, float var8)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) var2 + 0.5f, (float) var4 + 1.5f, (float) var6 + 0.5f);
if(var1.isFull())
{
bindTextureByName("/speiger/src/tinychest/textures/models/ModelAdvancedTinyChestFull.png");
}
else
{
bindTextureByName("/speiger/src/tinychest/textures/models/ModelAdvancedTinyChest.png");
}
switch(var1.getFacing())
{
case 2: GL11.glRotatef(0, 0.0F, 1.0F, 0.0F); break;
case 3: GL11.glRotatef(180, 0.0F, 1.0F, 0.0F); break;
case 4: GL11.glRotatef(90, 0.0F, 1.0F, 0.0F); break;
case 5: GL11.glRotatef(270, 0.0F, 1.0F, 0.0F); break;
}
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
model.render(0.0625F);
GL11.glPopMatrix();
}
}