Jump to content

Any way to check if the code is running on Client, or server?


diniboy

Recommended Posts

Hi again,

 

I have followed Shadowfact's tutorial, and now I have a working mod (here is the source) on client side. But at the server side it gives me an error:


 

[14:14:59] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Testing mod (dtm)

Caused by: java.lang.NoSuchMethodError: diniboy.TestMod2.item.ItemBase.setUnlocalizedName(Ljava/lang/String;)Lnet/minecraft/item/Item;
    at diniboy.TestMod2.item.ItemBase.<init>(ItemBase.java:13) ~[ItemBase.class:?]
    at diniboy.TestMod2.item.ItemOre.<init>(ItemOre.java:10) ~[ItemOre.class:?]
    at diniboy.TestMod2.item.ModItems.init(ModItems.java:14) ~[ModItems.class:?]
    at diniboy.TestMod2.TestMod2.preInit(TestMod2.java:31) ~[TestMod2.class:?]
[...]

 

Well, that's clear. The server hasn't got the setUnlocalizedName method. So I Cannot call that on server side. But is there a way to check if it is running now on a server or not? The world.isRemote would be nice, but I Cannot use that there (for example here), because I didn't find a method which returns the current world.

 

Thanks!

Link to comment
Share on other sites

7 minutes ago, V0idWa1k3r said:

In any case if you need to call methods that only exist on client use proxies.

Okay, but in that case, I have to rethink the whole conception. The check might be a lazy solution. :D

 

BTW Can You please compile the mod, and test it on a 1.11.2 forge server? Is it throw that error too for You?

 

Thanks a lot!

Link to comment
Share on other sites

1) Just for grins, could you add a "this." in front of each call to each instance method and then recompile?

 

2) Did you compile your server jar using gradlew build? i ask because your build.gradle file looks like the default with

group = "com.yourname.modid"

still in it.

  • Like 1

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.