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.

[SOLVED] [1.14.4] Trouble replacing vanilla block on ChunkEvent.Load

Featured Replies

Posted

Hello.

I'm interested in learning to write mods for Minecraft, and have little experience with java from before (got some knowledge in C# and AS though). I've read up on the documentation, and I gotta admit a lot of it is overwhelming! Nevertheless I wanna give it a shot, and am now in process of testing the waters of Forge, and seek your guidance.

Now the problem:
Upon world generation, I wish to replace all stone blocks with a block of different properties and texture. I've somewhat managed to do so, but now the world won't save any changes and all blocks seem to reset upon reentering the world.

Code:

public class HelloEventHandler {
	
	@SubscribeEvent
	public void ChunkLoad(ChunkEvent.Load event)
	{ 	

		//final Logger logger = LogManager.getLogger(Reference.MOD_ID);
		
		IWorld world = event.getWorld();
		IChunk chunk = event.getChunk();
		
		if(!world.isRemote()) {
			
			//logger.info("Hi. this chunk is on server side");
			//if(chunk.isModified() == false) {
			
				Block fromBlock = Blocks.STONE;
				Block toBlock = Blocks.OAK_WOOD;
				
				for(ChunkSection storage : chunk.getSections())
				{
					if(storage != null) {
						
						for (int x = 0; x < 16; ++x) 
						{
							for (int z = 0; z < 16; ++z) 
							{
								for (int y = 0; y < chunk.getTopFilledSegment()+1; ++y) 
								{
									
									if (chunk.getBlockState(new BlockPos(x ,y, z)).getBlock().getDefaultState() == fromBlock.getDefaultState())
						            {
										chunk.setBlockState(new BlockPos(x ,y, z), toBlock.getDefaultState(), true);
						            }
								}
							}
						}
					}
				
				//chunk.setModified(true);
				//}
			}
		}
	}
}



Log:
https://pastebin.com/8d4S1zi6

All I understand from what I'm reading is that the chunks won't load due to a NullPointerException ?

I'm definitely open for other solutions here. At first I tried registering a new block as "minecraft:stone", as done in this thread, but didn't manage to change the texture this way. Searching for an alternative solution I came across this thread which is the origin of the event I'm currently using (I can't seem to find the markDirty-method under the IChunk class, so figured this might have been switched out in 1.14?). I would've thought that changing blocks on world generation would be optimal, but haven't managed to find any examples of this so far - and I'm far too inexperienced to trust my own assumptions. If this is something I easily would've solved with more java-experience, I'll take my leave.

Edited by StealthyNoodle
The issue was solved

  • Author

Seems like the log was referring to world being called, without it being declared first (I would've thought it would declare world every time the event ran).

Checking if world is null seemed to fix the issue, though I guess might not be the most optimal solution?
 

if(world != null) {
	if(!world.isRemote()) {


Anyways, it took care of the problem! I'll carry on.

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.