RMI
RMI

Reputation: 1

Issues with minecraft forge packages in 1.16.5

I am making a mod in minecraft 1.16.5 forge

I have a tile entity that is used for crafting but I don't want it to craft things every tick.

To achieve this I added a button that sends a package to the server whenever it needs to do the crafting.

I have no idea what I am doing wrong at this point and I cannot find the cause of the issue in the minecraft code because the exception stack does not reference any of my classes.

I am relatively new to minecraft modding and java in general which also isn't very helpful. However I have done my homework and have enough knowledge to know what I actually am doing and not just blindly copy pasting code from tutorials so calling me out to learn java will not help me in any capacity.

I am stuck with this problem for about a week now and this is the last place I can think of that can help me

It works flawlessly in singleplayer but whenever I try to join a server with this mod installed I get an error message on my screen saying

Internal Exception: io.netty.handler.codec.DecoderException: io.netty.handler.codec.EncoderException: java.io.UTFDataFormatExcpetion: malformed input around byte 5

Inside Debug.log it says

[25Nov2021 20:17:50.906] [Render thread/FATAL] [net.minecraft.util.concurrent.ThreadTaskExecutor/]: Error executing task on Client java.util.NoSuchElementException: packet_handler

I have compared my way of making the packets with multiple mods I found on curseforge most are the same way as I do it.

I have asked around in multiple forge and modding related discord servers but no one was able to help me with my problem.

All tutorials on youtube did the same as I did.

My PacketHandler class looks like this:

public static final String PROTOCOL_VERSION = "1";
public static SimpleChannel CHANNEL;


public static void init() {
    int index =0;
    CHANNEL = NetworkRegistry.ChannelBuilder
            .named(new ResourceLocation("pepsimc","simple_network"))
            .clientAcceptedVersions(PROTOCOL_VERSION::equals)
            .serverAcceptedVersions(PROTOCOL_VERSION::equals)
            .networkProtocolVersion(()->PROTOCOL_VERSION)
            .simpleChannel();
    
    CHANNEL.messageBuilder(ProcessingCraftPacket.class, index++, NetworkDirection.PLAY_TO_SERVER)
    .encoder(ProcessingCraftPacket::encode)
    .decoder(ProcessingCraftPacket::new)
    .consumer(ProcessingCraftPacket::handle)
    .add();
}

My packet class looks like this:

public final BlockPos Pos;

public ProcessingCraftPacket(BlockPos Pos) {
    this.Pos = Pos;
}

public ProcessingCraftPacket(PacketBuffer buffer) {
    this(buffer.readBlockPos());
}

public void encode(PacketBuffer buffer) {
    buffer.writeBlockPos(this.Pos);
}

public static void handle(ProcessingCraftPacket message, Supplier<NetworkEvent.Context> ctx) {
    ctx.get().enqueueWork(()->{
        final TileEntity TE = ctx.get().getSender().level.getBlockEntity(message.Pos);
        if(TE instanceof ProcessingTile) {
            final ProcessingTile PT = (ProcessingTile) TE;
            PT.process(ctx.get().getSender().level);
        }
    });
    ctx.get().setPacketHandled(true);
}

Thanks alot in advance.

Upvotes: 0

Views: 1085

Answers (2)

RMI
RMI

Reputation: 1

I found out what I was doing wrong. Apparently it had nothing to do with my packets but with my custom recipe type. I didn't read everything from the buffer which was causing the issue.

Upvotes: 0

Pieter12345
Pieter12345

Reputation: 1789

I'm not entirely sure what is going wrong in your code, but since you've asked this in official channels as well without finding an answer, I'm going to refer you to one of my projects with a working custom network packet setup. I'm noticing differences in how we construct the channel and register custom packets, so maybe there's a problem there.

Upvotes: 0

Related Questions