Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved] [1.14.4] Client side packet


Maciej916
 Share

Recommended Posts

Hello I want to sent packet from server to client and everything is working in single player but mod don't want to start on dedicated server because in packet I use Minecraft class. How can I fix this, can I use @OnlyIn()

 

 

public class PacketMultiJumpSync {

    private final int multiJump;

    public PacketMultiJumpSync(int multiJump) {
        this.multiJump = multiJump;
    }

    public PacketMultiJumpSync(PacketBuffer buf) {
        multiJump = buf.readInt();
    }

    public void toBytes(PacketBuffer buf) {
        buf.writeInt(multiJump);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            PlayerEntity player = Minecraft.getInstance().player;
            IEnchants enchantsCap = PlayerUtil.getEnchantsCapability(player);
            enchantsCap.setMultiJump(multiJump);
        });
        ctx.get().setPacketHandled(true);
    }
}

 

INSTANCE.registerMessage(nextID(), PacketMultiJumpSync.class, PacketMultiJumpSync::toBytes, PacketMultiJumpSync::new, PacketMultiJumpSync::handle);

 

Edited by Maciej916
Link to comment
Share on other sites

I tried to use DistExecutor but error remain the same:

 

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {

            DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
                
                PlayerEntity player = Minecraft.getInstance().player;
                IEnchants enchantsCap = PlayerUtil.getEnchantsCapability(player);
                enchantsCap.setMultiJump(multiJump);

            });
        });
        ctx.get().setPacketHandled(true);
    }

 

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.