Jump to content

Craftable Item that spawns mobs? [Unsolved]


Scatterbuns

Recommended Posts

First make your standard item class and register it and all that in your main mod class, I'm going to assume you know how to add in a custom recipe if not then stop here and go learn about that, because that's easy compared to making your own entity, anyway back to your item class add in this function

 

public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffSet)
{

		if (world.getBlockId(x, y + 1, z) == 0 && (world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.stone.blockID || world.getBlockId(x, y, z) == Block.dirt.blockID || world.getBlockId(x, y, z) == Block.sand.blockID))
		{
			EntitySkeleton ent = new EntitySkeleton(world); //change to whatever entity you're trying to spawn
			ent.setLocationAndAngles(x, y + 1, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F);
			ent.initCreature();
			world.spawnEntityInWorld(ent);
		}
	return true;
}

 

that function will make it when ever they right click, it will spawn a skeleton, though you can change that to whatever, but first it checks if there's air for it to spawn and if you're spawning it on dirt, grass or sand, though you can take that check out if you wish

Link to comment
Share on other sites

That works but it seems to spawn ghosts of the entity...

 

check if worldObj.isRemote is false when you're trying to spawn something.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

  • 2 months later...

tihs works but the mob usually gets suffocated because they appear on corners

I like helping people because i was also in a same problem and i do not like unfinished work, so a thank you will be enough for the people im helping and a thank you to the people that helped me :)

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.