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

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!

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

  • Author

ServerWorld, Access Transformers and a list entry, thank you very much, that sends me underway!

I'll figure out what I can, though I am not familiar yet with Access Transformers. Any additional help is appreciated.

  • Author
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

  • Author
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

  • Author
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?

  • Author
Just now, diesieben07 said:

Please learn basic Java.

That's... Why I'm here.

I guess I'll seek assistance elsewhere, then

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.