Inline EffectPacket

This commit is contained in:
TheMode 2021-07-15 18:26:02 +02:00
parent 0a84b1c542
commit d3d809f714
2 changed files with 14 additions and 19 deletions

View File

@ -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;
}

View File

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