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

UPDATE - SOLVED

 

So I figured out how to do this.  It's actually pretty simple.  First, create a new class anywhere in your mod, and call it "EntityJoinWorldHandler" or "SpawnHandler" or "SpawnEvent" or whatever you want, as long as it makes sense to you.  The class should look like this:

 

package your.own.package.here;

import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

public class EntityJoinWorldHandler {
@ForgeSubscribe
public void onEntitySpawn(EntityJoinWorldEvent event)
{
	if(event.entity instanceof EntitySkeleton || event.entity instanceof EntityZombie || event.entity instanceof EntitySpider) {
    	event.setCanceled(true);
    }
}
}

 

Note: "onEntitySpawn()" can be named whatever you want, too.  The method name does not actually matter.

 

The class above sets up an event listener that listens for EntityJoinWorldEvent events, which means anytime an entity (like a mob) is spawned into the world, this event triggers.  The if statement within the class checks if the entity spawning is an EntitySkeleton, EntityZombie, or an EntitySpider, and if it's any of those, it cancels the event.  As a result, the mob doesn't spawn in.

 

But you're not done yet.  You still have to register this listener with your mod!  To do that, go into your mod's base class and, in the load() method (under @Init), add this line:

 

MinecraftForge.EVENT_BUS.register(new EntityJoinWorldHandler());

 

Note: "EntityJoinWorldHandler()" should be whatever you named the class above.  Eclipse will probably ask you to import your new class into your base class.  And that's it!  When you run your mod, skeletons, zombies, and spiders will no longer spawn.

 

Now you can add your own mobs to replace them if you like, or do whatever else your mod needs.  :)  Ciao!

 

Original post below:

 

So in net.minecraft.world.SpawnerAnimals.java there's an array that, I'm guessing, tells the game what mobs to spawn at night.  The array is:

 

/** An array of entity classes that spawn at night. */
    protected static final Class[] nightSpawnEntities = new Class[] {EntitySpider.class, EntityZombie.class, EntitySkeleton.class};

 

Is there a way, without editing the base classes, to access and modify this array from within my mod?  I do something similar with the Block.blocksList[] array by removing vanilla blocks from it and registering my own blocks in their places.  Can I do something like that here, to modify this nightSpawnEntities array?

 

Or, is there a different way to remove vanilla spawns that I haven't considered yet?

coremod mod,or array = null......

 

p.s. i dont think what array=null will work,but you can try!

edit: and in both way's,you need coremod mod......

  • Author

You *might* try using events to cancel the spawns. It'll certainly be more ugly, but at least you wouldn't have to use a coremod.

 

Thanks for the response.  :)  I actually already resolved this on my own (I feel the need to mention that because it's significant for me!) and indeed I did do it with an event.  I'll update the original post with how to do it so others who might be looking to do this can hopefully find a resolution.

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.