Jump to content

[1.19.3] Making an entity naturally spawn in an existing structure


Kaboom Roads
 Share

Recommended Posts

I've been trying many different ways and I found a way, but it doesn't work with Forge, only Fabric, probably because of the way Forge registers things.

@Mixin(NetherFortressStructure.class)
public abstract class NetherFortressStructureMixin {
    @SuppressWarnings("unchecked")
    @Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/random/WeightedRandomList;create([Lnet/minecraft/util/random/WeightedEntry;)Lnet/minecraft/util/random/WeightedRandomList;"))
    private static <E extends WeightedEntry> WeightedRandomList<E> redirectSpawnerData(E[] array) {
        ArrayList<E> list = new ArrayList<>(List.of(array));
        list.add((E) new MobSpawnSettings.SpawnerData(ModEntityTypes.WILDFIRE.get(), 5, 1, 1));
        return WeightedRandomList.create(list);
    }
}

It tells me "Registry Object not present" with the ModEntityTypes.WILDFIRE.get().

Is there a way I can fix this, and is this even a good way to do this?

Also how do I check if the spawn location is inside a structure if the mixin way fails?

Link to comment
Share on other sites

On 1/22/2023 at 11:40 AM, Kaboom Roads said:

It tells me "Registry Object not present" with the ModEntityTypes.WILDFIRE.get().

Well yeah, mixins are applied manually and vanilla entries are added before mods are even loaded. This generally wouldn't work on Fabric too, but since you can initialize registry objects whenever you want, you typically don't encounter it.

On 1/22/2023 at 11:40 AM, Kaboom Roads said:

Is there a way I can fix this, and is this even a good way to do this?

I can think of a way that involves getting the specific item list from the weighted random, and replacing the immutable list with another to append the entry that would need to be done after registries (so probably common setup), but I would recommend against it as there are probably some side effects I would be neglecting.

On 1/22/2023 at 11:40 AM, Kaboom Roads said:

Also how do I check if the spawn location is inside a structure if the mixin way fails?

SpawnPlacementRegisterEvent and check if the position is in a structure. See LocationPredicate

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

 Share



×
×
  • Create New...

Important Information

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