Jump to content

Recommended Posts

Posted

I'm attempting to add a custom trunk placer for my custom trees. I have attempted to register the type as a new RegistryObject and tried to use Reflection as the TrunkPlacerType register() method is private.

public static final DeferredRegister<TrunkPlacerType<?>> TRUNK_PLACER_TYPES = DeferredRegister.create(Registries.TRUNK_PLACER_TYPE, SlayersBeasts.MOD_ID);

public static final RegistryObject<TrunkPlacerType<CrossTrunkPlacer>> CROSS_TRUNK_PLACER = 
    TRUNK_PLACER_TYPES.register("cross_trunk_placer", () -> new TrunkPlacerType<>(CrossTrunkPlacer.CODEC));

public ModTrunkPlacerTypes(Codec<P> pCodec) { super(pCodec); }

public static void registerTrunkPlacers() {
    try {
    	Method method = ObfuscationReflectionHelper.findMethod(TrunkPlacerType.class, "register", String.class, Codec.class);
        method.setAccessible(true);
        method.invoke(null, "cross_trunk_placer", CrossTrunkPlacer.CODEC);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static void register(IEventBus eventBus) {
    TRUNK_PLACER_TYPES.register(eventBus);
}

The registerTrunkPlacers() method has been called in the event.enqueueWork() supplier in commonSetup.

My issue is now that both saplings and worldgen spawn the tree with acacia trunks and I'm stumped as to why seeing as there is no reference to them in my code and there are no errors in the logs. I did rip some of the vanilla acacia trunk code for reference initially but that has been changed significantly now. And I'm sure it cannot be the CrossTrunkPlacer class as that was working in 1.18.x versions and I can't find any changes to the vanilla classes. This is new code I wrote when porting to 1.19+ created errors.

As I'm quite new to Reflection I'm guessing the issue may lie somewhere in there? Or perhaps that I created a DeferredRegister for a non-forge registry? I am unsure how to continue if anyone has any suggestions.

Posted

Why are you trying to call the TrunkPlacerType.register() method?

All that method does is register the codec with the registry, i.e. exactly what your RegistryObject is doing.

 

Since you don't show any other details, it's impossible to answer your question.

Posting small snippets of code out-of-context isn't going to get you many answers (I would have ignored this post for that reason if it wasn't your first forum post).

Put your code on github where we can see everything in context and maybe try it for ourselves if it is not obvious what the problem is.

 

On a quick search of github: https://github.com/search?q=TrunkPlacerType&type=code

I can see the aether mod creating a trunk placer for a recent version of minecraft.

Maybe you can compare your code with theirs if you don't want to share your code for some reason?

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • InvictusSlayer changed the title to [1.19.3] [solved] custom TrunkPlacerType

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.