Jump to content

[1.7.10][Build 1180]Making entities spawn into world


theOriginalByte

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

  • Like 1

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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