Posted November 25, 201311 yr 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 http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]
November 25, 201311 yr 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.
November 25, 201311 yr EntityList.getEntityID(Entity) This is what you are looking for. If you want to support a mod added entity, you'd better use EntityList.getEntityString(Entity) And make a different spawner egg to support names instead.
November 25, 201311 yr The more I know PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.
November 25, 201311 yr Author 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 http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]
November 25, 201311 yr 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.
November 25, 201311 yr Author 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 http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]
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.