| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import io.netty.buffer.ByteBuf;
|
| 4 | import java.util.function.IntFunction;
|
| 5 | import net.minecraft.core.particles.ParticleOptions;
|
| 6 | import net.minecraft.core.particles.ParticleTypes;
|
| 7 | import net.minecraft.network.RegistryFriendlyByteBuf;
|
| 8 | import net.minecraft.network.codec.ByteBufCodecs;
|
| 9 | import net.minecraft.network.codec.StreamCodec;
|
| 10 | import net.minecraft.network.protocol.Packet;
|
| 11 | import net.minecraft.network.protocol.PacketType;
|
| 12 | import net.minecraft.util.ByIdMap;
|
| 13 |
|
| 14 | public record ClientboundLevelParticlesPacket(
|
| 15 | ParticleOptions particle,
|
| 16 | boolean overrideLimiter,
|
| 17 | boolean alwaysShow,
|
| 18 | double x,
|
| 19 | double y,
|
| 20 | double z,
|
| 21 | float xDist,
|
| 22 | float yDist,
|
| 23 | float zDist,
|
| 24 | float xMaxSpeed,
|
| 25 | float yMaxSpeed,
|
| 26 | float zMaxSpeed,
|
| 27 | int count,
|
| 28 | ClientboundLevelParticlesPacket.RandomizationType randomizationType
|
| 29 | ) implements Packet<ClientGamePacketListener> {
|
| 30 | public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundLevelParticlesPacket> STREAM_CODEC = StreamCodec.composite(
|
| 31 | ParticleTypes.STREAM_CODEC,
|
| 32 | ClientboundLevelParticlesPacket::particle,
|
| 33 | ByteBufCodecs.BOOL,
|
| 34 | ClientboundLevelParticlesPacket::overrideLimiter,
|
| 35 | ByteBufCodecs.BOOL,
|
| 36 | ClientboundLevelParticlesPacket::alwaysShow,
|
| 37 | ByteBufCodecs.DOUBLE,
|
| 38 | ClientboundLevelParticlesPacket::x,
|
| 39 | ByteBufCodecs.DOUBLE,
|
| 40 | ClientboundLevelParticlesPacket::y,
|
| 41 | ByteBufCodecs.DOUBLE,
|
| 42 | ClientboundLevelParticlesPacket::z,
|
| 43 | ByteBufCodecs.FLOAT,
|
| 44 | ClientboundLevelParticlesPacket::xDist,
|
| 45 | ByteBufCodecs.FLOAT,
|
| 46 | ClientboundLevelParticlesPacket::yDist,
|
| 47 | ByteBufCodecs.FLOAT,
|
| 48 | ClientboundLevelParticlesPacket::zDist,
|
| 49 | ByteBufCodecs.FLOAT,
|
| 50 | ClientboundLevelParticlesPacket::xMaxSpeed,
|
| 51 | ByteBufCodecs.FLOAT,
|
| 52 | ClientboundLevelParticlesPacket::yMaxSpeed,
|
| 53 | ByteBufCodecs.FLOAT,
|
| 54 | ClientboundLevelParticlesPacket::zMaxSpeed,
|
| 55 | ByteBufCodecs.VAR_INT,
|
| 56 | ClientboundLevelParticlesPacket::count,
|
| 57 | ClientboundLevelParticlesPacket.RandomizationType.STREAM_CODEC,
|
| 58 | ClientboundLevelParticlesPacket::randomizationType,
|
| 59 | ClientboundLevelParticlesPacket::new
|
| 60 | );
|
| 61 |
|
| 62 | public ClientboundLevelParticlesPacket(
|
| 63 | final ParticleOptions particle,
|
| 64 | final boolean overrideLimiter,
|
| 65 | final boolean alwaysShow,
|
| 66 | final double x,
|
| 67 | final double y,
|
| 68 | final double z,
|
| 69 | final float xDist,
|
| 70 | final float yDist,
|
| 71 | final float zDist,
|
| 72 | final float maxSpeed,
|
| 73 | final int count
|
| 74 | ) {
|
| 75 | this(
|
| 76 | particle,
|
| 77 | overrideLimiter,
|
| 78 | alwaysShow,
|
| 79 | x,
|
| 80 | y,
|
| 81 | z,
|
| 82 | xDist,
|
| 83 | yDist,
|
| 84 | zDist,
|
| 85 | maxSpeed,
|
| 86 | maxSpeed,
|
| 87 | maxSpeed,
|
| 88 | count,
|
| 89 | ClientboundLevelParticlesPacket.RandomizationType.DEFAULT
|
| 90 | );
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | public PacketType<ClientboundLevelParticlesPacket> type() {
|
| 95 | return GamePacketTypes.CLIENTBOUND_LEVEL_PARTICLES;
|
| 96 | }
|
| 97 |
|
| 98 | public void handle(final ClientGamePacketListener listener) {
|
| 99 | listener.handleParticleEvent(this);
|
| 100 | }
|
| 101 |
|
| 102 | public enum RandomizationType {
|
| 103 | DEFAULT(0),
|
| 104 | ALTERNATIVE(1),
|
| 105 | ALTERNATIVE_WITH_SPEED(2);
|
| 106 |
|
| 107 | private static final IntFunction<ClientboundLevelParticlesPacket.RandomizationType> BY_ID = ByIdMap.continuous(
|
| 108 | h -> h.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO
|
| 109 | );
|
| 110 | public static final StreamCodec<ByteBuf, ClientboundLevelParticlesPacket.RandomizationType> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, h -> h.id);
|
| 111 | private final int id;
|
| 112 |
|
| 113 | RandomizationType(final int id) {
|
| 114 | this.id = id;
|
| 115 | }
|
| 116 |
|
| 117 | public boolean isAlternative() {
|
| 118 | return this != DEFAULT;
|
| 119 | }
|
| 120 | }
|
| 121 | }
|
| 122 |
|