I want to lower the chances that trees will spawn in my custom biome. I watched a tutorial and I was told that I needed to modify the fields of the decorator object from the Biome superclass. Makes sense. It doesn't seem to work though. I seem to have no control from the decorator. Even when I change treesPerChunk to 0 and extraTreeChance to 0, trees still spawn. The numbers seem to have no effect on the rate at which trees generate, and I have no clue what is going on.
package com.nordryd.tutorialmod.world.biome;
import java.util.Random;
import com.nordryd.tutorialmod.blocks.flavors.IceCreamBlocks;
import com.nordryd.tutorialmod.init.ModBlocks;
import com.nordryd.tutorialmod.util.handlers.EnumHandler;
import com.nordryd.tutorialmod.world.gen.generators.trees.ChocolateTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.MintTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.StrawberryTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.VanillaTree;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraft.world.gen.feature.WorldGenMinable;
public class BiomeIceCream extends Biome
{
// check the tree tutorial
public BiomeIceCream(String name) {
// Water color, copy decimal from
// https://www.mathsisfun.com/hexadecimal-decimal-colors.html
super(new BiomeProperties(name).setBaseHeight(0.1F).setHeightVariation(0.2F).setTemperature(0.2F).setRainDisabled().setWaterColor(16751104));
topBlock = ModBlocks.ICE_CREAM_BLOCKS.getDefaultState().withProperty(IceCreamBlocks.VARIANT, EnumHandler.EnumFlavors.VANILLA);
fillerBlock = ModBlocks.ICE_CREAM_BLOCKS.getDefaultState().withProperty(IceCreamBlocks.VARIANT, EnumHandler.EnumFlavors.STRAWBERRY);
// Any coal that would spawn is now the block you specify
this.decorator.coalGen = new WorldGenMinable(ModBlocks.COOKIE_ORE.getDefaultState(), 10);
this.decorator.andesiteGen = new WorldGenMinable(
ModBlocks.ICE_CREAM_BLOCKS.getDefaultState().withProperty(IceCreamBlocks.VARIANT, EnumHandler.EnumFlavors.MINT), 10);
this.decorator.graniteGen = new WorldGenMinable(
ModBlocks.ICE_CREAM_BLOCKS.getDefaultState().withProperty(IceCreamBlocks.VARIANT, EnumHandler.EnumFlavors.MINT), 10);
this.decorator.dioriteGen = new WorldGenMinable(
ModBlocks.ICE_CREAM_BLOCKS.getDefaultState().withProperty(IceCreamBlocks.VARIANT, EnumHandler.EnumFlavors.MINT), 10);
this.decorator.treesPerChunk = 0;
this.decorator.extraTreeChance = 0.05F;
// Clear default spawn lists
this.spawnableCaveCreatureList.clear();
this.spawnableCreatureList.clear();
this.spawnableMonsterList.clear();
this.spawnableWaterCreatureList.clear();
// Add creature to spawn list: new SpawnListEntry(<entity>.class, weight,
// minPackSize, maxPackSize)
this.spawnableCreatureList.add(new SpawnListEntry(EntityVillager.class, 10, 1, 5));
}
@Override
public WorldGenAbstractTree getRandomTreeFeature(Random rand) {
switch (rand.nextInt(3)) {
case 0:
return new VanillaTree();
case 1:
return new MintTree();
case 2:
return new StrawberryTree();
case 3:
return new ChocolateTree();
default:
return new VanillaTree();
}
}
}
package com.nordryd.tutorialmod.world.gen;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import com.nordryd.tutorialmod.init.ModBiomes;
import com.nordryd.tutorialmod.util.variables.Dimensions;
import com.nordryd.tutorialmod.util.variables.ModValues;
import com.nordryd.tutorialmod.world.gen.generators.trees.ChocolateTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.MintTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.StrawberryTree;
import com.nordryd.tutorialmod.world.gen.generators.trees.VanillaTree;
import net.minecraft.init.Biomes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
public class TreeGenerator implements IWorldGenerator
{
private final WorldGenerator VANILLA = new VanillaTree();
private final WorldGenerator MINT = new MintTree();
private final WorldGenerator STRAWBERRY = new StrawberryTree();
private final WorldGenerator CHOCOLATE = new ChocolateTree();
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
switch (world.provider.getDimension()) {
case Dimensions.OVERWORLD:
//runGenerator(VANILLA, world, random, chunkX, chunkZ, 1, -1, 0, Biomes.EXTREME_HILLS.getClass(), ModBiomes.ICE_CREAM.getClass());
runGenerator(MINT, world, random, chunkX, chunkZ, 1, -1, 0, Biomes.EXTREME_HILLS.getClass(), ModBiomes.ICE_CREAM.getClass());
//runGenerator(STRAWBERRY, world, random, chunkX, chunkZ, 1, -1, 0, Biomes.EXTREME_HILLS.getClass(), ModBiomes.ICE_CREAM.getClass());
//runGenerator(CHOCOLATE, world, random, chunkX, chunkZ, 1, -1, 0, Biomes.EXTREME_HILLS.getClass(), ModBiomes.ICE_CREAM.getClass());
break;
case Dimensions.NETHER:
break;
case Dimensions.END:
break;
default:
}
}
// chancesToSpawn = possible trees per chunk
private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, double chancesToSpawn, int minHeight,
int maxHeight, Class<?>... biomeClasses) {
if (chancesToSpawn < 1) {
if (rand.nextDouble() < chancesToSpawn) {
chancesToSpawn = 1;
} else {
chancesToSpawn = 0;
}
}
List<Class<?>> classesList = new ArrayList<Class<?>>(Arrays.asList(biomeClasses));
int heightDiff = maxHeight - minHeight + 1;
for (int i = 0; i < chancesToSpawn; i++) {
BlockPos pos = new BlockPos(chunkX * ModValues.CHUNK_SIZE + 10 + rand.nextInt(ModValues.CHUNK_SIZE - 1),
minHeight + rand.nextInt(heightDiff), chunkZ * ModValues.CHUNK_SIZE + 10 + rand.nextInt(ModValues.CHUNK_SIZE - 1));
if (minHeight < 0) {
pos = world.getHeight(pos);
}
Class<?> biome = world.provider.getBiomeForCoords(pos).getClass();
if (classesList.contains(biome) || biomeClasses.length == 0) {
gen.generate(world, rand, pos);
}
}
}
}
Note: the vanilla, strawberry, and chocolate trees are commented out for testing purposes, and because I wanted to test leaf configurations
I also want this biome to have all the andestite, granite, and diorite replaced with my custom Mint block, and the coal ore to be replaced by my cookie ore. That's not working either. The decorator seems to be completely inconsequential, and I'm needing some help. I'm relatively new to minecraft modding, but I have pretty good knowledge of Java. Thanks for any help!