Posted June 26, 20169 yr I'm trying to make a simple block that just makes a pillar of itself when used. Everything is working when I run it, however problems arise when I save the world and reload it. All of the new blocks placed by the block disappear when the world is reloaded. I haven't been able to find much information on this and I'm relatively new to Minecraft modding and Java my background is in C/C++ for research and robotics. @Override public boolean onBlockActivated( World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote){ return false; } Random rand = new Random(); IBlockState block = world.getBlockState(pos); for(int i = 0; i < 7; i++){ world.setBlockState(pos.add(0, i, 0), block); } for(int k = 0; k < 20; k++){ int x, z; x= rand.nextInt(16)-8; z= rand.nextInt(16)-8; EntityLightningBolt lightning = new EntityLightningBolt(world, pos.getX()+x, pos.getY(), pos.getZ()+z, false); world.addWeatherEffect(lightning); } return true; } I'm working by deconstructing examples but I seem to be missing something. Any advice is appreciated, thanks in advance.
June 26, 20169 yr World#isRemote is true on the client and false on the server, so you're doing everything on the client instead of the server. The server is in charge of the game state, so the changes you make disappear when the client next synchronises with the server. You may want to use the World#rand field instead of creating your own Random each time. Similarly, consider using the specialised methods like BlockPos#up instead of the more general BlockPos#add when only changing one coordinate of a BlockPos . There's no real performance difference, but your code will be a bit clearer. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 26, 20169 yr Author Thank you very much! I removed the negation and it worked fine. Thanks for the advice about cleaning up my code as well. Cheers!
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.