Jump to content

Recommended Posts

Posted (edited)
On 16/02/2017 at 1:37 PM, Choonster said:

EntityLiving#inventoryHandsDropChances and EntityLiving#inventoryArmorDropChances store the drop chances for the entity's held items and armour respectively. These fields are both protected, so you'll need to use reflection to access them.

 

 

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Hmmmm... Im having trouble getting the field. the crash report says it cannot find it. What am I doing wrong?

 

	public void playerTick(PlayerTickEvent event) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException
	{
		List<Entity> entities = event.player.getEntityWorld().getEntitiesWithinAABBExcludingEntity(event.player, event.player.getEntityBoundingBox().expand(5.0D, 5.0D, 5.0D));
		for(Entity entity : entities){
			if((entity instanceof EntityMob && ((EntityLivingBase) entity).getHeldItemMainhand() != null && !previousmobs.contains(entity))){
				Field dropchance = null;
				dropchance = ((EntityLiving)entity).getClass().getDeclaredField("inventoryHandsDropChances");
				dropchance.setAccessible(true);
				Object floatchance = dropchance.get(entity);
				event.player.addChatMessage(((EntityLivingBase) entity).getHeldItemMainhand().getTextComponent().appendSibling((new TextComponentString(" Drop Chance: ").appendText(Array.get(floatchance , 0).toString()))));

 

 

Crash Report: 

[11:04:45] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:210) ~[NetworkSystem.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:806) ~[MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) ~[MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: inventoryHandsDropChances
	at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?]
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:191) ~[EventBus.class:?]
	at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPreTick(FMLCommonHandler.java:360) ~[FMLCommonHandler.class:?]
	at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:215) ~[EntityPlayer.class:?]
	at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) ~[EntityPlayerMP.class:?]
	at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:174) ~[NetHandlerPlayServer.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:216) ~[NetworkDispatcher$1.class:?]
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:308) ~[NetworkManager.class:?]
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:195) ~[NetworkSystem.class:?]
	... 5 more
Caused by: java.lang.NoSuchFieldException: inventoryHandsDropChances

 

Posted

A few things:

Don't ever use reflection inside a tick or update event.  That is, the "go find this by string name" because it's expensive as hell.  Get the field once, store it in a class field for later.

Two, look at the ReflectionHelper class.  It'll make this easier.

Three, that will only work in dev, you'll need to use MCP Bot to get the SRG name so that it works when compiled, too.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, Draco18s said:

A few things:

Don't ever use reflection inside a tick or update event.  That is, the "go find this by string name" because it's expensive as hell.  Get the field once, store it in a class field for later.

Two, look at the ReflectionHelper class.  It'll make this easier.

Three, that will only work in dev, you'll need to use MCP Bot to get the SRG name so that it works when compiled, too.

How do I do it with MC Bot in order to get the SRG name?

Posted (edited)

On the page I linked: download the fields/methods csv files. Open it in Excel or other spreadsheet program. Search for the thing you want the SRG name for. Copy the SRG name.

 

There's also an IRC interface, but I don't use it.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well, you're looking for a field named inventoryHandsDropChances, so search the fields.csv file for "inventoryHandsDropChances"

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.