Skip to content

Commit

Permalink
WrapperPlayServerSoundEffect fix attempt for 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
retrooper committed May 8, 2024
1 parent 1bad630 commit 6869ac5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

public class Sounds {

private static final Map<String, Sound> POTION_TYPE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, Sound>> POTION_TYPE_ID_MAP = new HashMap<>();
private static final Map<String, Sound> SOUND_TYPE_MAP = new HashMap<>();
private static final Map<Byte, Map<Integer, Sound>> SOUND_TYPE_ID_MAP = new HashMap<>();

private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("sound/sound_mappings");

Expand Down Expand Up @@ -70,17 +70,17 @@ public boolean equals(Object obj) {
return false;
}
};
MappingHelper.registerMapping(TYPES_BUILDER, POTION_TYPE_MAP, POTION_TYPE_ID_MAP, potionType);
MappingHelper.registerMapping(TYPES_BUILDER, SOUND_TYPE_MAP, SOUND_TYPE_ID_MAP, potionType);
return potionType;
}

public static @Nullable Sound getByName(String name) {
return POTION_TYPE_MAP.get(name);
return SOUND_TYPE_MAP.get(name);
}

public static @Nullable Sound getById(ClientVersion version, int id) {
int index = TYPES_BUILDER.getDataIndex(version);
Map<Integer, Sound> idMap = POTION_TYPE_ID_MAP.get((byte) index);
Map<Integer, Sound> idMap = SOUND_TYPE_ID_MAP.get((byte) index);
return idMap.get(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.github.retrooper.packetevents.protocol.sound.Sounds;
import com.github.retrooper.packetevents.util.Vector3i;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -73,8 +74,11 @@ public WrapperPlayServerSoundEffect(Sound sound, SoundCategory soundCategory,
@Override
public void read() {
this.sound = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_19_3) ? Sound.read(this)
: Sounds.getById(this.serverVersion.toClientVersion(), this.readVarInt());
soundCategory = SoundCategory.fromId(readVarInt());
: serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9) ? Sounds.getById(this.serverVersion.toClientVersion(), this.readVarInt())
: Sounds.getByName(readString());
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) {
soundCategory = SoundCategory.fromId(readVarInt());
}
effectPosition = new Vector3i(readInt(), readInt(), readInt());
volume = readFloat();
pitch = readFloat();
Expand Down Expand Up @@ -103,7 +107,7 @@ public void write() {

@Override
public void copy(WrapperPlayServerSoundEffect wrapper) {
this.sound = wrapper.sound;
sound = wrapper.sound;
soundCategory = wrapper.soundCategory;
effectPosition = wrapper.effectPosition;
volume = wrapper.volume;
Expand All @@ -129,6 +133,7 @@ public void setSoundId(int soundId) {
this.setSound(Sounds.getById(this.serverVersion.toClientVersion(), soundId));
}

@Nullable
public SoundCategory getSoundCategory() {
return soundCategory;
}
Expand Down

0 comments on commit 6869ac5

Please sign in to comment.