Jump to content

[1.7.10] [SOLVED] Weird NoSuchMethodError with compiled mod.


Elix_x

Recommended Posts

Hello!

Today, i'm here with really strange issue, caused by something unknown to me:

I did not happen to me, but of one users who downloaded the mod, put it on server and joined server.

Here's part of server log that contains the issue:

[22:14:34] [server thread/ERROR] [FML/]: Exception caught during firing event cpw.mods.fml.common.gameevent.TickEvent$PlayerTickEvent@862de2b:
java.lang.NoSuchMethodError: net.minecraft.entity.player.EntityPlayer.func_71011_bu()Lnet/minecraft/item/ItemStack;
at code.elix_x.mods.teleplates.teleplates.TeleportationManager.onPlayerUpdate(TeleportationManager.java:50) ~[TeleportationManager.class:?]
at code.elix_x.mods.teleplates.events.OnPlayerTickEvent.tick(OnPlayerTickEvent.java:17) ~[OnPlayerTickEvent.class:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler_470_OnPlayerTickEvent_tick_PlayerTickEvent.invoke(.dynamic) ~[?:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?]
at cpw.mods.fml.common.FMLCommonHandler.onPlayerPreTick(FMLCommonHandler.java:345) [FMLCommonHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:220) [yz.class:?]
at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:295) [mw.class:?]
at net.minecraft.network.NetHandlerPlayServer.func_147347_a(NetHandlerPlayServer.java:303) [nh.class:?]
at net.minecraft.network.play.client.C03PacketPlayer.func_148833_a(SourceFile:137) [jd.class:?]
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.func_148833_a(SourceFile:20) [jf.class:?]
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) [ej.class:?]
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165) [nc.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:659) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:334) [lt.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:547) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) [li.class:?]

The issue happens on line 50 of TeleportationManager, so here's line 50 of TeleportationManager:

if(player.rotationPitch == 90 && ((block == TeleplatesBase.teleplate && EnergyManager.canTeleportFromTeleplate(player)) || (player.getItemInUse() != null && player.getItemInUse().getItem() == TeleplatesBase.portableTeleplate && EnergyManager.canTeleportFromPortableTeleplate(player)))){

As you can see,

EntityPlayer.func_71011_bu()

can only be

player.getItemInUse()

(it's the only called 1 param player method that returns ItemStack).

So apearently, something wrong went with obfuscation of the mod... Although BUILD SUCESSFULL...

In total, i'm confused in what have caused this... It seems that something else caused this error. Obfuscator? Different forge versions? MCP mappings? 3rd party coremod? What?

 

Original issue topic: http://www.minecraftforge.net/forum/index.php/topic,33187

 

Thanks for help!

If you have any questions - just ask!

Link to comment
Share on other sites

EntityPlayer#getItemInUse

is marked as

@SideOnly(Side.CLIENT)

, which means that it doesn't exist on the server.

 

To access the

EntityPlayer#itemInUse

field on the server, you'll need to use reflection or an access transformer.

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.

Link to comment
Share on other sites

EntityPlayer#getItemInUse

is marked as

@SideOnly(Side.CLIENT)

, which means that it doesn't exist on the server.

 

To access the

EntityPlayer#itemInUse

field on the server, you'll need to use reflection or an access transformer.

Why is it so? It's illogical...

Link to comment
Share on other sites

EntityPlayer#getItemInUse

is marked as

@SideOnly(Side.CLIENT)

, which means that it doesn't exist on the server.

 

To access the

EntityPlayer#itemInUse

field on the server, you'll need to use reflection or an access transformer.

Why is it so? It's illogical...

The Dedicated Server doesn't have a lot of the client-side code because it's not necessary if there's no local client.  I guess none of the dedicated server code needs to access itemInUse from outside EntityPlayer, so they never added a getter on that side.

 

Anyhow as Choonster said you can either use Reflection, an Access Transformer, or alternatively PlayerUseItemEvent  and isUsingItem().

 

If you just want to access a private field it's pretty easy, eg

 

@SideOnly(Side.CLIENT)
public class KeyBindingInterceptor 
{
  private static final Field pressTimeField = ReflectionHelper.findField(KeyBinding.class, "pressTime", "field_151474_i");  // unobfuscated name, and obfuscatedname

  //...
    int value = 0;
    try {
      value = pressTimeField.getInt(keyBinding, 0);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
}

 

-TGG

 

 

 

 

Link to comment
Share on other sites

EntityPlayer#getItemInUse

is marked as

@SideOnly(Side.CLIENT)

, which means that it doesn't exist on the server.

 

To access the

EntityPlayer#itemInUse

field on the server, you'll need to use reflection or an access transformer.

Why is it so? It's illogical...

The Dedicated Server doesn't have a lot of the client-side code because it's not necessary if there's no local client.  I guess none of the dedicated server code needs to access itemInUse from outside EntityPlayer, so they never added a getter on that side.

 

Anyhow as Choonster said you can either use Reflection, an Access Transformer, or alternatively PlayerUseItemEvent  and isUsingItem().

 

If you just want to access a private field it's pretty easy, eg

 

@SideOnly(Side.CLIENT)
public class KeyBindingInterceptor 
{
  private static final Field pressTimeField = ReflectionHelper.findField(KeyBinding.class, "pressTime", "field_151474_i");  // unobfuscated name, and obfuscatedname

  //...
    int value = 0;
    try {
      value = pressTimeField.getInt(keyBinding, 0);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
}

 

-TGG

I know how to use both reflection and ats to be friendly with obfuscation, don''t worry. The thing is that i have to check it every tick for each player. So the question of performance is here...

 

Also, why can't forge add their both sides getter method? Perhaps, i could add it myself, if only i could install forge on my pc, but i can't: running

gradlew setupForge

in cloned forge, stops at

:git

and then

build failed

. Where should i report this, by the way???

Link to comment
Share on other sites

HI

 

I know how to use both reflection and ats to be friendly with obfuscation, don''t worry. The thing is that i have to check it every tick for each player. So the question of performance is here...

 

100% for sure using Reflection to get this field once per tick will not be noticeable.  You could do it a million times per tick and the user probably still wouldn't notice.

 

Just a comment - if you haven't specifically designed your mod to work with DedicatedServer, then it's a pretty good bet a whole pile of other things will break.  If one of your classes has any mention of a vanilla client-side class, the classloader for your classes will often cause a crash even if the code that uses the client-side class is never ever executed.

 

> You can use player.isUsingItem() without any issues, and if that's true, use player.getHeldItem() to get the item being used. No need for Reflection here.

Didn't think of that... it's probably safe to assume they're always the same... probably... :)

 

-TGG

 

 

Link to comment
Share on other sites

> You can use player.isUsingItem() without any issues, and if that's true, use player.getHeldItem() to get the item being used. No need for Reflection here.

Didn't think of that... it's probably safe to assume they're always the same... probably... :)

At least until 1.9 :P

Yep... Forge and modders will have fun with 1.9 for sure

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.