Jump to content

Recommended Posts

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?

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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