Jump to content

[1.16.1] Flower Generation crashing on start


Pickle_Face5

Recommended Posts

Hello.

I'm trying to make my Sweet Barry Bushes generate, but now the game crashes on startup.

Here's the gen code:

package com.pickleface.survival.world.gen;

import com.google.common.collect.ImmutableSet;
import com.pickleface.survival.Registry;
import com.pickleface.survival.Survival;
import com.pickleface.survival.blocks.BlueberryBush;
import com.pickleface.survival.blocks.RaspberryBush;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.blockplacer.SimpleBlockPlacer;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.feature.BlockClusterFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.placement.ChanceConfig;
import net.minecraft.world.gen.placement.FrequencyConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.registries.ForgeRegistries;

@Mod.EventBusSubscriber(modid = Survival.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DecorationGen {
    // Get Stuff to Generate
    private static final BlockState BLUEBERRY_BUSH = (BlockState)Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3);
    private static final BlockState RASPBERRY_BUSH = (BlockState)Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3);

    // Make Config With Stuff
    public static final BlockClusterFeatureConfig BLUEBERRY_BUSH_CONFIG = (new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(BLUEBERRY_BUSH), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build();
    public static final BlockClusterFeatureConfig RASPBERRY_BUSH_CONFIG = (new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(RASPBERRY_BUSH), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build();

    @SubscribeEvent
    public static void generateDecorations(final FMLCommonSetupEvent event) {
        for (Biome biome : ForgeRegistries.BIOMES) {
            if (biome == Biomes.PLAINS) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(BLUEBERRY_BUSH_CONFIG).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
            }
            if (biome == Biomes.SUNFLOWER_PLAINS) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(BLUEBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.BIRCH_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.FLOWER_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(6))));
            }
            if (biome == Biomes.DARK_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(18))));
            }
            if (biome == Biomes.JUNGLE_EDGE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(BLUEBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
            }
            if (biome == Biomes.JUNGLE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(BLUEBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
            }
            if (biome == Biomes.MODIFIED_JUNGLE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(BLUEBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration(RASPBERRY_BUSH_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(24))));
            }
        }
    }
}

Any help is appreciated.

Thanks.

Edited by Pickle_Face5
Typo

Have some lorem ispum.

Link to comment
Share on other sites

5 hours ago, Pickle_Face5 said:

private static final BlockState BLUEBERRY_BUSH = (BlockState)Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3); private static final BlockState RASPBERRY_BUSH = (BlockState)Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3);

You can't really do this. When the class is first called by the event bus loader, it will declare these variables prior to the registry phase. So, it will initialize both of these values to null. Just create the variables locally in the event since you're not using them anywhere else. 

 

Two more things, if you need to cast the value to BlockState, you're doing BlockStates wrong. Second, everything must be wrapped in a DeferredWorkQueue as everything you're doing is not thread-safe.

Link to comment
Share on other sites

21 minutes ago, ChampionAsh5357 said:

You can't really do this. When the class is first called by the event bus loader, it will declare these variables prior to the registry phase. So, it will initialize both of these values to null. Just create the variables locally in the event since you're not using them anywhere else. 

 

Two more things, if you need to cast the value to BlockState, you're doing BlockStates wrong. Second, everything must be wrapped in a DeferredWorkQueue as everything you're doing is not thread-safe.

Thanks for the tip! Can you give the updated piece of code though? I'm pretty bad a following tips :P

Also, that explais the 'null' values. When I go ingame, it says null.

Have some lorem ispum.

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

Didn't we already have this in a previous thread? Yes we did.

Stop initializing everything in static initializers.

Works now. Here's my code:

package com.pickleface.survival.world.gen;

import com.google.common.collect.ImmutableSet;
import com.pickleface.survival.Registry;
import com.pickleface.survival.Survival;
import com.pickleface.survival.blocks.BlueberryBush;
import com.pickleface.survival.blocks.RaspberryBush;
import net.minecraft.block.Blocks;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.blockplacer.SimpleBlockPlacer;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.feature.BlockClusterFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.placement.ChanceConfig;
import net.minecraft.world.gen.placement.FrequencyConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.registries.ForgeRegistries;

@Mod.EventBusSubscriber(modid = Survival.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DecorationGen {
    // Get Stuff to Generate
    //private static final BlockState BLUEBERRY_BUSH = Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3);
    //private static final BlockState RASPBERRY_BUSH = Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3);

    // Make Config With Stuff
    //public static final BlockClusterFeatureConfig BLUEBERRY_BUSH_CONFIG = (new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build();
    //public static final BlockClusterFeatureConfig RASPBERRY_BUSH_CONFIG = (new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(RASPBERRY_BUSH), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build();

    @SubscribeEvent
    public static void generateDecorations(final FMLCommonSetupEvent event) {
        for (Biome biome : ForgeRegistries.BIOMES) {
            if (biome == Biomes.PLAINS) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
            }
            if (biome == Biomes.SUNFLOWER_PLAINS) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
            }
            if (biome == Biomes.FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.BIRCH_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.FLOWER_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.DARK_FOREST) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.JUNGLE_EDGE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.JUNGLE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
            if (biome == Biomes.MODIFIED_JUNGLE) {
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.COUNT_HEIGHTMAP_DOUBLE.configure(new FrequencyConfig(1))));
                biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.RANDOM_PATCH.withConfiguration((new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3)), SimpleBlockPlacer.field_236447_c_)).tries(64).whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK.getBlock())).func_227317_b_().build()).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(12))));
            }
        }
    }
}

 

Have some lorem ispum.

Link to comment
Share on other sites

Tip: you can declare your blockstates: 

final BlockState BLUEBERRY_BUSH = Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3);
final BlockState RASPBERRY_BUSH = Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3);

right in front of your for loop (inside the event) as local variables, so you can reuse the blockstates without havining the static initializer problem.

 

 

And consider using a DeferredWorkQueue:

11 hours ago, ChampionAsh5357 said:

Second, everything must be wrapped in a DeferredWorkQueue as everything you're doing is not thread-safe.

 

DeferredWorkQueue example: 

private void commonSetup(final FMLCommonSetupEvent event) {
	DeferredWorkQueue.runLater(() -> {
		//Your Code
	});
}

For more see here: https://championash5357.github.io/ChampionAsh5357/tutorial/minecraft/1.16.1/basic/ore_gen

Link to comment
Share on other sites

9 minutes ago, Maxi07 said:

Tip: you can declare your blockstates: 


final BlockState BLUEBERRY_BUSH = Registry.BLUEBERRY_BUSH.get().getDefaultState().with(BlueberryBush.AGE, 3);
final BlockState RASPBERRY_BUSH = Registry.RASPBERRY_BUSH.get().getDefaultState().with(RaspberryBush.AGE, 3);

right in front of your for loop (inside the event) as local variables, so you can reuse the blockstates without havining the static initializer problem.

 

 

And consider using a DeferredWorkQueue:

 

DeferredWorkQueue example: 


private void commonSetup(final FMLCommonSetupEvent event) {
	DeferredWorkQueue.runLater(() -> {
		//Your Code
	});
}

For more see here: https://championash5357.github.io/ChampionAsh5357/tutorial/minecraft/1.16.1/basic/ore_gen

Thank you! I’ll add this to my code. Also, can I declare the config(commented out right now) as local variables too?

Have some lorem ispum.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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