Fabric API

Fabric API

106M Downloads

Unable to register new Chunk Generator Type

Draylar opened this issue ยท 2 comments

commented

#52 references this issue under the "ChunkGeneratorType" section, but I feel like it's different enough to justify a separate issue granted that it's not really related (and is mostly a side note in said issue).

To give context, there is a registry type for chunk generators (CHUNK_GENERATOR_TYPE). This allows you to add new world gen types to the world creation screen (super flat, overworld, etc). The standard format for registering it would be:

6/11: I majorly misunderstood the purpose of this class, but it's still a required change.

ChunkGeneratorType CUSTOM = Registry.register(Registry.CHUNK_GENERATOR_TYPE, "custom", new ChunkGeneratorType<>(OverworldChunkGenerator::new, false, OverworldChunkGeneratorConfig::new));

This is straight out of the vanilla implementation of things. The first argument is a ChunkGeneratorFactory, which is, of course, not available outside the chunk package. It doesn't have any sort of static builder available, either.

Ezwasteland encountered this issue, and you can see part of their explaination & fix here.

It should be fairly obvious right off the bat that this is not an ideal solution-- and at the current stage, adding new generator types does not seem to be possible unless you use their fix.

My idea is adding some sort of FabricChunkGeneratorTypeCreator class which allows the user to create ChunkGeneratorTypes for registration, although I don't have any suggestions as to how that would actually be implemented.

Thanks!

commented

There is actually a far easier way to create a ChunkGeneratorType. As @UpcraftLP noted, the factory is only ever used in a single method in the ChunkGeneratorType itself. As such, you can pass null for the factory in the constructor, and subclass ChunkGeneratorType to override the create method and avoid NPE.

commented

The main issue here is that Mixin can't target a class that's package-private. There are only really three solutions I can think of:

  1. cave and add access transformers (don't really want to do, more of a hassle than it's worth in most cases)
  2. use Ezwasteland's reflection hack (probably a bad idea)
  3. directly inject a class into the minecraft jar to use (absolutely a bad idea and almost definitely impossible bc of jar signing)

Honestly if we could just have ATs for classes only or have better options in Mixin for accessing private classes, I'd be fine by that, but we don't, so we have to do something else.