Jump to content

[Solved] [1.13.2] Reflection Cannot Find Method


DavidM

Recommended Posts

I am trying to called the EntityLiving#getLootTable, which is private, and therefore I am using "ObfuscationReflectionHelper":

Method getLootTable = ObfuscationReflectionHelper.findMethod(entityLiving.getClass(), "getLootTable", new Class[0]);

 

However, I am getting an exception on the line posted above (only after I've build the mod and ran it in the normal game; it works fine in dev env) :

[18:25:02] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: net.minecraftforge.fml.common.ObfuscationReflectionHelper$UnableToFindMethodException: java.lang.NoSuchMethodException: net.minecraft.entity.passive.EntityPig.getLootTable()
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_74]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_74]
	at net.minecraft.util.Util.func_181617_a(SourceFile:200) [?:?]
	at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:715) [?:?]
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:669) [?:?]
	at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:115) [?:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:565) [?:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_74]
Caused by: net.minecraftforge.fml.common.ObfuscationReflectionHelper$UnableToFindMethodException: java.lang.NoSuchMethodException: net.minecraft.entity.passive.EntityPig.getLootTable()
	at net.minecraftforge.fml.common.ObfuscationReflectionHelper.findMethod(ObfuscationReflectionHelper.java:175) ~[?:?]
	at cn.davidma.tinymobfarm.core.util.EntityHelper.getLootTableLocation(EntityHelper.java:40) ~[?:1.0.5]
	at cn.davidma.tinymobfarm.common.item.ItemLasso.func_111207_a(ItemLasso.java:69) ~[?:1.0.5]
	at net.minecraft.item.ItemStack.func_111282_a(ItemStack.java:315) ~[?:?]
	at net.minecraft.entity.player.EntityPlayer.func_190775_a(EntityPlayer.java:1013) ~[?:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147340_a(NetHandlerPlayServer.java:1068) ~[?:?]
	at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:69) ~[?:?]
	at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:13) ~[?:?]
	at net.minecraft.network.PacketThreadUtil.func_210405_a(SourceFile:10) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_74]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_74]
	at net.minecraft.util.Util.func_181617_a(SourceFile:199) ~[?:?]
	... 5 more
Caused by: java.lang.NoSuchMethodException: net.minecraft.entity.passive.EntityPig.getLootTable()
	at java.lang.Class.getDeclaredMethod(Class.java:2130) ~[?:1.8.0_74]
	at net.minecraftforge.fml.common.ObfuscationReflectionHelper.findMethod(ObfuscationReflectionHelper.java:169) ~[?:?]
	at cn.davidma.tinymobfarm.core.util.EntityHelper.getLootTableLocation(EntityHelper.java:40) ~[?:1.0.5]
	at cn.davidma.tinymobfarm.common.item.ItemLasso.func_111207_a(ItemLasso.java:69) ~[?:1.0.5]
	at net.minecraft.item.ItemStack.func_111282_a(ItemStack.java:315) ~[?:?]
	at net.minecraft.entity.player.EntityPlayer.func_190775_a(EntityPlayer.java:1013) ~[?:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147340_a(NetHandlerPlayServer.java:1068) ~[?:?]
	at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:69) ~[?:?]
	at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:13) ~[?:?]
	at net.minecraft.network.PacketThreadUtil.func_210405_a(SourceFile:10) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_74]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_74]
	at net.minecraft.util.Util.func_181617_a(SourceFile:199) ~[?:?]
	... 5 more

 

I assume that this is due to the usage of unobfuscated names for the method name parameter in ObfuscationReflectionHelper#findMethod.

I am wondering:

- Back in 1.12.2, ReflectionHelper#findMethod takes two parameters for the name of a method; the SRG name and the MCP name. It then automatically decides which one to use. Does the ObfuscationReflectionHelper in 1.13.2 has a method that does the same thing (auto decide which name to use)?

- The MCPBot doesn't have files on 1.13.2 yet AFAIK. What are the other ways to get the SRG name of methods in 1.13.2?

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

1. I am indeed storing the Method instance in a static field.

2. Did not realize the getClass problem. Fixed it. Will keep that in mind in the future. Thanks!

3. That would be very handy.

4. The mapping from 1.13.1 works.

 

Thanks!

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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.