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

I'm currently using the method World.setBlockState() to change blocks in the world.

 

However, these blocks disappear when you right click or reload the world.

I'm guessing this has something to do with server/client synchronization, but I don't know for sure.

 

I am using a Server-side Tickhandler.

There is no way, that using ServerTickEvent, this is causing problems. Show your code.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

My Tick event:

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event)
{
	EAPlugin.internalTick();

	for(EAPluginContainer plugin : EALoader.instance().loadedPlugins)
	{
		plugin.plugin.onTick();
	}
}

 

And the code that changes blocks:

@Override
public void onTick()
{
	if(day <= 4) phase = day;
	else phase = 4;

	try
	{
		minecraft.theWorld.setBlockState(new BlockPos(minecraft.thePlayer.posX, minecraft.thePlayer.posY, minecraft.thePlayer.posZ), Blocks.dirt.getDefaultState());
	}
	catch(Exception e)
	{
		System.err.println("Errorino");
	}

	Random random = new Random(1337);
	int randX = random.nextInt();
	int randZ = random.nextInt();
	int randY = EAToolkit.getTopBlock(minecraft.theWorld, randX, randZ);

	try
	{
		if(phase == 1)
		{
			blockBuffer++;

			if(blockBuffer >= 20)
			{
				Block block = minecraft.theWorld.getChunkFromChunkCoords(randX, randZ).getBlock(randX, randY, randZ);

				if(block == Blocks.grass)
				{
					minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.dirt.getDefaultState());
				}

				if(block == Blocks.leaves)
				{
					minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.air.getDefaultState());
				}
			}
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

 

The first setBlockState call is for testing purposes, and right clicking the dirt that is created makes it disappear, breaking it in survival doesn't drop anything but still makes the sound, and world reload removes all dirt and resets my spawn.

Okay, so basically - this code will crash on Dedicated server.

 

You can't access Minecraft.class inside ANY server methods, including ticks.

You are accesting MC.theWorld - this is single, one and only client-sided world (the one your client player is in).

 

Server has x worlds. You need to pick one or use WorldTickEvent to launch tick for all worlds (every world ticks separately).

 

Note: TickEvents have Phases - START and END! Pick one or code will run twice.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

I have started using WorldServer instead of World for my tickhandler, but MinecraftServer.worldServers has nothing in it.

 

It returns ArrayIndexOutOfBounds for whatever number I put in, and if I use a for() loop to get the first WorldServer I can it always uses the default null variable.

In WorldTIckEvent you don't need any of that. This event is launched ONLY ON SERVER SIDE for EVERY world there is.

event.world - will give you direct access.

 

Edit: Just a note: "event is launched ONLY ON SERVER SIDE" might have changed lately, just make sure. (I don't know really, it might also work for client)

1.7.10 is no longer supported by forge, you are on your own.

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.