Jump to content

[1.8.9] OkHttp crushing the client?


Bets

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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: 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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