Sour_Tooth Posted September 16, 2019 Posted September 16, 2019 (edited) Greetings, I am trying to make a mod that randomly generates biomes. My end goal is to call upon a method to generate a biome. Part of my code is this random number generator that generates the color of the grass. static class BiomeGenCustom extends Biome { public RandomBiome() { int Color = myRandomBiome.randomColor(); @SideOnly(Side.CLIENT) public int getGrassColorAtPos(BlockPos pos) { return -Color; } } The issue I've encountered is that myBiome's grass color is generated when Minecraft is launched. Consequently, myBiome's grass color will be re-generated (and changed) every time Minecraft is launched. What I would like to happen is for myBiome's grass color to be generated when the world is made, and stay the same thenceforth. My current idea entails saving myBiome's grass color to myBiome.txt, and referencing that stored number on world load. I, however, have no clue as to how I would approach implementing this idea. If you have any questions, let me know. Thanks, - Riley (I am using 1.12.2) Edited September 16, 2019 by Sour_Tooth Clarification Quote
DavidM Posted September 16, 2019 Posted September 16, 2019 1. Are you sure you've posted the correct code? That will not compile. 2. Check out WorldSavedData. The documentation of which is at https://mcforge.readthedocs.io/en/latest/datastorage/worldsaveddata/. Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
Sour_Tooth Posted September 16, 2019 Author Posted September 16, 2019 9 minutes ago, DavidM said: 1. Are you sure you've posted the correct code? That will not compile. 2. Check out WorldSavedData. The documentation of which is at https://mcforge.readthedocs.io/en/latest/datastorage/worldsaveddata/. Thanks for responding! 1. The code I posted was extracted from a much larger chunk of code. If you’d like, I can update the post with all the code necessary to compile and execute the mod in Minecraft. 2. This seems like it could work, but I’ll have to do some more research. Quote
DavidM Posted September 16, 2019 Posted September 16, 2019 44 minutes ago, Sour_Tooth said: What I would like to happen is for myBiome's grass color to be generated when the world is made, and stay the same thenceforth. Do you wish to make the grass color at the same position in each client the same? i.e. There are two players on a server with your mod. Should the grass color at (0, 0) be the same to both of them? If so, then you could override Biome#getGrassColorAtPos and calculate the color from the xyz coordinates. This would allow the grass color in your world to stay the same when Minecraft is relaunched, and allow the color to be the same on different client. Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
Sour_Tooth Posted September 16, 2019 Author Posted September 16, 2019 (edited) 27 minutes ago, DavidM said: Override Biome#getGrassColorAtPos and calculate the color from the xyz coordinates. This would allow the grass color in your world to stay the same when Minecraft is relaunched, and allow the color to be the same on different client. How would this prevent a new color being generated when Minecraft launches? If I understand you correctly, the grass color at (0, 0) would still be equal to randomColor. If so, then the grass at (0, 0) would still be given a new color at launch. Edited September 16, 2019 by Sour_Tooth Clarification Quote
DavidM Posted September 16, 2019 Posted September 16, 2019 (edited) 6 minutes ago, Sour_Tooth said: If I understand you correctly, the grass color at (0, 0) would still be equal to randomNumber(min, max). By calculating the color from the xyz coordinates I mean generate the color value from the coordinates. That way, the color at a specific position will always be the same (like how Minecraft handles its own grass coloring). An example would be: @Override @SideOnly(Side.Client) public int getGrassColorAtPos(BlockPos pos) { return min + (pos.getX() * pos.getY() * pos.getZ() % (max - min)); } Edited September 16, 2019 by DavidM Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
Sour_Tooth Posted September 16, 2019 Author Posted September 16, 2019 4 minutes ago, DavidM said: @Override @SideOnly(Side.Client) public int getGrassColorAtPos(BlockPos pos) { return min + (pos.getX() * pos.getY() * pos.getZ() % (max - min)); } I’ll test this tomorrow. Thanks for your help! Quote
Recommended Posts
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.