Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I made a cavevines decorator feature which places cave vines under the leaves of trees
 

public class CaveVinesFeature extends TreeDecorator {
    public static Codec<CaveVinesFeature> CODEC;
    public static TreeDecoratorType<CaveVinesFeature> type;
    public static float chance=1.0F;
    public static float maxPercent=100F;//0.01F;
    //private float chance;
    private int minAge;
    private int maxAge;
    private float berriesChance;
    private Function<Random, Integer> height;
    //this structure doesn't do anything
    public CaveVinesFeature(float chance){//, int minAge, int maxAge, float berriesChance, Function<Random,Integer> height){
        this.chance=chance;
        this.minAge=25;//minAge;
        this.maxAge=25;//maxAge;
        this.berriesChance=1;//berriesChance;
        this.height=height;
        //CODEC=Codec.unit(() -> this);
    }

    public CaveVinesFeature(){
        this(chance);
    }


    public boolean generateVineColumn(LevelSimulatedReader world, Random random, BlockPos.MutableBlockPos pos, BiConsumer<BlockPos, BlockState> replacer) {
        int length=0;//height.apply(random);
        BlockPos.MutableBlockPos pos1=pos.mutable();
        for(int i=0;i<4;i++){
            Direction dir=Direction.from2DDataValue(i);
            if(!Feature.isAir(world,pos1.move(dir))){
                return false;
            }
            for(int j=0;j<4;j++) {
                Direction dir1 = Direction.from2DDataValue(j);
                if(!Feature.isAir(world,pos1.move(dir).move(dir1))){
                    return false;
                }
            }
        }

        while(Feature.isAir(world,pos1)){
            length++;
            pos1.move(Direction.DOWN);
        }
        length=length-4;
        length=Math.min(length,6);
        //length=length<=0?0:random.nextInt(length);
        boolean flag=false;
        for (int i = 0; i <= length; ++i) {
            if (Feature.isAir(world,pos)) {
                if (i == length || !Feature.isAir(world,pos.below())) {
                    flag=true;
                    int age= Mth.nextInt(random, minAge, maxAge);
                    BlockState state= Blocks.CAVE_VINES.defaultBlockState().setValue(BlockStateProperties.AGE_25, age);
                    state=state.setValue(BlockStateProperties.BERRIES,random.nextFloat()<berriesChance?true:false);
                    replacer.accept(pos,state);
                    break;
                }
                replacer.accept(pos,Blocks.CAVE_VINES_PLANT.defaultBlockState().setValue(BlockStateProperties.BERRIES,random.nextFloat()<berriesChance?true:false));
            }
            pos.move(Direction.DOWN);
        }
        return flag;
    }

    protected TreeDecoratorType<?> type() {
        return type;
    }

    @Override
    public void place(LevelSimulatedReader world, BiConsumer<BlockPos, BlockState> blockSetter, Random random, List<BlockPos> pLogPositions, List<BlockPos> leafPositions) {
        AtomicInteger sum= new AtomicInteger();
        int maxVines=(int)(maxPercent*leafPositions.size());
        List<BlockPos> positions=new ArrayList<>();
        leafPositions.forEach(pos -> {
            if(random.nextFloat()<chance&& sum.get() <maxVines){
                sum.set(sum.get() + 1);
                generateVines(pos,world,random,blockSetter,positions);
            }
        });
    }

    private void generateVines(BlockPos pos, LevelSimulatedReader world, Random random, BiConsumer<BlockPos, BlockState> replacer, List<BlockPos> positions) {
        BlockPos.MutableBlockPos mutable = pos.mutable().move(Direction.DOWN);
        if (!Feature.isAir(world,mutable)) {
            return;
        }
        for(BlockPos pos1: positions){
            int x=pos1.getX();
            int z=pos1.getZ();
            if(Math.abs(x-pos.getX())<4||Math.abs(z-pos.getZ())<4){
                return;
            }
        }
        if(generateVineColumn(world, random, mutable, replacer)){
            positions.add(mutable);
        }
    }

}

Then I registered the cave vines feature

@Mod.EventBusSubscriber(modid = "aoemod", bus = Mod.EventBusSubscriber.Bus.MOD)
public class TreeDecoratorRegistry {

