Bets Posted February 15, 2017 Author Posted February 15, 2017 3 minutes ago, larsgerrits said: Show your codeTM. Well... I have this inside a very fancy class I call "THING": @EventHandler public static void runUponConnectingToServer(ClientConnectedToServerEvent e) { System.out.println("IS THIS WORKING?"); Minecraft.getMinecraft().addScheduledTask(new Runnable() { @Override public void run() { System.out.println("WORKS!"); } }); } This is how I register the class: @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { MinecraftForge.EVENT_BUS.register(new THING()); } Quote
Choonster Posted February 16, 2017 Posted February 16, 2017 You're also using the wrong annotation for your ClientConnectedToServerEvent handler: @Mod.EventHandler is only for FML lifecycle events (classes that extend net.minecraftforge.fml.common.event.FMLEvent) and only works in your @Mod class. @SubscribeEvent is for gameplay events (classes that extend net.minecraftforge.fml.common.eventhandler.Event) and only works in a class that's had the Class object or an instance registered with the appropriate EventBus. 1 Quote 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.
Bets Posted February 16, 2017 Author Posted February 16, 2017 15 hours ago, Choonster said: You're also using the wrong annotation for your ClientConnectedToServerEvent handler: @Mod.EventHandler is only for FML lifecycle events (classes that extend net.minecraftforge.fml.common.event.FMLEvent) and only works in your @Mod class. @SubscribeEvent is for gameplay events (classes that extend net.minecraftforge.fml.common.eventhandler.Event) and only works in a class that's had the Class object or an instance registered with the appropriate EventBus. So I just need to change the @EventHandler to @SubscribeEvent. because the @Mod one is in my mod class. Quote
Bets Posted February 16, 2017 Author Posted February 16, 2017 On 2/15/2017 at 10:26 PM, diesieben07 said: Your event handler method is static, that means you need to register the class to the event bus. You can read this in the event documentation. 19 hours ago, Choonster said: You're also using the wrong annotation for your ClientConnectedToServerEvent handler: @Mod.EventHandler is only for FML lifecycle events (classes that extend net.minecraftforge.fml.common.event.FMLEvent) and only works in your @Mod class. @SubscribeEvent is for gameplay events (classes that extend net.minecraftforge.fml.common.eventhandler.Event) and only works in a class that's had the Class object or an instance registered with the appropriate EventBus. Works perfectly! one problem I found is when I check if a string is == to "null" or anything else it doesn't work. for (String str : getUserData(player)) { if (str != "null") { System.out.println(str + " " + player); } } The getUserData function checks the connected server of a player from an API that is loaded from the web using GSON, "str" should give back the server of the player and if it's null it should just ignore it, but it doesn't. Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 12 hours ago, diesieben07 said: Why "null" and not null? Also, that's not how you compare Strings, you must use equals. Oh yeah lol forgot it's not like js haha. I use "null" because the API returns a JSON object, and when the user is not connected to a server it returns "null" Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 Hmm, looks like there's an issue with Forge and OkHttp I am getting errors when I try to build the mod (running it inside Eclipse works) This is one of the errors I get when I try to recompile the mod: E:\forge-1.8.9-11.15.1.1902-1.8.9-mdk\build\sources\main\java\name\mods\testingForge\this\THING.java:16: error: package okhttp3 does not exist import okhttp3.Response; ^ Any idea why? Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 5 hours ago, diesieben07 said: You must add dependencies via Gradle. Don't add jars directly in Eclipse. I added this: classpath 'com.squareup.okhttp3:okhttp:3.6.0' to my dependencies section inside the gradle file. Do I need to remove the jars from eclipse too? I am still getting errors like: cannot find symbol Response response = APIClient.newCall(request).execute(); ^ Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 3 hours ago, diesieben07 said: Post the updated build.gradle. dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' classpath 'com.squareup.okhttp3:okhttp:3.6.0' } Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 4 minutes ago, diesieben07 said: That's a part of the build.gradle. Found the issue, apparently there are two places that say "dependencies" Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 (edited) 7 minutes ago, diesieben07 said: Yes, that was my concern. The one in buildscript are for buildscript dependencies, i.e. code that is needed by the build.gradle (the build.gradle is just groovy code). Now the game is crashing whenever I am loading the recompiled mod ;-; Found the issue, no idea why it happens though: The game crashed whilst there was a severe problem during mod loading that has caused the game to failError: net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: okhttp3/OkHttpClient Edited February 17, 2017 by Bets Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 4 minutes ago, diesieben07 said: If you use a library in your mod you either have to shade it into your Jar or the user needs to put the library jar into the mods folder as well. And that means I need to get NOT ONLY OKHTTP but OKIO TOOOO0OOOOO..... dang it. Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 Isn't there like a better way of getting JSON data from the web without the external stuff? Quote
Bets Posted February 17, 2017 Author Posted February 17, 2017 7 minutes ago, diesieben07 said: Ahem: It will be a pain to get this to work lol but I'll try! Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 19 hours ago, diesieben07 said: The apache http client is not that hard to use, really. And there are plenty of tutorials on the web. And if you really need to, you could just use native java URLConnection Hopefully I'll manage to get it working haha. Meanwhile I'm trying to check if the player is connected to a game by looking at the tab list. I got to this point "mc.getNetHandler().getPlayerInfoMap()", do I need to loop through it and somehow check if it finds the players name or there is some other faster way of doing so? P: Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 20 minutes ago, diesieben07 said: You can use NetHandlerPlayClient::getPlayerInfo(UUID) to get the info given a UUID instead of looping. Will it work if I'm trying to detect a fake player that his name is for example §lWelcome ? Quote
Kokkie Posted February 18, 2017 Posted February 18, 2017 Why would you have a fake player called §lWelcome? Just wondering... Quote Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
Bets Posted February 18, 2017 Author Posted February 18, 2017 1 hour ago, Kokkie said: Why would you have a fake player called §lWelcome? Just wondering... Some servers have titles like this at their tab list - I want to use it do detect when a player is at a certain place Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 2 hours ago, diesieben07 said: I don't know how those work 100% internally. I don't think there is a good way to detect them though, to be honest. Can I loop through all the users in the tab list? Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 31 minutes ago, diesieben07 said: getPlayerInfoMap will give you collection of all players in the list. I tried doing this Collection<NetworkPlayerInfo> users = mc.getNetHandler().getPlayerInfoMap(); for (NetworkPlayerInfo cuser : users) { System.out.println("LOOK AT THIS DAMMIT! " + cuser.getDisplayName()); } When I join a singleplayer world it just sends me back to the main screen. Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 1 minute ago, diesieben07 said: Where did you put that code? There must have been some kind of error message...? It's inside runUponConnectingToServer(ClientConnectedToServerEvent e) The only thing I could find is this [Server thread/INFO]: Player288 joined the game [Server thread/INFO]: Player288 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}} Quote
Bets Posted February 18, 2017 Author Posted February 18, 2017 (edited) 6 minutes ago, diesieben07 said: Well, that fires right after the connection has been established. There isn't any knowledge of the players yet. My idea was to fire it all the time on a RenderGameOverlayEvent.Text so it checks all the time if to display something or not. But it just kills the game for some reason. EDIT: I think I got it one sec EDIT: Ok it is not killing the game anymore, but the only thing I get is null Edited February 18, 2017 by Bets Quote
Bets Posted February 19, 2017 Author Posted February 19, 2017 17 hours ago, diesieben07 said: Post updated code. The code is the same, it's just in RenderGameOverlayEvent.Text instead of the first function Quote
Bets Posted February 19, 2017 Author Posted February 19, 2017 20 hours ago, diesieben07 said: Post updated code. Most of the stuff I try doing won't work on ClientConnectedToServerEvent is there an alternative? Quote
Bets Posted February 19, 2017 Author Posted February 19, 2017 2 hours ago, diesieben07 said: Well, what are you trying to do? I need to check if a fake player by the name of §lWelcome (for example) is on the tab list. Quote
Bets Posted February 19, 2017 Author Posted February 19, 2017 Just now, diesieben07 said: And then do what? Judging by that decide if to display or not display a certain thing Quote
Recommended Posts
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.