Posted October 29, 20186 yr Hy, everyone! I have a problem) I create simple TileCounter and BlockCounter. If I click on different sides of the block, then my counter value is updated. And server displays correct value, but client don't. How to sync it? P.S. I'm a beginner in modding. P.S.S. I understand much better if there is a example. Spoiler public class BlockCounter extends Block implements ITileEntityProvider { public BlockCounter(String name) { super(Material.IRON); this.setRegistryName(name); this.setUnlocalizedName(name); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } @Override public boolean onBlockActivated(World world, BlockPos position, IBlockState blockState, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { TileCounter tileEntity = (TileCounter) world.getTileEntity(position); if (!world.isRemote) { if(tileEntity != null) { if(side == EnumFacing.DOWN) { tileEntity.decrementCount(); } if(side == EnumFacing.UP) { tileEntity.incrementCount(); } if(side == EnumFacing.NORTH || side == EnumFacing.SOUTH) { tileEntity.resetCount(); } TextComponentTranslation component = new TextComponentTranslation("[Server] Counter" + tileEntity.getCount(), tileEntity.getCount()); component.getStyle().setColor(TextFormatting.GREEN); player.sendStatusMessage(component, false); } } else { TextComponentTranslation component = new TextComponentTranslation("[CLIENT] Counter" + tileEntity.getCount(), 1); component.getStyle().setColor(TextFormatting.RED); player.sendStatusMessage(component, false); } return true; } public Class<TileCounter> getTileEntityClass() { return TileCounter.class; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileCounter(); } } Spoiler public class TileCounter extends TileEntity { public int count; public TileCounter() { this.count=0; } public int getCount() { return count; } public void incrementCount() { count++; this.markDirty(); } public void decrementCount() { count--; this.markDirty(); } public void resetCount() { count=0; this.markDirty(); } @Override public void readFromNBT(NBTTagCompound compound) { this.count = compound.getInteger("count"); super.readFromNBT(compound); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setInteger("count", this.count); return super.writeToNBT(compound); } @Override @Nullable public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); int meta = getBlockMetadata(); return new SPacketUpdateTileEntity(this.pos, meta, nbt); } @Override public NBTTagCompound getUpdateTag() { return this.writeToNBT(new NBTTagCompound()); } @Override public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity packet) { this.readFromNBT(packet.getNbtCompound()); } @Override public void handleUpdateTag(NBTTagCompound nbt) { this.readFromNBT(nbt); } }
October 29, 20186 yr Looks like you're not syncing the updates to the server. You'll want to look into this https://mcforge.readthedocs.io/en/latest/networking/simpleimpl/
October 30, 20186 yr Don’t use ITileEntityProvider, it’s legacy Minecraft code. Just override hasTileEntity(IBlockState) and getTileEntity in your block class About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
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.