Jump to content

[1.8]Having Trouble Getting a Mob to Spawn In a Village


TheExceptionist

Recommended Posts

I been trying for a couple of days now to get a village guard-like mob to spawn in a village that generates in the game. I started by using a forge event "PopulateChunkEvent", but it doesn't seem to be working right.

'

@SubscribeEvent

public void onPopulateChunk(PopulateChunkEvent.Populate event){

FMLLog.getLogger().info("Spawn Watch");

if(event.hasVillageGenerated){

EntityVillageWatch.spawnWatch(event.world);

}

}

'

 

Registering the class into the forge EVENTBUS:

 

'

    @EventHandler

public void preInit(FMLPreInitializationEvent event){

CivItems.init();

CivBlocks.init();

CivItems.register();

CivBlocks.register();

//EntityRegisterCiv.addSpawns();

 

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

}

'

 

My spawnWatch function:

'

    public EntityVillageWatch(World worldIn, int x, int y, int z)

    {

        super(worldIn);

        this.posX = x;

        this.posY = y;

        this.posZ = z;

        this.setSize(1.4F, 2.9F);

        ((PathNavigateGround)this.getNavigator()).func_179690_a(true);

        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true));

        this.tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 0.9D, 32.0F));

        this.tasks.addTask(3, new EntityAIMoveThroughVillage(this, 0.6D, true));

        this.tasks.addTask(4, new EntityAIMoveTowardsRestriction(this, 1.0D));

        this.tasks.addTask(6, new EntityAIWander(this, 0.6D));

        this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));

        this.tasks.addTask(8, new EntityAILookIdle(this));

        this.targetTasks.addTask(1, new EntityAIGuardVillage(this));

        this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false, new Class[0]));

        this.targetTasks.addTask(3, new EntityVillageWatch.AINearestAttackableTargetNonCreeper(this, EntityLiving.class, 10, false, true, IMob.field_175450_e));

    }

   

   

    public static void spawnWatch(World worldIn){

        int i = 0;

        int numWatch = r.nextInt(20)+21;

        List villages = worldIn.getVillageCollection().getVillageList();

       

        while(villages.iterator().hasNext()){

        int numWatchSpawned = 0;

        Village village = (Village) villages.get(i);

       

        BlockPos center = village.getCenter();

        int radius = village.getVillageRadius();

       

        while(numWatchSpawned < numWatch){

        worldIn.spawnEntityInWorld(new EntityVillageWatch(worldIn, center.getX() + r.nextInt(radius), center.getY()+r.nextInt(radius), center.getZ()+r.nextInt(radius)));

        numWatchSpawned++;

        }

       

        i++;

        }

    }

'

Any suggestions or problems you see with this code? Any help is greatly appreciated.

Link to comment
Share on other sites

PopulateChunkEvent is a Forge event. You have to register it to the

MinecraftForge.EVENT_BUS

, but you are registering it to the FML event bus (FMLCommonHandler.instance().bus()).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

All of my bus registrations are in my post init handlers, but yours is in pre init. Try doing it in a later handler.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Registering it later shouldn't make any difference - you can generally register your Forge / FML event handlers at any time during the entire initialization process, as most of them aren't fired until after that has completed.

 

I'm guessing your issue is that you are not adjusting the Y position at all when trying to spawn, so the entities may be trying to spawn in the ground or in the air - try using getWorldHeight(x, z) + 1 as the y position.

 

Also, to be absolutely certain that your event is getting called properly, look in your console log - based on the code you posted, you should see "Spawn Watch" basically spammed all over in it; if not, then your event handler class is somehow set up incorrectly.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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