    @SubscribeEvent
    public static void registerFeatures(RegistryEvent.Register<TreeDecoratorType<?>> event) {
        IForgeRegistry registry=event.getRegistry();

        CaveVinesFeature caveVines=new CaveVinesFeature();
        CaveVinesFeature.CODEC= Codec.unit(() -> caveVines);
        CaveVinesFeature.type=(TreeDecoratorType<CaveVinesFeature>) TreeDecoratedAccessor.createType(CaveVinesFeature.CODEC);

        register("cave_vines",registry, CaveVinesFeature.type);
    }
    public static void register(String name,IForgeRegistry registry, TreeDecoratorType decoratorType){
        decoratorType.setRegistryName(new ResourceLocation("aoemod", name));
        registry.register(decoratorType);
    }

}

Then I made JSON file for a configured feature which is a tree that uses my decorator

{
  "type": "minecraft:tree",
  "config": {
    "decorators": [
      {
        "type": "minecraft:cocoa",
        "probability": 0.2
      },
      {
        "type": "minecraft:trunk_vine"
      },
      {
        "type": "aoemod:cave_vines"
      },
      {
        "type": "minecraft:leave_vine",
        "probability": 0.25
      }
    ],
    "dirt_provider": {
      "type": "minecraft:simple_state_provider",
      "state": {
        "Name": "minecraft:dirt"
      }
    },
    "foliage_placer": {
      "type": "minecraft:blob_foliage_placer",
      "height": 3,
      "offset": 0,
      "radius": 2
    },
    "foliage_provider": {
      "type": "minecraft:simple_state_provider",
      "state": {
        "Name": "minecraft:jungle_leaves",
        "Properties": {
          "distance": "7",
          "persistent": "false",
          "waterlogged": "false"
        }
      }
    },
    "force_dirt": false,
    "ignore_vines": true,
    "minimum_size": {
      "type": "minecraft:two_layers_feature_size",
      "limit": 1,
      "lower_size": 0,
      "upper_size": 1
    },
    "trunk_placer": {
      "type": "minecraft:straight_trunk_placer",
      "base_height": 4,
      "height_rand_a": 8,
      "height_rand_b": 0
    },
    "trunk_provider": {
      "type": "minecraft:simple_state_provider",
      "state": {
        "Name": "minecraft:jungle_log",
        "Properties": {
          "axis": "y"
        }
      }
    }
  }
}

When I try to create a world I get the following error:

Spoiler

com.google.gson.JsonParseException: Error loading registry data: Unknown registry key in ResourceKey[minecraft:root / minecraft:worldgen/tree_decorator_type]: aoemod:cave_vines
    at net.minecraft.core.RegistryAccess.lambda$readRegistry$6(RegistryAccess.java:232) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
    at net.minecraft.core.RegistryAccess.readRegistry(RegistryAccess.java:231) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.core.RegistryAccess.load(RegistryAccess.java:219) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.resources.RegistryReadOps.createAndLoad(RegistryReadOps.java:48) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.resources.RegistryReadOps.createAndLoad(RegistryReadOps.java:37) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.lambda$createLevel$34(Minecraft.java:1928) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.makeServerStem(Minecraft.java:2119) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.doLoadLevel(Minecraft.java:1953) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.createLevel(Minecraft.java:1924) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.screens.worldselection.CreateWorldScreen.onCreate(CreateWorldScreen.java:249) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.screens.worldselection.CreateWorldScreen.lambda$init$13(CreateWorldScreen.java:187) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.components.Button.onPress(Button.java:29) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.components.AbstractButton.onClick(AbstractButton.java:17) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.components.AbstractWidget.mouseClicked(AbstractWidget.java:111) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.components.events.ContainerEventHandler.mouseClicked(ContainerEventHandler.java:31) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.MouseHandler.lambda$onPress$0(MouseHandler.java:93) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.gui.screens.Screen.wrapScreenError(Screen.java:527) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.MouseHandler.onPress(MouseHandler.java:90) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.MouseHandler.lambda$setup$4(MouseHandler.java:195) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.util.thread.BlockableEventLoop.execute(BlockableEventLoop.java:90) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.MouseHandler.lambda$setup$5(MouseHandler.java:194) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar%2355!:build 10]
    at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar%2361!:build 10]
    at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar%2355!:build 10]
    at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:162) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at com.mojang.blaze3d.platform.Window.updateDisplay(Window.java:333) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1088) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:665) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at net.minecraft.client.main.Main.main(Main.java:205) ~[forge-1.18.1-39.0.20_mapped_parchment_2021.12.19-1.18.1-recomp.jar%2377!:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:38) ~[fmlloader-1.18.1-39.0.20.jar%230!:?]
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.24.jar%2310!:?]
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?]

I believe that I have registered my cave vines treedecoratedtype incorrectly. I have also put in a print statement instead of the registry event so I know the registry event runs. Please let me know how I can fix the registry event.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.