Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.