mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Store BuiltinSound in ClientboundSoundEntityPacket instead of a soundId
Use generated output for BuiltinSound. Remove SoundCategory from MagicValues
This commit is contained in:
parent
3e163501aa
commit
5096d90655
8 changed files with 36 additions and 39 deletions
|
@ -60,7 +60,6 @@ import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValu
|
|||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.RespawnScreenValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSourceType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||
|
@ -617,17 +616,6 @@ public class MagicValues {
|
|||
register(StringProperties.QUOTABLE_PHRASE, 1);
|
||||
register(StringProperties.GREEDY_PHRASE, 2);
|
||||
|
||||
register(SoundCategory.MASTER, 0);
|
||||
register(SoundCategory.MUSIC, 1);
|
||||
register(SoundCategory.RECORD, 2);
|
||||
register(SoundCategory.WEATHER, 3);
|
||||
register(SoundCategory.BLOCK, 4);
|
||||
register(SoundCategory.HOSTILE, 5);
|
||||
register(SoundCategory.NEUTRAL, 6);
|
||||
register(SoundCategory.PLAYER, 7);
|
||||
register(SoundCategory.AMBIENT, 8);
|
||||
register(SoundCategory.VOICE, 9);
|
||||
|
||||
register(PositionSourceType.BLOCK, "minecraft:block");
|
||||
register(PositionSourceType.ENTITY, "minecraft:entity");
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ import java.util.Map;
|
|||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BuiltinSound implements Sound {
|
||||
ALLAY_AMBIENT_WITH_ITEM("entity.allay.ambient_with_item"),
|
||||
ALLAY_AMBIENT_WITHOUT_ITEM("entity.allay_ambient_without_item"),
|
||||
ALLAY_DEATH("entity.allay.death"),
|
||||
ALLAY_HURT("entity.allay.hurt"),
|
||||
ALLAY_ITEM_GIVEN("entity.allay.item_given"),
|
||||
ALLAY_ITEM_TAKEN("entity.allay.item_taken"),
|
||||
ALLAY_THROW("entity.allay.allay_throw"),
|
||||
ENTITY_ALLAY_AMBIENT_WITH_ITEM("entity.allay.ambient_with_item"),
|
||||
ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM("entity.allay.ambient_without_item"),
|
||||
ENTITY_ALLAY_DEATH("entity.allay.death"),
|
||||
ENTITY_ALLAY_HURT("entity.allay.hurt"),
|
||||
ENTITY_ALLAY_ITEM_GIVEN("entity.allay.item_given"),
|
||||
ENTITY_ALLAY_ITEM_TAKEN("entity.allay.item_taken"),
|
||||
ENTITY_ALLAY_ITEM_THROWN("entity.allay.item_thrown"),
|
||||
AMBIENT_CAVE("ambient.cave"),
|
||||
AMBIENT_BASALT_DELTAS_ADDITIONS("ambient.basalt_deltas.additions"),
|
||||
AMBIENT_BASALT_DELTAS_LOOP("ambient.basalt_deltas.loop"),
|
||||
|
@ -481,7 +481,7 @@ public enum BuiltinSound implements Sound {
|
|||
ENTITY_GOAT_PREPARE_RAM("entity.goat.prepare_ram"),
|
||||
ENTITY_GOAT_RAM_IMPACT("entity.goat.ram_impact"),
|
||||
ENTITY_GOAT_HORN_BREAK("entity.goat.horn_break"),
|
||||
ENTITY_GOAT_HORN_PLAY("item.goat_horn.play"),
|
||||
ITEM_GOAT_HORN_PLAY("item.goat_horn.play"),
|
||||
ENTITY_GOAT_SCREAMING_AMBIENT("entity.goat.screaming.ambient"),
|
||||
ENTITY_GOAT_SCREAMING_DEATH("entity.goat.screaming.death"),
|
||||
ENTITY_GOAT_SCREAMING_EAT("entity.goat.screaming.eat"),
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.sound;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public enum SoundCategory {
|
||||
MASTER,
|
||||
MUSIC,
|
||||
|
@ -10,5 +14,15 @@ public enum SoundCategory {
|
|||
NEUTRAL,
|
||||
PLAYER,
|
||||
AMBIENT,
|
||||
VOICE
|
||||
VOICE;
|
||||
|
||||
private static final SoundCategory[] VALUES = values();
|
||||
|
||||
public static SoundCategory read(NetInput in) throws IOException {
|
||||
return in.readEnum(VALUES);
|
||||
}
|
||||
|
||||
public static SoundCategory fromId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
@ -16,16 +16,16 @@ import java.io.IOException;
|
|||
@With
|
||||
@AllArgsConstructor
|
||||
public class ClientboundSoundEntityPacket implements Packet {
|
||||
private final int soundId;
|
||||
private final @NonNull SoundCategory soundCategory;
|
||||
private final @NonNull BuiltinSound sound;
|
||||
private final @NonNull SoundCategory category;
|
||||
private final int entityId;
|
||||
private final float volume;
|
||||
private final float pitch;
|
||||
private final long seed;
|
||||
|
||||
public ClientboundSoundEntityPacket(NetInput in) throws IOException {
|
||||
this.soundId = in.readVarInt();
|
||||
this.soundCategory = MagicValues.key(SoundCategory.class, in.readVarInt());
|
||||
this.sound = BuiltinSound.VALUES[in.readVarInt()];
|
||||
this.category = SoundCategory.read(in);
|
||||
this.entityId = in.readVarInt();
|
||||
this.volume = in.readFloat();
|
||||
this.pitch = in.readFloat();
|
||||
|
@ -34,8 +34,8 @@ public class ClientboundSoundEntityPacket implements Packet {
|
|||
|
||||
@Override
|
||||
public void write(NetOutput out) throws IOException {
|
||||
out.writeVarInt(this.soundId);
|
||||
out.writeVarInt(MagicValues.value(Integer.class, this.soundCategory));
|
||||
out.writeVarInt(this.sound.ordinal());
|
||||
out.writeVarInt(this.category.ordinal());
|
||||
out.writeVarInt(this.entityId);
|
||||
out.writeFloat(this.volume);
|
||||
out.writeFloat(this.pitch);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
|
||||
|
@ -28,7 +27,7 @@ public class ClientboundStopSoundPacket implements Packet {
|
|||
public ClientboundStopSoundPacket(NetInput in) throws IOException {
|
||||
int flags = in.readByte();
|
||||
if ((flags & FLAG_CATEGORY) != 0) {
|
||||
this.category = MagicValues.key(SoundCategory.class, in.readVarInt());
|
||||
this.category = SoundCategory.read(in);
|
||||
} else {
|
||||
this.category = null;
|
||||
}
|
||||
|
@ -59,7 +58,7 @@ public class ClientboundStopSoundPacket implements Packet {
|
|||
|
||||
out.writeByte(flags);
|
||||
if (this.category != null) {
|
||||
out.writeByte(MagicValues.value(Integer.class, this.category));
|
||||
out.writeByte(this.category.ordinal());
|
||||
}
|
||||
|
||||
if (this.sound != null) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.level;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
|
||||
|
@ -37,7 +36,7 @@ public class ClientboundCustomSoundPacket implements Packet {
|
|||
this.sound = new CustomSound(value);
|
||||
}
|
||||
|
||||
this.category = MagicValues.key(SoundCategory.class, in.readVarInt());
|
||||
this.category = SoundCategory.read(in);
|
||||
this.x = in.readInt() / 8D;
|
||||
this.y = in.readInt() / 8D;
|
||||
this.z = in.readInt() / 8D;
|
||||
|
@ -56,7 +55,7 @@ public class ClientboundCustomSoundPacket implements Packet {
|
|||
}
|
||||
|
||||
out.writeString(value);
|
||||
out.writeVarInt(MagicValues.value(Integer.class, this.category));
|
||||
out.writeVarInt(this.category.ordinal());
|
||||
out.writeInt((int) (this.x * 8));
|
||||
out.writeInt((int) (this.y * 8));
|
||||
out.writeInt((int) (this.z * 8));
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.level;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
|
@ -28,7 +27,7 @@ public class ClientboundSoundPacket implements Packet {
|
|||
|
||||
public ClientboundSoundPacket(NetInput in) throws IOException {
|
||||
this.sound = BuiltinSound.VALUES[in.readVarInt()];
|
||||
this.category = MagicValues.key(SoundCategory.class, in.readVarInt());
|
||||
this.category = SoundCategory.read(in);
|
||||
this.x = in.readInt() / 8D;
|
||||
this.y = in.readInt() / 8D;
|
||||
this.z = in.readInt() / 8D;
|
||||
|
@ -40,7 +39,7 @@ public class ClientboundSoundPacket implements Packet {
|
|||
@Override
|
||||
public void write(NetOutput out) throws IOException {
|
||||
out.writeVarInt(this.sound.ordinal());
|
||||
out.writeVarInt(MagicValues.value(Integer.class, this.category));
|
||||
out.writeVarInt(this.category.ordinal());
|
||||
out.writeInt((int) (this.x * 8));
|
||||
out.writeInt((int) (this.y * 8));
|
||||
out.writeInt((int) (this.z * 8));
|
||||
|
|
|
@ -58,7 +58,6 @@ import com.github.steveice10.mc.protocol.data.game.level.notify.DemoMessageValue
|
|||
import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSourceType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||
|
@ -160,7 +159,6 @@ public class MagicValuesTest {
|
|||
this.register(CommandParser.class, Integer.class);
|
||||
this.register(SuggestionType.class, String.class);
|
||||
this.register(StringProperties.class, Integer.class);
|
||||
this.register(SoundCategory.class, Integer.class);
|
||||
this.register(PositionSourceType.class, String.class);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue