Posted January 17, 201510 yr I am trying to get the NBT data to sync on a tile entity between client and server. I have the getDescriptionPacket() and onDataPacket() in my tileentity class. I also have worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord) in my updateEntity method. The getDescriptionPacket fires everytime, but the onDataPacket never gets called. I have no clue what im doing wrong. Searched everywhere and can't seem to find the answer. Here is my Tileentity class: public class TileAim extends TileEntity implements IEnergyHandler, IInventory { protected EnergyStorage energy = new EnergyStorage(10000, 80, 0); private ItemStack[] inventory; protected float lastSyncPowerStored = -1; private int storedEnergyRF; public TileAim() { inventory = new ItemStack[2]; } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList list = tag.getTagList("ItemsAim", Constants.NBT.TAG_COMPOUND); for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound item = list.getCompoundTagAt(i); int slot = item.getByte("SlotAim"); if(slot >= 0 && slot < getSizeInventory()) { setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } energy.readFromNBT(tag); } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); NBTTagList list = new NBTTagList(); for(int i = 0; i < getSizeInventory(); i++) { ItemStack itemstack = getStackInSlot(i); if(itemstack != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("SlotAim", (byte) i); itemstack.writeToNBT(item); list.appendTag(item); } } tag.setTag("ItemsAim", list); energy.writeToNBT(tag); } @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); this.writeToNBT(tag); return new S35PacketUpdateTileEntity(xCoord, yCoord, xCoord, 1, tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } @Override public void updateEntity() { if (worldObj.isRemote) return; worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); //markDirty(); } @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { return energy.receiveEnergy(maxReceive, simulate); } @Override public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { return 0; } @Override public int getEnergyStored(ForgeDirection from) { return energy.getEnergyStored(); } @Override public int getMaxEnergyStored(ForgeDirection from) { return energy.getMaxEnergyStored(); } @Override public boolean canConnectEnergy(ForgeDirection from) { return true; } @Override public int getSizeInventory() { return inventory.length; } @Override public ItemStack getStackInSlot(int i) { return inventory[i]; } @Override public ItemStack decrStackSize(int slot, int count) { ItemStack itemstack = getStackInSlot(slot); if(itemstack != null) { if(itemstack.stackSize <= count) { setInventorySlotContents(slot, null); } itemstack = itemstack.splitStack(count); } super.markDirty(); return itemstack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack itemStack = getStackInSlot(slot); setInventorySlotContents(slot, null); return itemStack; } @Override public void setInventorySlotContents(int slot, ItemStack itemstack) { inventory[slot] = itemstack; if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } //onInventoryChanged(); super.markDirty(); } @Override public String getInventoryName() { return "beyondreality:AIM"; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { return true; } public float getPowerScaled() { return (float)energy.getEnergyStored() / (float)energy.getMaxEnergyStored(); } } My updateEntity method is just set like this for testing right now. I wouldn't normally call an update that much.
January 17, 201510 yr Hi Show the code where you register the TileEntity? Also, the Block it's attached to? -TGG
January 17, 201510 yr Author Block Code: public class BlockAim extends BlockContainer { @SideOnly(Side.CLIENT) private IIcon top, front; public BlockAim() { super(Material.rock); this.setHardness(10000.0F); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconregister) { this.blockIcon = iconregister.registerIcon("beyondrealitycore:aim_side"); //this.front = iconregister.registerIcon(this.isBurning2 ? "beyondrealitycore:aim_front_on" : "beyondrealitycore:aim_front_off"); this.front = iconregister.registerIcon("beyondrealitycore:aim_front_off"); this.top = iconregister.registerIcon("beyondrealitycore:aim_top"); } public IIcon getIcon(int side, int meta) { if (side == 1) return this.top; else if (side == 0) return this.top; else if (meta == 2 && side == 2) return this.front; else if (meta == 3 && side == 5) return this.front; else if (meta == 0 && side == 3) return this.front; else if (meta == 1 && side == 4) return this.front; else return this.blockIcon; } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack) { int whichDirectionFacing = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, whichDirectionFacing, 2); } @Override public boolean canHarvestBlock(EntityPlayer player, int meta) { return false; } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public TileEntity createNewTileEntity(World world, int metadata) { return new TileAim(); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ) { if (world.getTileEntity(x, y, z) != null) { player.openGui(BeyondRealityCore.instance, BeyondRealityCore.GUIs.AIM.ordinal(), world, x, y, z); return true; } return true; } } Tile Entity Registration: @EventHandler public void init(FMLInitializationEvent event) { if(ConfigHandler.enableOreBlocks) { CustomOreBlockHandler.oreDictInit(); CraftingHandler.init(); } NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); GameRegistry.registerTileEntity(TileAim.class, "beyondrealitycore:tileAim"); } Any help would be appreciated.
January 17, 201510 yr Hi Spot the fatal flaw... > return new S35PacketUpdateTileEntity(xCoord, yCoord, xCoord, 1, tag); perhaps you need more zzzz's -TGG
January 17, 201510 yr Author I feel like an idiot now except I had someone else look at it and couldn't spot that error. Thank you VERY much!
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.