Jump to content

ClientOnly message causes problem on server start.


Raycoms

Recommended Posts

I have the message:

 

@Nullable
    @Override
    public IMessage onMessage(@NotNull SaveScanMessage message, MessageContext ctx)
    {
        File file = new File(FMLClientHandler.instance().getClient().mcDataDir, message.storeLocation);
        StructureWrapper.createScanDirectory(FMLClientHandler.instance().getClient().theWorld);

        try (OutputStream outputstream = new FileOutputStream(file))
        {
            CompressedStreamTools.writeCompressed(message.nbttagcompound, outputstream);
        }
        catch (Exception e)
        {
            LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer, LanguageHandler.format("item.scepterSteel.scanFailure"));
            return null;
        }

        LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer,
                LanguageHandler.format("item.scepterSteel.scanSuccess", message.storeLocation));

        return null;
    }

 

Which will be sent from the server to the client.

 

I registered it.

 

        getNetwork().registerMessage(SaveScanMessage.class, SaveScanMessage.class, 51, Side.CLIENT);

 

It still crashes the server on loading because he has problems with:

 

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient

 

Also tried it with Minecraft.getMinecraft() no success.

 

Shouldn't it work because it will only be executed on the client?

 

 

Link to comment
Share on other sites

I have the message:

 

@Nullable
    @Override
    public IMessage onMessage(@NotNull SaveScanMessage message, MessageContext ctx)
    {
        File file = new File(FMLClientHandler.instance().getClient().mcDataDir, message.storeLocation);
        StructureWrapper.createScanDirectory(FMLClientHandler.instance().getClient().theWorld);

        try (OutputStream outputstream = new FileOutputStream(file))
        {
            CompressedStreamTools.writeCompressed(message.nbttagcompound, outputstream);
        }
        catch (Exception e)
        {
            LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer, LanguageHandler.format("item.scepterSteel.scanFailure"));
            return null;
        }

        LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer,
                LanguageHandler.format("item.scepterSteel.scanSuccess", message.storeLocation));

        return null;
    }

 

Which will be sent from the server to the client.

 

I registered it.

 

        getNetwork().registerMessage(SaveScanMessage.class, SaveScanMessage.class, 51, Side.CLIENT);

 

It still crashes the server on loading because he has problems with:

 

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient

 

Also tried it with Minecraft.getMinecraft() no success.

 

Shouldn't it work because it will only be executed on the client?

Is your IMessage and  IMessageHandler the same class?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Sure.

 

package com.minecolonies.network.messages;

import com.minecolonies.util.LanguageHandler;
import com.minecolonies.util.StructureWrapper;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
* Send a scan outputStream to the client.
*/
public class SaveScanMessage implements IMessage, IMessageHandler<SaveScanMessage, IMessage>
{
    private NBTTagCompound nbttagcompound;
    private String         storeLocation;

    /**
     * Public standard constructor.
     */
    public SaveScanMessage()
    {
        /*
         * Intentionally left empty.
         */
    }

    /**
     * Send a scan compound to the client.
     *
     * @param nbttagcompound the stream.
     * @param storeAt string describing where to store the scan.
     */
    public SaveScanMessage(NBTTagCompound nbttagcompound, String storeAt)
    {
        this.nbttagcompound = nbttagcompound;
        this.storeLocation = storeAt;
    }

    @Override
    public void fromBytes(@NotNull ByteBuf buf)
    {
        nbttagcompound = ByteBufUtils.readTag(buf);
        storeLocation = ByteBufUtils.readUTF8String(buf);
    }

    @Override
    public void toBytes(@NotNull ByteBuf buf)
    {
        ByteBufUtils.writeTag(buf, nbttagcompound);
        ByteBufUtils.writeUTF8String(buf, storeLocation);
    }

    @Nullable
    @Override
    public IMessage onMessage(@NotNull SaveScanMessage message, MessageContext ctx)
    {
        File file = new File(FMLClientHandler.instance().getClient().mcDataDir, message.storeLocation);
        StructureWrapper.createScanDirectory(FMLClientHandler.instance().getClient().theWorld);

        try (OutputStream outputstream = new FileOutputStream(file))
        {
            CompressedStreamTools.writeCompressed(message.nbttagcompound, outputstream);
        }
        catch (Exception e)
        {
            LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer, LanguageHandler.format("item.scepterSteel.scanFailure"));
            return null;
        }

        LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer,
                LanguageHandler.format("item.scepterSteel.scanSuccess", message.storeLocation));

        return null;
    }
}

Link to comment
Share on other sites

TL;DR don't do that. Use separate classes.

Your packet handler code is trying to load client-side-only objects and because it's the same class on the server, the server tries to load those objects in order to instantiate your packet.  Ergo, it crashes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So one class only for the handler and one for the message?

One class for the handler and one more class for the message.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

        getNetwork().registerMessage(SaveScanMessageHandler.class, SaveScanMessage.class, 51, Side.CLIENT);

 

package com.minecolonies.network.messages;

import com.minecolonies.util.LanguageHandler;
import com.minecolonies.util.StructureWrapper;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
* Handles sendScanMessages.
*/
public class SaveScanMessageHandler implements IMessageHandler<SaveScanMessage, IMessage>
{
    /**
     * Public standard constructor.
     */
    public SaveScanMessageHandler()
    {
        /*
         * Intentionally left empty.
         */
    }

