From d3d809f714e044b3bb36fc01b0f205f3c8d541d6 Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 15 Jul 2021 18:26:02 +0200 Subject: [PATCH] Inline EffectPacket --- .../server/instance/InstanceContainer.java | 20 ++++--------------- .../packet/server/play/EffectPacket.java | 13 +++++++++--- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index f8535715f..54fd7f16f 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -198,24 +198,12 @@ public class InstanceContainer extends Instance { final Block resultBlock = blockBreakEvent.getResultBlock(); UNSAFE_setBlock(chunk, x, y, z, resultBlock, null, new BlockHandler.PlayerDestroy(block, this, blockPosition, player)); - // Send the block break effect packet - { - EffectPacket effectPacket = new EffectPacket(); - effectPacket.effectId = 2001; // Block break + block break sound - effectPacket.position = blockPosition; - effectPacket.data = resultBlock.stateId(); - effectPacket.disableRelativeVolume = false; - - PacketUtils.sendGroupedPacket(chunk.getViewers(), effectPacket, - (viewer) -> { - // Prevent the block breaker to play the particles and sound two times - return !viewer.equals(player); - }); - } - + PacketUtils.sendGroupedPacket(chunk.getViewers(), + new EffectPacket(2001 /*Block break + block break sound*/, blockPosition, resultBlock.stateId(), false), + // Prevent the block breaker to play the particles and sound two times + (viewer) -> !viewer.equals(player)); } - return allowed; } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java index 8120de0c5..d789ad30d 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java @@ -1,11 +1,11 @@ package net.minestom.server.network.packet.server.play; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; -import net.minestom.server.coordinate.Point; -import net.minestom.server.coordinate.Vec; import org.jetbrains.annotations.NotNull; public class EffectPacket implements ServerPacket { @@ -15,8 +15,15 @@ public class EffectPacket implements ServerPacket { public int data; public boolean disableRelativeVolume; + public EffectPacket(int effectId, Point position, int data, boolean disableRelativeVolume) { + this.effectId = effectId; + this.position = position; + this.data = data; + this.disableRelativeVolume = disableRelativeVolume; + } + public EffectPacket() { - position = Vec.ZERO; + this(0, Vec.ZERO, 0, false); } @Override