Jump to content

[1.19.3] Networking On Dedicated Server Fails


MultiCoder

Recommended Posts

My mod is not loading on a dedicated server that I'm using for beta testing features the crash report is below.

Crash Report

I followed a tutorial to create the classes to run the networking.

My current code is below. One thing to note is that the mod runs on client side without an issue.

package org.multicoder.mcpaintball.network;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.simple.SimpleChannel;
import org.multicoder.mcpaintball.MCPaintball;
import org.multicoder.mcpaintball.network.packets.*;

public class Networking
{
    private static SimpleChannel INSTANCE;
    private static int id = 0;
    private static int ID(){
        return id++;
    }

    public static void Register()
    {
        SimpleChannel net = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(MCPaintball.MODID,"messsage")).networkProtocolVersion(() -> "1.0.0").clientAcceptedVersions(s -> true)
                .serverAcceptedVersions(s -> true).simpleChannel();

        INSTANCE = net;

        net.messageBuilder(TeamPointS2CPacket.class,ID(),NetworkDirection.PLAY_TO_CLIENT).decoder(TeamPointS2CPacket::new).encoder(TeamPointS2CPacket::toBytes).consumerMainThread(TeamPointS2CPacket::Handle).add();
        net.messageBuilder(TeamUpdateS2CPacket.class,ID(),NetworkDirection.PLAY_TO_CLIENT).decoder(TeamUpdateS2CPacket::new).encoder(TeamUpdateS2CPacket::toBytes).consumerMainThread(TeamUpdateS2CPacket::Handle).add();
        net.messageBuilder(PlayLowClassSoundS2CPacket.class,ID(),NetworkDirection.PLAY_TO_CLIENT).decoder(PlayLowClassSoundS2CPacket::new).encoder(PlayLowClassSoundS2CPacket::toBytes).consumerMainThread(PlayLowClassSoundS2CPacket::Handle).add();
        net.messageBuilder(PlayHighClassSoundS2CPacket.class,ID(),NetworkDirection.PLAY_TO_CLIENT).decoder(PlayHighClassSoundS2CPacket::new).encoder(PlayHighClassSoundS2CPacket::toBytes).consumerMainThread(PlayHighClassSoundS2CPacket::Handle).add();
        net.messageBuilder(TeamUpdateC2SPacket.class,ID(),NetworkDirection.PLAY_TO_SERVER).decoder(TeamUpdateC2SPacket::new).encoder(TeamUpdateC2SPacket::toBytes).consumerMainThread(TeamUpdateC2SPacket::Handle).add();
    }

    public static <MSG> void SendToServer(MSG message)
    {
        INSTANCE.sendToServer(message);
    }

    public static <MSG> void sendToPlayer(MSG message, ServerPlayer player) {INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), message);}

    public static <MSG> void sendToClients(MSG message) {INSTANCE.send(PacketDistributor.ALL.noArg(), message);}
}
@Mod(MCPaintball.MODID)
public class MCPaintball
{
    public static final String MODID = "mcpaintball";
    public static final Logger LOG = LogManager.getLogger(MODID);
    public MCPaintball()
    {
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, MCPaintballConfig.SPEC,"mcpaintball-common.toml");
        IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        bus.register(this);
        bus.addListener(this::OnCommon);
    }


    private void OnCommon(FMLCommonSetupEvent event)
    {
        event.enqueueWork(() -> {
            BlockHolder.AppendList();
        });
        Networking.Register();

    }

    // Removed Unnessacery things from file to shrink its size
}

 

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.