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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER web [ ht tps:// muyerntrusthack.solutions/ ] for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m  
    • Do you have still this problem? (I have it too so I want to know if you did something with it)  
    • Thank you very much, the mod worked. I almost destroyed my computer out of anger because I couldn't find the error.
  • Topics

×
×
  • Create New...

Important Information

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