JimiIT92 Posted May 14, 2014 Posted May 14, 2014 Hi guys I'm making a new biome today but since there isn't anymore the method GameRegistry.registerBiome i can't figure it out how to add a new biome and make it spawn. Actually i've only coded it and registered in the way i see online but it doesn't spawn Here is the code of my custom biome: package mod.mineworld.world.mod_plants; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.feature.WorldGenLiquids; import net.minecraft.world.gen.feature.WorldGenerator; public class BiomeGenAppleForest extends BiomeGenBase { private WorldGenerator WorldGenTrees; private WorldGenerator WorldGenLakes; int color; public BiomeGenAppleForest(int par1) { super(par1); this.theBiomeDecorator.treesPerChunk = 50; this.topBlock = Blocks.grass; this.fillerBlock = Blocks.dirt; this.WorldGenTrees = new WorldGenAppleTrees(false); this.WorldGenLakes = new WorldGenLiquids(Blocks.water); } /** * Gets a WorldGen appropriate for this biome. */ public WorldGenerator getRandomWorldGenForTrees(Random par1Random) { return (WorldGenerator)(par1Random.nextInt(5) == 0 ? this.WorldGenLakes : (par1Random.nextInt(10) == 0 ? this.WorldGenTrees : this.WorldGenTrees)); } public BiomeGenBase setColor(int par1) { this.color = 16711680; return this; } } And here is how i registered it in the main sub-mod file: public static BiomeGenBase AppleForest AppleForest = new BiomeGenAppleForest(154).setColor(353825).setBiomeName("Apple Forest"); BiomeDictionary.registerBiomeType(AppleForest, Type.FOREST); BiomeManager.addSpawnBiome(AppleForest); I think it should be registered this way but i don't know why it doesn't spawn Quote Don't blame me if i always ask for your help. I just want to learn to be better
robustus Posted May 15, 2014 Posted May 15, 2014 http://www.minecraftforge.net/forum/index.php/topic,17885.msg90964.html#msg90964 Quote
JimiIT92 Posted May 16, 2014 Author Posted May 16, 2014 Ok this works but i have to create a new World Type (so when creating a new world specifing this new type)... but how to make it works WITHOUT making this new World Type? How can i add my custom biome to the default world type GenLayer? Quote Don't blame me if i always ask for your help. I just want to learn to be better
Azaka7 Posted May 19, 2014 Posted May 19, 2014 I have a good idea on how to add new biomes without a new world type, but I haven't figured everything out yet. To add your biome to world generation without making a new world type, use the InitBiomeGens event. First, if you haven't made an event handler class for you mod, do so (just a plain class file). Register it in you main class using MinecraftForge.TERRAIN_GEN_BUS.register(new MyEventHandler()); replacing MyEventHandler with whatever you decided to name your event handler. You must register the handler with the terrain gen bus. Then, in your event handler class, use this anotated method: @SubscribeEvent public void registrerBiomes(InitBiomeGens event){ GenLayer layer1 = event.newBiomeGens[0]; GenLayer layer2 = event.newBiomeGens[1]; /* Your genlayer-altering code goes here! */ GenLayer event.newBiomeGens[0] = layer1; GenLayer event.newBiomeGens[1] = layer2; } You can rename the method to whatever you want, but the annotation and argument need to stay the same. You don't necessarily need the layer1 and layer2, but they're just convenient so you don't have to keep referring to the array. To alter the GenLayer, create your own GenLayerMod class (named whatever you want) that extends GenLayer and has a constructor similar to this: public GenLayerMod(long par1, GenLayer par2) { super(par1); this.parent = par2; // TODO Auto-generated constructor stub } You have it alter the world using the public int[] getInts(int par1, int par2, int par3, int par4){} method. To have your new gen layer class take control of world generation, use layer1 = new GenLayerMod(40L,layer1); layer2 = new GenLayerMod(40L,layer2); in the event method. Change the 40L to whatever default randomization seed you feel necessary. The getInts method will take over and that's where you'll get to play with the world generation. This is where I'm stuck. I've looked at vanilla genlayers, and they seem to control the biomes one square block at a time (x and z coords). I recommend using the GenLayerDeepOcean to start out with learning how to identify blocks, but Minecraft's vanilla code has it lucky. All vanilla biomes generate before the world is magnified, so each biome really only needs to generate in the area of a few blocks, then it's all expanded. What's left for us modders is an already magnified world with only the ability to control biomes 1 block at a time. I haven't come up with a good way to go about generating full-scale biomes yet. I really hope Forge eventually adds an easier way to generate biomes. So, overall, adding a new world type is probably the easiest way to generate new biomes. Quote
chrissiOnAir Posted May 23, 2014 Posted May 23, 2014 so, now i tell you what i did yet, without new custom WorldType: I took the InitBiomeGens event like Azaka7 described before. He gets lost while looking all that GenLayers and so do i .. haha .. maybe later when i have time to study that .. but Azaka7, you seem to understand these layers much better than i do, so far .. But i did this: I just copied the public static initializeAllBiomeGenerators() and squeezed my biome in, so i don't have to mess around all these layers! (take a look at my comments ////// and search for "Tutorial".. all other stuff is just copied): package com.chrissionair.tutorial.event; import net.minecraft.world.WorldType; import net.minecraft.world.gen.layer.GenLayer; import net.minecraft.world.gen.layer.GenLayerAddIsland; import net.minecraft.world.gen.layer.GenLayerAddMushroomIsland; import net.minecraft.world.gen.layer.GenLayerAddSnow; import net.minecraft.world.gen.layer.GenLayerBiomeEdge; import net.minecraft.world.gen.layer.GenLayerDeepOcean; import net.minecraft.world.gen.layer.GenLayerEdge; import net.minecraft.world.gen.layer.GenLayerFuzzyZoom; import net.minecraft.world.gen.layer.GenLayerHills; import net.minecraft.world.gen.layer.GenLayerIsland; import net.minecraft.world.gen.layer.GenLayerRareBiome; import net.minecraft.world.gen.layer.GenLayerRemoveTooMuchOcean; import net.minecraft.world.gen.layer.GenLayerRiver; import net.minecraft.world.gen.layer.GenLayerRiverInit; import net.minecraft.world.gen.layer.GenLayerRiverMix; import net.minecraft.world.gen.layer.GenLayerShore; import net.minecraft.world.gen.layer.GenLayerSmooth; import net.minecraft.world.gen.layer.GenLayerVoronoiZoom; import net.minecraft.world.gen.layer.GenLayerZoom; import net.minecraftforge.event.terraingen.WorldTypeEvent.InitBiomeGens; import com.chrissionair.tutorial.world.GenLayerBiome_Tutorial; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class Tutorial_Biome_Event { // Forge WorldTypeEvent used in WorldChunkManager.class @SubscribeEvent public void onBiomeInit(InitBiomeGens e) { e.newBiomeGens = initializeAllBiomeGenerators_Tutorial(e.seed, e.worldType); } // copied from GenLayer.class initializeAllBiomeGenerators() // with only one changed input public static GenLayer[] initializeAllBiomeGenerators_Tutorial(long par0, WorldType par2WorldType) { boolean flag = false; GenLayerIsland genlayerisland = new GenLayerIsland(1L); GenLayerFuzzyZoom genlayerfuzzyzoom = new GenLayerFuzzyZoom(2000L, genlayerisland); GenLayerAddIsland genlayeraddisland = new GenLayerAddIsland(1L, genlayerfuzzyzoom); GenLayerZoom genlayerzoom = new GenLayerZoom(2001L, genlayeraddisland); genlayeraddisland = new GenLayerAddIsland(2L, genlayerzoom); genlayeraddisland = new GenLayerAddIsland(50L, genlayeraddisland); genlayeraddisland = new GenLayerAddIsland(70L, genlayeraddisland); GenLayerRemoveTooMuchOcean genlayerremovetoomuchocean = new GenLayerRemoveTooMuchOcean(2L, genlayeraddisland); GenLayerAddSnow genlayeraddsnow = new GenLayerAddSnow(2L, genlayerremovetoomuchocean); genlayeraddisland = new GenLayerAddIsland(3L, genlayeraddsnow); GenLayerEdge genlayeredge = new GenLayerEdge(2L, genlayeraddisland, GenLayerEdge.Mode.COOL_WARM); genlayeredge = new GenLayerEdge(2L, genlayeredge, GenLayerEdge.Mode.HEAT_ICE); genlayeredge = new GenLayerEdge(3L, genlayeredge, GenLayerEdge.Mode.SPECIAL); genlayerzoom = new GenLayerZoom(2002L, genlayeredge); genlayerzoom = new GenLayerZoom(2003L, genlayerzoom); genlayeraddisland = new GenLayerAddIsland(4L, genlayerzoom); GenLayerAddMushroomIsland genlayeraddmushroomisland = new GenLayerAddMushroomIsland(5L, genlayeraddisland); GenLayerDeepOcean genlayerdeepocean = new GenLayerDeepOcean(4L, genlayeraddmushroomisland); GenLayer genlayer3 = GenLayerZoom.magnify(1000L, genlayerdeepocean, 0); byte b0 = 4; if (par2WorldType == WorldType.LARGE_BIOMES) { b0 = 6; } if (flag) { b0 = 4; } b0 = GenLayer.getModdedBiomeSize(par2WorldType, b0); GenLayer genlayer = GenLayerZoom.magnify(1000L, genlayer3, 0); GenLayerRiverInit genlayerriverinit = new GenLayerRiverInit(100L, genlayer); // BeginnOF my own code // started here to put in the code from getBiomeLayer()-method from WorldType.class // but instead of GenLayerBiome i put here my own GenLayerBiome_Tutorial() // so instead of: Object object = par2WorldType.getBiomeLayer(par0, genlayer3); GenLayer ret = new GenLayerBiome_Tutorial(200L, genlayer3, par2WorldType); ret = GenLayerZoom.magnify(1000L, ret, 2); Object object = new GenLayerBiomeEdge(1000L, ret); // EndOF GenLayer genlayer1 = GenLayerZoom.magnify(1000L, genlayerriverinit, 2); GenLayerHills genlayerhills = new GenLayerHills(1000L, (GenLayer)object, genlayer1); genlayer = GenLayerZoom.magnify(1000L, genlayerriverinit, 2); genlayer = GenLayerZoom.magnify(1000L, genlayer, b0); GenLayerRiver genlayerriver = new GenLayerRiver(1L, genlayer); GenLayerSmooth genlayersmooth = new GenLayerSmooth(1000L, genlayerriver); object = new GenLayerRareBiome(1001L, genlayerhills); for (int j = 0; j < b0; ++j) { object = new GenLayerZoom((long)(1000 + j), (GenLayer)object); if (j == 0) { object = new GenLayerAddIsland(3L, (GenLayer)object); } if (j == 1) { object = new GenLayerShore(1000L, (GenLayer)object); } } GenLayerSmooth genlayersmooth1 = new GenLayerSmooth(1000L, (GenLayer)object); GenLayerRiverMix genlayerrivermix = new GenLayerRiverMix(100L, genlayersmooth1, genlayersmooth); GenLayerVoronoiZoom genlayervoronoizoom = new GenLayerVoronoiZoom(10L, genlayerrivermix); genlayerrivermix.initWorldGenSeed(par0); genlayervoronoizoom.initWorldGenSeed(par0); return new GenLayer[] {genlayerrivermix, genlayervoronoizoom, genlayerrivermix}; } } My own GenLayerBiome_Tutorial(..) looks like this: package com.chrissionair.tutorial.world; import net.minecraft.world.WorldType; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.layer.GenLayer; import net.minecraft.world.gen.layer.IntCache; import com.chrissionair.tutorial.Tutorial; public class GenLayerBiome_Tutorial extends GenLayer { private BiomeGenBase[] field_151623_c; private BiomeGenBase[] field_151621_d; private BiomeGenBase[] field_151622_e; private BiomeGenBase[] field_151620_f; private static final String __OBFID = "CL_00000555"; public GenLayerBiomeTutorial(long par1, GenLayer par3GenLayer, WorldType par4WorldType) { super(par1); this.field_151623_c = new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.desert, BiomeGenBase.desert, BiomeGenBase.savanna, BiomeGenBase.savanna, BiomeGenBase.plains}; this.field_151621_d = new BiomeGenBase[] {BiomeGenBase.forest, BiomeGenBase.roofedForest, BiomeGenBase.extremeHills, BiomeGenBase.plains, BiomeGenBase.birchForest, BiomeGenBase.swampland, Tutorial.tutorialBiome}; this.field_151622_e = new BiomeGenBase[] {BiomeGenBase.forest, BiomeGenBase.extremeHills, BiomeGenBase.taiga, BiomeGenBase.plains, Tutorial.tutorialBiome}; this.field_151620_f = new BiomeGenBase[] {BiomeGenBase.icePlains, BiomeGenBase.icePlains, BiomeGenBase.icePlains, BiomeGenBase.coldTaiga}; this.parent = par3GenLayer; if (par4WorldType == WorldType.DEFAULT_1_1) { this.field_151623_c = new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.forest, BiomeGenBase.extremeHills, BiomeGenBase.swampland, BiomeGenBase.plains, BiomeGenBase.taiga, Tutorial.tutorialBiome}; } } /** * Returns a list of integer values generated by this layer. These may be interpreted as temperatures, rainfall * amounts, or biomeList[] indices based on the particular GenLayer subclass. */ public int[] getInts(int par1, int par2, int par3, int par4) { int[] aint = this.parent.getInts(par1, par2, par3, par4); int[] aint1 = IntCache.getIntCache(par3 * par4); for (int i1 = 0; i1 < par4; ++i1) { for (int j1 = 0; j1 < par3; ++j1) { this.initChunkSeed((long)(j1 + par1), (long)(i1 + par2)); int k1 = aint[j1 + i1 * par3]; int l1 = (k1 & 3840) >> 8; k1 &= -3841; if (isBiomeOceanic(k1)) { aint1[j1 + i1 * par3] = k1; } else if (k1 == BiomeGenBase.mushroomIsland.biomeID) { aint1[j1 + i1 * par3] = k1; } else if (k1 == 1) { if (l1 > 0) { if (this.nextInt(3) == 0) { aint1[j1 + i1 * par3] = BiomeGenBase.mesaPlateau.biomeID; } else { aint1[j1 + i1 * par3] = BiomeGenBase.mesaPlateau_F.biomeID; } } else { aint1[j1 + i1 * par3] = this.field_151623_c[this.nextInt(this.field_151623_c.length)].biomeID; } } else if (k1 == 2) { if (l1 > 0) { aint1[j1 + i1 * par3] = BiomeGenBase.jungle.biomeID; } else { aint1[j1 + i1 * par3] = this.field_151621_d[this.nextInt(this.field_151621_d.length)].biomeID; } } else if (k1 == 3) { if (l1 > 0) { aint1[j1 + i1 * par3] = BiomeGenBase.megaTaiga.biomeID; } else { aint1[j1 + i1 * par3] = this.field_151622_e[this.nextInt(this.field_151622_e.length)].biomeID; } } else if (k1 == 4) { aint1[j1 + i1 * par3] = this.field_151620_f[this.nextInt(this.field_151620_f.length)].biomeID; } else { aint1[j1 + i1 * par3] = BiomeGenBase.mushroomIsland.biomeID; } } } return aint1; } } This is almost a copy of the original except that i put in my Tutorial.tutorialBiome into the biome-arrays at the top. It seems that these arrays are sorted by temperature, so you can decide where (and how often) you put in your Biome, which should be an extended BiomeGenBase of course. Did i forget something? If my code is not working for you, it's maybe because i put an error here, because i renamed some stuff for this post If someone can tell us more, it would be helpful. And maybe i'm wrong in some points. The key seems to be the Forge InitBiomeGens-Event (getModdedBiomeGenerators(..) in WorldChunkManager), which seems to override the original GenLayers, even if they are not modded (newBiomeGens = original.clone()). Because i was worried if i doubled the GenLayers .. but it's ok i think. public WorldChunkManager(long par1, WorldType par3WorldType) { this(); GenLayer[] agenlayer = GenLayer.initializeAllBiomeGenerators(par1, par3WorldType); agenlayer = getModdedBiomeGenerators(par3WorldType, par1, agenlayer); this.genBiomes = agenlayer[0]; this.biomeIndexLayer = agenlayer[1]; } ps: of course you need to define your Biome in your basemod-file, and register the Event there [MinecraftForge.TERRAIN_GEN_BUS.register(new Tutorial_Biome_Event());] as described above in the first post, i think .. I also did register my biome to the Biome-Dictionary. and with the BiomeManager you can modify the spawning, but i'm sure you know these things already 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.