#752: Add the ability to retrieve hit, step, fall, and other sounds from blocks.

By: Martoph <sager1018@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2020-11-26 09:36:57 +11:00
parent ec41049c8d
commit d9f5dbb3e6
7 changed files with 99 additions and 1012 deletions

View File

@@ -0,0 +1,59 @@
package org.bukkit.craftbukkit;
import java.util.HashMap;
import net.minecraft.server.SoundEffectType;
import org.bukkit.Sound;
import org.bukkit.SoundGroup;
public class CraftSoundGroup implements SoundGroup {
private final net.minecraft.server.SoundEffectType handle;
private static final HashMap<SoundEffectType, CraftSoundGroup> SOUND_GROUPS = new HashMap<>();
public static SoundGroup getSoundGroup(SoundEffectType soundEffectType) {
return SOUND_GROUPS.computeIfAbsent(soundEffectType, CraftSoundGroup::new);
}
private CraftSoundGroup(net.minecraft.server.SoundEffectType soundEffectType) {
this.handle = soundEffectType;
}
public net.minecraft.server.SoundEffectType getHandle() {
return handle;
}
@Override
public float getVolume() {
return getHandle().V; // PAIL rename volume
}
@Override
public float getPitch() {
return getHandle().W; // PAIL rename pitch
}
@Override
public Sound getBreakSound() {
return CraftSound.getBukkit(getHandle().X);
}
@Override
public Sound getStepSound() {
return CraftSound.getBukkit(getHandle().d()); // PAIL rename getStepSound
}
@Override
public Sound getPlaceSound() {
return CraftSound.getBukkit(getHandle().e()); // PAIL rename getPlaceSound
}
@Override
public Sound getHitSound() {
return CraftSound.getBukkit(getHandle().aa);
}
@Override
public Sound getFallSound() {
return CraftSound.getBukkit(getHandle().g()); // PAIL rename getFallSound
}
}

View File

@@ -2070,7 +2070,7 @@ public class CraftWorld implements World {
double y = loc.getY();
double z = loc.getZ();
getHandle().playSound(null, x, y, z, CraftSound.getSoundEffect(CraftSound.getSound(sound)), SoundCategory.valueOf(category.name()), volume, pitch);
getHandle().playSound(null, x, y, z, CraftSound.getSoundEffect(sound), SoundCategory.valueOf(category.name()), volume, pitch);
}
@Override

View File

@@ -2,8 +2,6 @@ package org.bukkit.craftbukkit.block.data;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableSet;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -24,8 +22,10 @@ import net.minecraft.server.INamable;
import net.minecraft.server.IRegistry;
import net.minecraft.server.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.SoundGroup;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.CraftSoundGroup;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@@ -512,4 +512,9 @@ public class CraftBlockData implements BlockData {
public static CraftBlockData fromData(IBlockData data) {
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
}
@Override
public SoundGroup getSoundGroup() {
return CraftSoundGroup.getSoundGroup(state.getStepSound());
}
}

View File

@@ -475,7 +475,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (loc == null || sound == null || category == null || getHandle().playerConnection == null) return;
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(CraftSound.getSound(sound)), net.minecraft.server.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch);
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(sound), net.minecraft.server.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch);
getHandle().playerConnection.sendPacket(packet);
}
@@ -499,7 +499,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void stopSound(Sound sound, org.bukkit.SoundCategory category) {
stopSound(CraftSound.getSound(sound), category);
stopSound(sound.getKey().getKey(), category);
}
@Override

View File

@@ -13,7 +13,7 @@ public class SoundTest extends AbstractTestingBase {
@Test
public void testGetSound() {
for (Sound sound : Sound.values()) {
assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
assertThat(sound.name(), CraftSound.getSoundEffect(sound), is(not(nullValue())));
}
}