mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 11:41:52 +01:00
Fixed block break particles and sound being played two times for the breaker
This commit is contained in:
parent
c1b584da1b
commit
3a988ddba1
@ -20,6 +20,7 @@ import net.minestom.server.network.packet.server.play.EffectPacket;
|
||||
import net.minestom.server.network.packet.server.play.UnloadChunkPacket;
|
||||
import net.minestom.server.storage.StorageLocation;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.block.CustomBlockUtils;
|
||||
import net.minestom.server.utils.callback.OptionalCallback;
|
||||
@ -398,7 +399,14 @@ public class InstanceContainer extends Instance {
|
||||
effectPacket.data = blockStateId;
|
||||
effectPacket.disableRelativeVolume = false;
|
||||
|
||||
chunk.sendPacketToViewers(effectPacket);
|
||||
PacketUtils.sendGroupedPacket(chunk.getViewers(), effectPacket,
|
||||
(viewer) -> {
|
||||
// Prevent the block breaker to play the particles and sound two times
|
||||
if (customBlock == null && viewer.equals(player)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -416,6 +416,7 @@ public final class NBTUtils {
|
||||
* @return the value representation of a tag
|
||||
* @throws UnsupportedOperationException if the tag type is not supported
|
||||
*/
|
||||
@NotNull
|
||||
public static Object fromNBT(@NotNull NBT nbt) {
|
||||
if (nbt instanceof NBTNumber) {
|
||||
return ((NBTNumber) nbt).getValue();
|
||||
|
@ -11,7 +11,9 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.network.player.NettyPlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.callback.validator.PlayerValidator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.zip.Deflater;
|
||||
@ -36,10 +38,12 @@ public final class PacketUtils {
|
||||
* <p>
|
||||
* Can drastically improve performance since the packet will not have to be processed as much.
|
||||
*
|
||||
* @param players the players to send the packet to
|
||||
* @param packet the packet to send to the players
|
||||
* @param players the players to send the packet to
|
||||
* @param packet the packet to send to the players
|
||||
* @param playerValidator optional callback to check if a specify player of {@code players} should receive the packet
|
||||
*/
|
||||
public static void sendGroupedPacket(@NotNull Collection<Player> players, @NotNull ServerPacket packet) {
|
||||
public static void sendGroupedPacket(@NotNull Collection<Player> players, @NotNull ServerPacket packet,
|
||||
@Nullable PlayerValidator playerValidator) {
|
||||
if (players.isEmpty())
|
||||
return;
|
||||
|
||||
@ -50,6 +54,11 @@ public final class PacketUtils {
|
||||
|
||||
// Send packet to all players
|
||||
for (Player player : players) {
|
||||
|
||||
// Verify if the player should receive the packet
|
||||
if (playerValidator != null && !playerValidator.isValid(player))
|
||||
continue;
|
||||
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
|
||||
@ -61,6 +70,16 @@ public final class PacketUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #sendGroupedPacket(Collection, ServerPacket, PlayerValidator)}
|
||||
* but with the player validator sets to null.
|
||||
*
|
||||
* @see #sendGroupedPacket(Collection, ServerPacket, PlayerValidator)
|
||||
*/
|
||||
public static void sendGroupedPacket(@NotNull Collection<Player> players, @NotNull ServerPacket packet) {
|
||||
sendGroupedPacket(players, packet, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@link ServerPacket} into a {@link ByteBuf}.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user