Jump to content

Unique EntityId Issues


DrEinsteinium

Recommended Posts

		World world = Minecraft.getMinecraft().theWorld;
	try
	{
	if(Minecraft.getMinecraft().objectMouseOver != null)
		if(Minecraft.getMinecraft().objectMouseOver.entityHit != null)
		{
			if(Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityLiving)
			{Entity entity = (EntityLiving)Minecraft.getMinecraft().objectMouseOver.entityHit;
				Entity entity1 = entity.getClass().getConstructor(new Class[] {World.class}).newInstance(new Object[] {world});

				//The ItemStack to pass to the GUI
				//Since it's an entity, I pass a monster egg.
				ItemStack item = new ItemStack(Item.monsterPlacer);
					item.setItemDamage(entity1.entityId);

				WikiLink.LogHelper.info("Mob Id " + entity1.entityId);	

				//FMLClientHandler.instance().getClient().displayGuiScreen(new GuiContainerMenu(item));
			}	
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}

 

So, using that code, I want to be able to get the "EntityId" of the entity the player is looking at, which works, but it's not the EntityId that I want. I want the integer of the entity that corresponds to the metadata on the spawn eggs.

 

Ex: For IronGolem it is 383:99, yet it returns the unique entity id of the entity in the world, which is some crazy number such as 98741.

 

If anyone has any insight on this, please help, I'm desperate. ;P

 

Cheers,

Follow me on twitter! @keepablock

Read up on whats new! www.catacombs.co

width=700 height=60http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]

Link to comment
Share on other sites

You need to somehow compare it with the EntityList.class and use its ID to class mapping.

 

I would do it like:

public void getEntityEggID(Entity entity1) {
    for (i = 0; i < EntityList.IDtoClassMapping.length(); i++) {
        if (entity1 instanceof EntityList.IDtoClassMapping[i]) {
            return i;
        }
        return -1;
    }
}

 

You will probably need to adjust this code a bit since it is a hash map.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

Thank you both for your answers, as I could have gotten them both to work, but GotoLink's solution was the easiest. :) As for entities from other mods MobId's however, they work, because all entities that can be spawned through mob eggs(which are added by default in forge) get added to the EntityList class.

 

Thanks :)

 

 

Follow me on twitter! @keepablock

Read up on whats new! www.catacombs.co

width=700 height=60http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]

Link to comment
Share on other sites

You could also use

Entity#getPickedResult(MovingObjectPosition)

though i don't know what you want actually.

 

Entity entity = (EntityLiving)Minecraft.getMinecraft().objectMouseOver.entityHit;//useless cast
Entity entity1 = entity.getClass().getConstructor(new Class[] {World.class}).newInstance(new Object[] {world});//why ?

I don't understand that part either.

 

 

Link to comment
Share on other sites

I was actually trying to see if I created a new instance of the same entity if it would give me the correct Id, as it works for a lot of my other code.

 

I've removed that part now.

 

Here is my completed code.

	World world = Minecraft.getMinecraft().theWorld;
	try
	{
	if(Minecraft.getMinecraft().objectMouseOver != null)
		if(Minecraft.getMinecraft().objectMouseOver.entityHit != null)
		{
			if(Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityLiving)
			{Entity entity = (EntityLiving)Minecraft.getMinecraft().objectMouseOver.entityHit;

				//The ItemStack to pass to the GUI
				//Since it's an entity, I pass a monster egg.
				ItemStack item = new ItemStack(Item.monsterPlacer);
					item.setItemDamage(EntityList.getEntityID(entity));

				FMLClientHandler.instance().getClient().displayGuiScreen(new GuiContainerMenu(item));
			}	
		}
		else if(world.blockExists(Minecraft.getMinecraft().objectMouseOver.blockX, 
								  Minecraft.getMinecraft().objectMouseOver.blockY, 
								  Minecraft.getMinecraft().objectMouseOver.blockZ))
			{
				int worldX = Minecraft.getMinecraft().objectMouseOver.blockX;
				int worldY = Minecraft.getMinecraft().objectMouseOver.blockY;
				int worldZ = Minecraft.getMinecraft().objectMouseOver.blockZ;

				int id = world.getBlockId(worldX, worldY, worldZ);
				ItemStack item = new ItemStack(Block.blocksList[id]);

				FMLClientHandler.instance().getClient().displayGuiScreen(new GuiContainerMenu(item));
			}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}

Follow me on twitter! @keepablock

Read up on whats new! www.catacombs.co

width=700 height=60http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]

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.