Send packet to minecraft server Forge 1.16.5

Viewed 344

I want to send a minecraft vanilla packet to a server. I have searched for an eternity now and didn't find anything. This script works if I remove INSTANCE.sendToServer(new CPlayerPacket.RotationPacket(1f, 1f, MC.player.isOnGround())); otherwise my game crashes as soon as I interact with a block. How would I fix that?

The only thing I understand from the crash report is: Invalid message net.minecraft.network.play.client.CPlayerPacket$RotationPacket but how do I make my packet valid?

    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
            new ResourceLocation("mymodid", "main"),
            () -> PROTOCOL_VERSION,
            PROTOCOL_VERSION::equals,
            PROTOCOL_VERSION::equals
    );
    
    private static final Minecraft MC = Minecraft.getInstance();
    @SubscribeEvent
    public void thing(PlayerInteractEvent event) {
        if (MC.player == null) {
            return;
        }
        BlockPos pos = event.getPos().add(0, 1,0);

        // BlockRayTraceResult result = new BlockRayTraceResult(Vector3d.ZERO ,event.getFace(), pos, true);
        INSTANCE.sendToServer(new CPlayerPacket.RotationPacket(1f, 1f, MC.player.isOnGround()));
        // MC.playerController.processRightClick(MC.player, MC.player.world, Hand.MAIN_HAND);
        MC.player.world.setBlockState(pos, Blocks.WATER.getDefaultState());
        if (MC.player.isSneaking()) {
            MC.player.swing(Hand.MAIN_HAND, true);
        }
    }
}
0 Answers
Related