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.