Posted January 18, 20205 yr 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, 20205 yr by StealthyNoodle The issue was solved
January 19, 20205 yr 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.