Jump to content

Recommended Posts

Posted
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());
    }

 

Posted

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.
  • Like 1

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
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.

Posted
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.

Posted
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" :P

Posted

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?

Posted
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();
                ^

 

Posted
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'
    }

 

Posted
4 minutes ago, diesieben07 said:

That's a part of the build.gradle.

 

Found the issue, apparently there are two places that say "dependencies" :D 

Posted (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 fail
Error: net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: okhttp3/OkHttpClient

Edited by Bets
Posted
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.

Posted
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 :D

 

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: 

Posted
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 ?

Posted
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 :)

Posted
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?

Posted
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.

Posted
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}}
 

Posted (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 by Bets
Posted
17 hours ago, diesieben07 said:

Post updated code.

 

The code is the same, it's just in  RenderGameOverlayEvent.Text instead of the first function

Posted
20 hours ago, diesieben07 said:

Post updated code.

 

Most of the stuff I try doing won't work on  ClientConnectedToServerEvent  is there an alternative?

Posted
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.

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




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.