Jump to content

Recommended Posts

Posted (edited)

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!

Edited by nordryd
Posted
4 hours ago, nordryd said:

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 doesn't work because the default implementation of BiomeDecorator resets these to default values every time it decorates a chunk, so you need a custom BiomeDecorator. Use Biome#createBiomeDecorator to have a custom one for your biome.

 

4 hours ago, nordryd said:

Even when I change treesPerChunk to 0 and extraTreeChance to 0, trees still spawn

Are you sure about that? Setting them both to 0 should completely prevent trees from spawning. In your code you don't have them both set to zero. In any case you can simply return a NOOP implementation of WorldGenAbstractTree in Biome#getRandomTreeFeature.

 

4 hours ago, nordryd said:

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(); }

This is not how Random#nextInt works. It returns a number in range of [0 - (max-1)], meaning that in this case it will return [0 - 2] and will never return 3. 

 

4 hours ago, nordryd said:

// Water color, copy decimal from // https://www.mathsisfun.com/hexadecimal-decimal-colors.html

Or you could simply write a hex number through a 0x literal, like 0xffffff for example.

 

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.