Posted November 19, 20195 yr 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 November 20, 20195 yr by Maciej916
November 20, 20195 yr Author 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); }
November 20, 20195 yr Author Sorry that was my mistake i didn't realize that i have other method in that class using Minecraft instance. Now everything works correctly, thank you!
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.