Jump to content

[SOLVED]Mob spawns with spawn egg, but doesn't spawn naturally[SOLUTION INSIDE]


Recommended Posts

Posted

Hey,

    My mob spawns with the help of a spawn egg. But it doesn't spawn naturally. Here is my code:-

 

Tutorial.java (Main file)

 

  Reveal hidden contents

 

 

UncleTomo.java

 

  Reveal hidden contents

 

 

EntityUncleTomo.java

 

  Reveal hidden contents

 

 

RenderUncleTomo.java

 

  Reveal hidden contents

 

 

Please help if you can.

 

Regards,

Ablaze.

 

 

Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze"

 

Currently: Making a mod!

Posted

Hi

 

Do you mean - they don't spawn randomly?

 

Have a look in WorldServer.spawnRandomCreature -

    public SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
    {
        List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4);
        list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list);
        return list != null && !list.isEmpty() ? (SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
    }

 

 

It does a call to ForgeEventFactory.getPotentialSpawns (WorldEvent.PotentialSpawns) which I think will let you add your own creatures to the list of creatures provided by the vanilla code.

 

-TGG

Posted
  On 11/3/2013 at 6:46 AM, TheGreyGhost said:

Hi

 

Do you mean - they don't spawn randomly?

 

Have a look in WorldServer.spawnRandomCreature -

    public SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
    {
        List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4);
        list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list);
        return list != null && !list.isEmpty() ? (SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
    }

 

 

It does a call to ForgeEventFactory.getPotentialSpawns (WorldEvent.PotentialSpawns) which I think will let you add your own creatures to the list of creatures provided by the vanilla code.

 

-TGG

 

I don't quite understand what you mean by 'spawn randomly.' Let me give you an example.

 

The Zombie:-

It can spawn in two ways.

 

1. Right click any block with a Zombie Spawn egg and it will spawn.

2. It spawns naturally on a difficulty of Easy or above.

 

Similarly, my mob:-

 

Uncle Tomo:-

It should spawn in two ways:-

 

1. Right click any block with an Uncle Tomo spawn egg and it will spawn. (This method works)

2. It spawns naturally on a difficulty of Easy or above. (This isn't working! It is not spawning naturally!)

 

Regards,

Ablaze.

Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze"

 

Currently: Making a mod!

Posted
  On 11/3/2013 at 7:04 AM, TheGreyGhost said:

Hi

 

Keen, that's what I thought you meant.

 

You can get them to spawn naturally using the Forge event WorldEvent.PotentialSpawns

 

Have you used Forge events before?

A bit of an introduction here - http://www.minecraftforum.net/topic/1419836-131-forge-4x-events-howto/

 

-TGG

 

-TGG

 

I've never used events before. I was reading the article you gave me, but I can't understand much. :( :(

Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze"

 

Currently: Making a mod!

Posted

Hi

 

yeah it's a bit cryptic.  Let's see if I can't adapt a bit of code I've used before...

 

public class MyEventHandler {

  @ForgeSubscribe
  public void addMyCreature(WorldEvent.PotentialSpawns event) {
    World world = event.world;
    int xposition = event.x;
    int yposition = event.y;
    int zposition = event.z;
    EnumCreatureType creatureType = event.type;
    List<SpawnListEntry> listOfSpawnableCreatures = event.list;

    final int SPAWNWEIGHT = 5;  // the higher the number, the more likely this creature will spawn
    final int MINIMUMNUMBERTOSPAWN = 1;
    final int MAXIMUMNUMBERTOSPAWN = 4;

    switch (creatureType) {
      case monster: {
        SpawnListEntry myNewCreatureSpawn = new SpawnListEntry(MyCreature.class, SPAWNWEIGHT, MINIMUMNUMBERTOSPAWN, MAXIMUMNUMBERTOSPAWN);
        listOfSpawnableCreatures.add(myNewCreatureSpawn);
        break;
      }
      case creature:
      case waterCreature:
      case ambient:
      default:  
    }
  }
}

In my mod's base class

  @EventHandler
  public void load(FMLInitializationEvent event) {
    MinecraftForge.EVENT_BUS.register(new MyEventHandler());
  }

 

I haven't actually run that code, but it should be pretty close to what you need.

 

-TGG

Posted

Thanks so much!

 

:D

 

Regards,

Ablaze.

Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze"

 

Currently: Making a mod!

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.