Posted July 17, 20169 yr Hi, I am calling my change block state method from server tick event grabbing the world from the dimension ID but the blocks don't change in the world. @EventHandler @SubscribeEvent public void serverTickEvent(TickEvent.ServerTickEvent e) { World world = DimensionManager.getWorld(0); //worldTicks = world.getTotalWorldTime(); for (int i = 0; i < world.playerEntities.size(); i++) { EntityPlayer player = (EntityPlayer) world.playerEntities .get(i); int randX = world.rand.nextInt(16); int randZ = world.rand.nextInt(16); int playerPosX = MathHelper.floor_double(player.posX); int playerPosZ = MathHelper.floor_double(player.posY); int randY = getTopBlock(world, randX + playerPosX, randZ + playerPosZ); byte effectRange = 7; for (int zOffset = -effectRange; zOffset <= effectRange; zOffset++) { BlockPos blk = new BlockPos(randX + playerPosX, randY, randZ + playerPosZ); IBlockState block = world.getBlockState(blk); // setBlockState(Blocks.dirt, new BlockPos(blk.getX(), blk.getY(), blk.getZ()), world); // if its grass /*if (block == Blocks.grass || block == Blocks.mycelium) { setBlockState(Blocks.dirt, new BlockPos(blk.getX(), blk.getY(), blk.getZ()), world); } else { System.out.println("No Grass"); }*/ } } } //} private void setBlockState(Block block, BlockPos pos, World world) { if (!world.isRemote) { IBlockState state0 = block.getDefaultState(); world.setBlockState(pos, state0); System.out.println("Block changed"); } else { System.out.println("Block not changed"); } } The console spams out Block changed so the code is being ran but I see no visual change in the world.
July 17, 20169 yr The change is not being sent to the client. Change your setBlockState method from world.setBlockState(pos, state0); to world.setBlockState(pos, state0, 2); where the 2 is a flag that sends the updated state to the client. Please read over the world#setBlockState documentation inside your IDE, for the various flags available. Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
July 17, 20169 yr The change is not being sent to the client. Change your setBlockState method from world.setBlockState(pos, state0); to world.setBlockState(pos, state0, 2); where the 2 is a flag that sends the updated state to the client. Please read over the world#setBlockState documentation inside your IDE, for the various flags available. This isn't quite the case. World#setBlockState(BlockPos, IBlockState) calls World#setBlockState(BlockPos, IBlockState, int) with 3 as the flags argument. Flags are additive, so 3 is both 2 (send the change to clients) and 1 (cause a block update). 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.
July 17, 20169 yr The console spams out Block changed so the code is being ran but I see no visual change in the world.if it says it works, than sometimes it actually works. not always where you want it though. playerPosZ has a bad value. BlockPos blk = new BlockPos(randX + playerPosX, randY, randZ + playerPosZ); setBlockState(Blocks.dirt, new BlockPos(blk.getX(), blk.getY(), blk.getZ()), world); **imagines slapping the guy over the head**
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.