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

Hi guys!

I asked this question a while back and never got a specific answer on how to do this. I want to make my entity spawn, like mobs do, into specific areas of the world(mineshafts in particular if its possible). What would I need to put to get this to happen?

Thanks in advance!

You mean to spawn naturally during world creation, or in response to some event or activity on part of the player?

 

The natural spawns that are associated with the defined biomes, I use something like the following (called by my CommonProxy in the preInit() phase).

    public void registerEntitySpawns()
    {
        // register natural spawns for entities
        // EntityRegistry.addSpawn(MyEntity.class, spawnProbability, minSpawn, maxSpawn, enumCreatureType, [spawnBiome]);
        // See the constructor in BiomeGenBase.java to see the rarity of vanilla mobs; Sheep are probability 10 while Endermen are probability 1
        // minSpawn and maxSpawn are about how groups of the entity spawn
        // enumCreatureType represents the "rules" Minecraft uses to determine spawning, based on creature type. By default, you have three choices:
        //    EnumCreatureType.creature uses rules for animals: spawn everywhere it is light out.
        //    EnumCreatureType.monster uses rules for monsters: spawn everywhere it is dark out.
        //    EnumCreatureType.waterCreature uses rules for water creatures: spawn only in water.
        // [spawnBiome] is an optional parameter of type BiomeGenBase that limits the creature spawn to a single biome type. Without this parameter, it will spawn everywhere. 

         // DEBUG
        System.out.println("Registering natural spawns");
        
        // For the biome type you can use an list, but unfortunately the built-in biomeList contains
        // null entries and will crash, so you need to clean up that list.
        // Diesieben07 suggested the following code to remove the nulls and create list of all biomes
        BiomeGenBase[] allBiomes = Iterators.toArray(Iterators.filter(Iterators.forArray(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()), BiomeGenBase.class);

        // savanna
        EntityRegistry.addSpawn(EntityLion.class, 6, 1, 5, EnumCreatureType.creature, BiomeGenBase.savanna); //change the values to vary the spawn rarity, biome, etc.              
        EntityRegistry.addSpawn(EntityElephant.class, 10, 1, 5, EnumCreatureType.creature, BiomeGenBase.savanna); //change the values to vary the spawn rarity, biome, etc.              

        // savannPlateau
        EntityRegistry.addSpawn(EntityLion.class, 6, 1, 5, EnumCreatureType.creature, BiomeGenBase.savannaPlateau); //change the values to vary the spawn rarity, biome, etc.              
        EntityRegistry.addSpawn(EntityElephant.class, 10, 1, 5, EnumCreatureType.creature, BiomeGenBase.savannaPlateau); //change the values to vary the spawn rarity, biome, etc.  
   }            

 

But if you want to spawn in more specific place that isn't already identified as a biome it sort of depends on your ability to find the conditions then use the standard way of spawning in the world.  Basically if you can identify a position to spawn then you can use following to actually spawn:

		if (!world.isRemote)
	{
		System.out.println("Spawning on server side");


	    String fullEntityName = WildAnimals.MODID+"."+entityName; // put string for your entity's name here
	    if (EntityList.stringToClassMapping.containsKey(fullEntityName))
	    {
            Entity conjuredEntity = EntityList.createEntityByName(fullEntityName, world);
    		conjuredEntity.setPosition(locationX, locationY, locationZ); // put the location here that you want
    		world.spawnEntityInWorld(conjuredEntity);
	    }
	    else
	    {
	    	System.out.println("Entity not found");
	    }  

I'm not really sure how you'd identify a mine shaft as the location though, but maybe others have suggestion.

 

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

  • Author

You mean to spawn naturally during world creation, or in response to some event or activity on part of the player?

 

The natural spawns that are associated with the defined biomes, I use something like the following (called by my CommonProxy in the preInit() phase).

    public void registerEntitySpawns()
    {
        // register natural spawns for entities
        // EntityRegistry.addSpawn(MyEntity.class, spawnProbability, minSpawn, maxSpawn, enumCreatureType, [spawnBiome]);
        // See the constructor in BiomeGenBase.java to see the rarity of vanilla mobs; Sheep are probability 10 while Endermen are probability 1
        // minSpawn and maxSpawn are about how groups of the entity spawn
        // enumCreatureType represents the "rules" Minecraft uses to determine spawning, based on creature type. By default, you have three choices:
        //    EnumCreatureType.creature uses rules for animals: spawn everywhere it is light out.
        //    EnumCreatureType.monster uses rules for monsters: spawn everywhere it is dark out.
        //    EnumCreatureType.waterCreature uses rules for water creatures: spawn only in water.
        // [spawnBiome] is an optional parameter of type BiomeGenBase that limits the creature spawn to a single biome type. Without this parameter, it will spawn everywhere. 

         // DEBUG
        System.out.println("Registering natural spawns");
        
        // For the biome type you can use an list, but unfortunately the built-in biomeList contains
        // null entries and will crash, so you need to clean up that list.
        // Diesieben07 suggested the following code to remove the nulls and create list of all biomes
        BiomeGenBase[] allBiomes = Iterators.toArray(Iterators.filter(Iterators.forArray(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()), BiomeGenBase.class);

        // savanna
        EntityRegistry.addSpawn(EntityLion.class, 6, 1, 5, EnumCreatureType.creature, BiomeGenBase.savanna); //change the values to vary the spawn rarity, biome, etc.              
        EntityRegistry.addSpawn(EntityElephant.class, 10, 1, 5, EnumCreatureType.creature, BiomeGenBase.savanna); //change the values to vary the spawn rarity, biome, etc.              

        // savannPlateau
        EntityRegistry.addSpawn(EntityLion.class, 6, 1, 5, EnumCreatureType.creature, BiomeGenBase.savannaPlateau); //change the values to vary the spawn rarity, biome, etc.              
        EntityRegistry.addSpawn(EntityElephant.class, 10, 1, 5, EnumCreatureType.creature, BiomeGenBase.savannaPlateau); //change the values to vary the spawn rarity, biome, etc.  
   }            

 

But if you want to spawn in more specific place that isn't already identified as a biome it sort of depends on your ability to find the conditions then use the standard way of spawning in the world.  Basically if you can identify a position to spawn then you can use following to actually spawn:

		if (!world.isRemote)
	{
		System.out.println("Spawning on server side");


	    String fullEntityName = WildAnimals.MODID+"."+entityName; // put string for your entity's name here
	    if (EntityList.stringToClassMapping.containsKey(fullEntityName))
	    {
            Entity conjuredEntity = EntityList.createEntityByName(fullEntityName, world);
    		conjuredEntity.setPosition(locationX, locationY, locationZ); // put the location here that you want
    		world.spawnEntityInWorld(conjuredEntity);
	    }
	    else
	    {
	    	System.out.println("Entity not found");
	    }  

I'm not really sure how you'd identify a mine shaft as the location though, but maybe others have suggestion.

 

So the first block of code you did would need to go into my proxyCommon class? Can I declare it in my main class file instead?

Guest
This topic is now closed to further replies.

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.