    @Nullable
    @Override
    public IMessage onMessage(@NotNull SaveScanMessage message, MessageContext ctx)
    {
        File file = new File(FMLClientHandler.instance().getClient().mcDataDir, message.storeLocation);
        StructureWrapper.createScanDirectory(FMLClientHandler.instance().getClient().theWorld);

        try (OutputStream outputstream = new FileOutputStream(file))
        {
            CompressedStreamTools.writeCompressed(message.nbttagcompound, outputstream);
        }
        catch (Exception e)
        {
            LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer, LanguageHandler.format("item.scepterSteel.scanFailure"));
            return null;
        }

        LanguageHandler.sendPlayerLocalizedMessage(FMLClientHandler.instance().getClient().thePlayer,
                LanguageHandler.format("item.scepterSteel.scanSuccess", message.storeLocation));

        return null;
    }
}

 

 

package com.minecolonies.network.messages;

import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import org.jetbrains.annotations.NotNull;

/**
* Creates a message to save scans on the clients.
*/
public class SaveScanMessage implements IMessage
{
    public NBTTagCompound nbttagcompound;
    public String         storeLocation;

    /**
     * Send a scan compound to the client.
     *
     * @param nbttagcompound the stream.
     * @param storeAt string describing where to store the scan.
     */
    public SaveScanMessage(NBTTagCompound nbttagcompound, String storeAt)
    {
        this.nbttagcompound = nbttagcompound;
        this.storeLocation = storeAt;
    }

    @Override
    public void fromBytes(@NotNull ByteBuf buf)
    {
        nbttagcompound = ByteBufUtils.readTag(buf);
        storeLocation = ByteBufUtils.readUTF8String(buf);
    }

    @Override
    public void toBytes(@NotNull ByteBuf buf)
    {
        ByteBufUtils.writeTag(buf, nbttagcompound);
        ByteBufUtils.writeUTF8String(buf, storeLocation);
    }
}

 

Still, same problem.

Link to comment
Share on other sites

You need a 0-argument constructor for SaveScanMessage.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Still:

 

Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/multiplayer/WorldClient for invalid side SERVER
at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:56) ~[forgeSrc-1.10.2-12.18.1.2077-PROJECT(minecolonies).jar:?]
at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:249) ~[forgeSrc-1.10.2-12.18.1.2077-PROJECT(minecolonies).jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_112]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_112]
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.8.0_112]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[?:1.8.0_112]
at java.lang.Class.getConstructor0(Class.java:3075) ~[?:1.8.0_112]
at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_112]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:166) ~[forgeSrc-1.10.2-12.18.1.2077-PROJECT(minecolonies).jar:?]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:159) ~[forgeSrc-1.10.2-12.18.1.2077-PROJECT(minecolonies).jar:?]
at com.minecolonies.MineColonies.initializeNetwork(MineColonies.java:149) ~[minecolonies_main/:?]
at com.minecolonies.MineColonies.init(MineColonies.java:96) ~[minecolonies_main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_112]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:597) ~[forgeSrc-1.10.2-12.18.1.2077-PROJECT(minecolonies).jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_112]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:239) ~[LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:217) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_112]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:142) ~[LoadController.class:?]
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:788) ~[Loader.class:?]
... 5 more

Link to comment
Share on other sites

Register your network handler in your client proxy.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The server doesn't need to know it?

 

Having had to fight with COG to get the server running in Dev, I was wrong.

 

Yes, the server needs to know about the packet handler, because you need to register the networking stuff on both sides.

 

Which means...

 

You guessed it...

 

The packet handler cannot contain client-side-only code.  I just had to move a bunch of stuff to my client proxy.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You can call a method in your proxy class, yes.  But it must be done through MainMod.proxy.whatever() not ClientProxy.whatever().

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • Sometimes, tweaking load order or specific configs can also help ease those conflicts.
    • I have recently tired downloading forge so i can run mods for hypixel skyblock but whenever i download forge and do it the same way as videos and tutorials forge keeps downloading as log file and doesnt download the .jar file any help will be aprecciated.
    • So I have created a Create Mod Server with my friends and i to play everyone can join play except one of my friends because when he tries to launch the game from the CurseForge Launcher it will load but never open or give him a crash report, we have tried everything from deleting CF and reinstalling it to Updating his drivers, IDK what to do if anyone can help I would be very Grateful
    • I get this error when trying to start the server for forged mods. In the code below it mentions distant horizons but no matter what mod I put in (deleting distant horizons) it still gives an error and doesn't launch Crash Report UUID: 3e91d5c7-18a7-43c2-a935-a8d28de560d1 FML: 47.3 Forge: net.minecraftforge:47.3.10[23:33:47] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [    Distant Horizons (distanthorizons) encountered an error during the sided_setup event phase§7java.lang.ExceptionInInitializerError: null]     at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:246) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$20(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$loadMods$15(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraft.server.loading.ServerModLoader.load(ServerModLoader.java:31) ~[forge-1.20.1-47.3.10-universal.jar%23108!/:?] {re:classloading}     at net.minecraft.server.Main.main(Main.java:125) ~[server-1.20.1-20230612.114412-srg.jar%23103!/:?] {re:classloading}     at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:111) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.lambda$run$1(CommonLaunchHandler.java:103) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$makeService$0(CommonServerLaunchHandler.java:27) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:108) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:78) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {}  
    • This error keeps coming up after player tries to join server, doesn't happen to anyone else.  Error: Internal Exception: io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: Index 17196645 out of bounds for length 13 Heres the latest.log https://pastebin.com/uaw3KC0K  Heres the debug.log https://drive.google.com/file/d/1QzqtCMUf7ps1Iz85AOsMM7W8QhbHjBeU/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

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