Jump to content

Illager Patrols spawn code [1.16.5]


Blubbee

Recommended Posts

Hello there!

I'm a new modder. I have created a functional entity similar to Pillagers. Public class net.minecraft.world.spawner.PatrolSpawner which implements ISpecialSpawner spawns these, and I have copied this class with a variant that spawns my own entities.

However, I can't for the life of me figure out where PatrolSpawner is ever called or initiated to happen, and thus, I am also unsure where to start with causing my own custom class to start working. The Illager spawn mechanic is pretty niche to work with and I can't find anything about it.

Does anyone have ideas? Thanks for the help!

Link to comment
Share on other sites

okay the whole thing is a bit complicated, as you already found out
you need an Access Transformers, use it to make the field customSpawners in ServerWorld public
then use WorldEvent.Load and check whether the world of the event is a ServerWorld if so,
you can simply add a new instance of your spawner to the CustomSpawner list

Edit: the AT for ServerWorld.customSpawners is:

public net.minecraft.world.server.ServerWorld field_241104_N_ # customSpawners
Edited by Luis_ST
  • Like 1
Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

There is no reason to use an access transformer or any other hacks like that and it is also not very complicated.

All that is done with the customSpawners field is loop through it and call their tick method if GameRules.RULE_DOMOBSPAWNING is true.

You can achieve the same thing using TickEvent.WorldTickEvent (note though that you need to check the phase field, otherwise your code runs twice every tick).

That sounds feasible! Thank you, I'll try that as well.

Though, silly question maybe, but where would I call customSpawners' tick method? Do you have an example? Should I call it from my RegisterEntities class? I'm not sure how to make it so that I call the method once ServerWorld starts, if that is how it works

Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

From your WorldTickEvent handler.

    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public void onWorldTick(TickEvent.WorldTickEvent event) {
            ServerWorld.tickCustomSpawners(true, true);
        }
    }

 

I have this in my main mod class- I see where it's going, but how do I obtain the correct instance of ServerWorld? I tried getting it by using the event variable by writing "event.world.tickCustomSpawners(true, true);" but I am not sure how to go from a WorldTickEvent to a ServerWorld

Link to comment
Share on other sites

15 minutes ago, diesieben07 said:
  • You are not checking the phase of the event like I told you to.
  • Don't call tickCustomSpawners, that would tick the vanilla spawners... You need to call tick on your spawner.
  • You get the world instance from the event.

MiSquadSpawner is my spawner, which is public int tick(ServerWorld, boolean, boolean).

       @SubscribeEvent
        public void onWorldTick(TickEvent.WorldTickEvent xevent) {
            if (xevent.phase != null) {
                MiSquadSpawner.tick(xevent.world, false, false);
            }
        }

I do not fully understand what to do, how exactly to check the phase, and how to get a ServerWorld from a TickEvent.WorldTickEvent. Currently, the errors I get are-

"xevent cannot be resolved to a type"

"The method tick(Serverworld, boolean, boolean) is not applicable for the arguments (World, boolean, boolean)"

Does anyone know how to continue from here?

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.