Jump to content

Changing entity natural spawning -- what is best way? what is setCustomSpawn()?


Recommended Posts

Posted

Okay basically I just want to make a configuration where either only my custom mobs spawn naturally or every mob spawns naturally.

 

I always think that the entity join event will do the trick, but then realize that it seems to be fired not just for spawns but also whenever chunk loads -- right? So if a player spawns a mob with a spawn egg then if that chunk has to load later it would disappear. Right?  Sorry but I always get confused on what "join" means exactly.

 

The entity constructing event doesn't help because it isn't cancelable, although I suppose you could do something like set it dead right away?

 

Anyway, I think the best way is to actually use the removeSpawn method in the EntityRegistry, right? That isn't too hard, so I'll probably do that.

 

However, while looking at EntityRegistry I see a method called setCustomSpawn() which seems to allow you to fully override the spawning functionality. Has anyone used that before? It seems like it could be pretty powerful if you could fully take over the spawning decisions...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

The custom spawning in EntityRegistry is just for when the Entity is being spawned on the client.

 

I am not sure there is an easy way to override the world spawning. You could disallow it entirely using LivingSpawnEvent.CheckSpawn and then do it yourself.  It depends on your actual needs.

 

Oh yeah I forgot about CheckSpawn event. That should work. (My need is to have a config boolean that can prevent all vanilla mobs from naturally spawning while letting my mobs spawn naturally.)

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Actually, CheckSpawn is still giving me some trouble -- it seems to be firing and setting result to DENY but when I make new world it is still full of chickens, pigs, etc.

 

I noticed CheckSpawn is not fired when the "preparing spawn area" messages are happening, but only later when there is a tick. If you look at the call hierarchy it seems that CheckSpawn isn't fired during world gen.

 

My code for the event handler:

    @SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true)
    public void onCheckSpawn(CheckSpawn event)
    {
        if (event.entityLiving instanceof EntityDinosaur)
        {
            if (MyMod.spawnDinosNaturally)
            {
                event.setResult(Result.ALLOW);
            }
            else
            {
                event.setResult(Result.DENY);
            }
        }
        else
        {
            if (MyMod.spawnNonDinoMobsNaturally)
            {
                MyMod.instance.getLogger().debug("Allowing spawn for non-dino");
                event.setResult(Result.ALLOW);
            }
            else
            {
                MyMod.instance.getLogger().debug("Denying spawn for non-dino");
                event.setResult(Result.DENY);
            }      
        }       
    }

 

And it is definitely getting called in game (although not during "preparing spawn area" as I mentioned). I know this because the logger sptis out continuos stream of "Denying spawn for non-dino".

 

So what should I do to prevent generation in the first place? I'm thinking using the removeSpawn from EntityRegistry is cleanest way...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.