Jump to content

How would I use a Tile Entity to spawn a mob on world tick?


Thornack

Recommended Posts

//How would I use a Tile Entity to spawn one of my custom mobs after x amount of ticks?

 

//I have a block class called spawn.java that extends BlockContainer and a tile entity functionality added to it.

 

public class TileEntitySpawn extends TileEntity [

 

private int timer;

 

public TileEntitySpawn(){

timer = 100;

}

 

@Override

public void updateEntity() {

if timer ==0 && !worldObj.isRemote){

 

}

}

}

 

//I wish to use

 

public void onEntityWalking(World par1World, int i, int j, int k, Entity par5Entity {}

 

//I know you have to use

 

EntityLiving ent = (EntityLiving)EntityList.createEntityByName("",par1World)

ent.setLocationAndAngles(i, j+1, k, 0F, 0F);

 

// but im not sure how to actually get it to spawn this is where I got stuck. Any help would be appreciated. I kind of want to make a custom mob spawner for 1.5.2 but with the walk on functionality added

 

Link to comment
Share on other sites

Two things:

timer--;

worldObj.spawnEntityInWorld(ent);

 

I know about the timer--; part and I have gotten the timer to work properly and count down (if you use ++ it counts up) for example. My issue is using this to call up a method to spawn my mob.

timer--;

 

I have found that

worldObj.spawnEntityInWorld(ent);

doesnt seem to work, and Im not sure why. Ive been trying to figure out how vanilla spawner work with no success yet. I havent been able to find the function that defines which mob spawns or the function that actually spawns them. Ive found the functions that define the spawn delay and radius but im stuck on this one.

Link to comment
Share on other sites

spawnEntityInWorld() works for sure! In Mobspawners this is also used, although I must say the Mobspawner code got more complicated after they added custom entity spawning. On line 140 of the MobspawnerBaseLogic class the obfuscated func_98265_a() gets a call. In there the entity gets spawned at line 217 with getSpawnerWorld().spawnEntityInWorld(par1Entity). Can you show your code which proved to you it didn't work?

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

I have figured it out and it was just me being stupid. The following worked

 

public class TileEntitySpawn extends TileEntity {

 

private int timer;

 

public TileEntitySpawn(){

timer = 100;

}

@Override

public void updateEntity() {

if (timer == 0 && !worldObj.isRemote) {

timespawner(worldObj, xCoord +1, yCoord +2, zCoord +1, null);

timer = 100;

 

 

}

timer--;

}

 

public static void timespawner(World par1World, int i, int j, int k, Entity par5Entity) {

EntityCustomMob CustomMob = new EntityCustomMob(par1World);

CustomMob.setLocationAndAngles(i, j, k, 0.0F, 0.0F);

par1World.spawnEntityInWorld(CustomMob);

}

}

 

 

I do have another question though, which function would I use to synchronize my timer with the world time

 

 

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.