Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] [1.14.4] Trouble replacing vanilla block on ChunkEvent.Load
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
StealthyNoodle

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

By StealthyNoodle, January 18, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

StealthyNoodle    1

StealthyNoodle

StealthyNoodle    1

  • Tree Puncher
  • StealthyNoodle
  • Members
  • 1
  • 9 posts
Posted January 18, 2020 (edited)

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 January 19, 2020 by StealthyNoodle
The issue was solved
  • Quote

Share this post


Link to post
Share on other sites

StealthyNoodle    1

StealthyNoodle

StealthyNoodle    1

  • Tree Puncher
  • StealthyNoodle
  • Members
  • 1
  • 9 posts
Posted January 19, 2020

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.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Badnews4u
      My forge server won't load all the mods

      By Badnews4u · Posted 1 minute ago

      Went through all the steps to make forge server hosted from my computer. I was able to successfully launch the server, but after joining the server I noticed not all my mods were working. Most notably it didn't generate a world with biomes o' plenty when I made sure to set the biomes o' plenty default world setting in the configs to true. Also gravestone mod won't give me gravestones. I made sure to update my java and everything and yes, I made sure to create the server using the forge .jar file. Any suggestions on how to fix this?
    • Lellian
      [SOLVED] [1.16.4] Change Block Hitbox/Outline

      By Lellian · Posted 1 hour ago

      Well this is embarrasing. I don't know how I missed this, but it fixed everything.   Thank you very much 🤣🔫
    • Draco18s
      [SOLVED] [1.16.4] Change Block Hitbox/Outline

      By Draco18s · Posted 2 hours ago

      Cough.  
    • Lellian
      [SOLVED] [1.16.4] Change Block Hitbox/Outline

      By Lellian · Posted 2 hours ago

      What do you mean? ExampleBlock is the small stone thing you see in the picture. It gets registered just fine (Via a DeferredRegistry), I can place it and then you see what is in the picture. This is about the hitbox/outline of the block, which I want to be smaller.
    • poopoodice
      [SOLVED] [1.16.4] Change Block Hitbox/Outline

      By poopoodice · Posted 3 hours ago

      You've never use ExampleBlock?
  • Topics

    • Badnews4u
      0
      My forge server won't load all the mods

      By Badnews4u
      Started 1 minute ago

    • Lellian
      4
      [SOLVED] [1.16.4] Change Block Hitbox/Outline

      By Lellian
      Started 3 hours ago

    • Chicckenprell
      0
      stoneblock 1.12.2 server crashing

      By Chicckenprell
      Started 4 hours ago

    • Veo
      2
      Unable to start LAN server detection: Can't assign requested address [Server][Modded][1.16.4]

      By Veo
      Started 8 hours ago

    • Curle
      2
      Dark Theme adjustment

      By Curle
      Started June 27, 2020

  • Who's Online (See full list)

    • LexManos
    • Klarks
    • Qrani
    • Draco18s
    • Lellian
    • kevinseoane6
    • TheHook
    • skip999
    • Rectum
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] [1.14.4] Trouble replacing vanilla block on ChunkEvent.Load
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community