From b4ebd54c9cf9b1988189d192b3038dbce02af876 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 21 May 2023 23:53:09 +0200 Subject: [PATCH] Defer netcode to server thread --- .../ContraptionColliderLockPacket.java | 10 +++-- .../clipboard/ClipboardEditPacket.java | 39 ++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/ContraptionColliderLockPacket.java b/src/main/java/com/simibubi/create/content/contraptions/ContraptionColliderLockPacket.java index edcc173cb..3b4ff0eeb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/ContraptionColliderLockPacket.java +++ b/src/main/java/com/simibubi/create/content/contraptions/ContraptionColliderLockPacket.java @@ -64,10 +64,12 @@ public class ContraptionColliderLockPacket extends SimplePacketBase { @Override public boolean handle(Context context) { - AllPackets.getChannel() - .send(PacketDistributor.TRACKING_ENTITY.with(context::getSender), - new ContraptionColliderLockPacket(contraption, offset, context.getSender() - .getId())); + context.enqueueWork(() -> { + AllPackets.getChannel() + .send(PacketDistributor.TRACKING_ENTITY.with(context::getSender), + new ContraptionColliderLockPacket(contraption, offset, context.getSender() + .getId())); + }); return true; } diff --git a/src/main/java/com/simibubi/create/content/equipment/clipboard/ClipboardEditPacket.java b/src/main/java/com/simibubi/create/content/equipment/clipboard/ClipboardEditPacket.java index 14e7dedee..85a92e8ce 100644 --- a/src/main/java/com/simibubi/create/content/equipment/clipboard/ClipboardEditPacket.java +++ b/src/main/java/com/simibubi/create/content/equipment/clipboard/ClipboardEditPacket.java @@ -43,26 +43,29 @@ public class ClipboardEditPacket extends SimplePacketBase { @Override public boolean handle(Context context) { - ServerPlayer sender = context.getSender(); - - if (targetedBlock != null) { - Level world = sender.level; - if (world == null || !world.isLoaded(targetedBlock)) - return true; - if (!targetedBlock.closerThan(sender.blockPosition(), 20)) - return true; - if (world.getBlockEntity(targetedBlock) instanceof ClipboardBlockEntity cbe) { - cbe.dataContainer.setTag(data.isEmpty() ? null : data); - cbe.onEditedBy(sender); + context.enqueueWork(() -> { + ServerPlayer sender = context.getSender(); + + if (targetedBlock != null) { + Level world = sender.level; + if (world == null || !world.isLoaded(targetedBlock)) + return; + if (!targetedBlock.closerThan(sender.blockPosition(), 20)) + return; + if (world.getBlockEntity(targetedBlock) instanceof ClipboardBlockEntity cbe) { + cbe.dataContainer.setTag(data.isEmpty() ? null : data); + cbe.onEditedBy(sender); + } + return; } - return true; - } + + ItemStack itemStack = sender.getInventory() + .getItem(hotbarSlot); + if (!AllBlocks.CLIPBOARD.isIn(itemStack)) + return; + itemStack.setTag(data.isEmpty() ? null : data); + }); - ItemStack itemStack = sender.getInventory() - .getItem(hotbarSlot); - if (!AllBlocks.CLIPBOARD.isIn(itemStack)) - return true; - itemStack.setTag(data.isEmpty() ? null : data); return true; }