#752: Add the ability to retrieve hit, step, fall, and other sounds from blocks.
This commit is contained in:
parent
167ff59173
commit
424598d294
15
nms-patches/SoundEffectType.patch
Normal file
15
nms-patches/SoundEffectType.patch
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
--- a/net/minecraft/server/SoundEffectType.java
|
||||||
|
+++ b/net/minecraft/server/SoundEffectType.java
|
||||||
|
@@ -51,10 +51,10 @@
|
||||||
|
public static final SoundEffectType U = new SoundEffectType(1.0F, 1.0F, SoundEffects.BLOCK_GILDED_BLACKSTONE_BREAK, SoundEffects.BLOCK_GILDED_BLACKSTONE_STEP, SoundEffects.BLOCK_GILDED_BLACKSTONE_PLACE, SoundEffects.BLOCK_GILDED_BLACKSTONE_HIT, SoundEffects.BLOCK_GILDED_BLACKSTONE_FALL);
|
||||||
|
public final float V;
|
||||||
|
public final float W;
|
||||||
|
- private final SoundEffect X;
|
||||||
|
+ public final SoundEffect X; // PAIL private -> public, rename breakSound
|
||||||
|
private final SoundEffect Y;
|
||||||
|
private final SoundEffect Z;
|
||||||
|
- private final SoundEffect aa;
|
||||||
|
+ public final SoundEffect aa; // PAIL private -> public, rename hitSound
|
||||||
|
private final SoundEffect ab;
|
||||||
|
|
||||||
|
public SoundEffectType(float f, float f1, SoundEffect soundeffect, SoundEffect soundeffect1, SoundEffect soundeffect2, SoundEffect soundeffect3, SoundEffect soundeffect4) {
|
File diff suppressed because it is too large
Load Diff
59
src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java
Normal file
59
src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -2070,7 +2070,7 @@ public class CraftWorld implements World {
|
|||||||
double y = loc.getY();
|
double y = loc.getY();
|
||||||
double z = loc.getZ();
|
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
|
@Override
|
||||||
|
@ -2,8 +2,6 @@ package org.bukkit.craftbukkit.block.data;
|
|||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Preconditions;
|
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.google.common.collect.ImmutableSet;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
@ -24,8 +22,10 @@ import net.minecraft.server.INamable;
|
|||||||
import net.minecraft.server.IRegistry;
|
import net.minecraft.server.IRegistry;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.SoundGroup;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.craftbukkit.CraftSoundGroup;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
|
|
||||||
@ -512,4 +512,9 @@ public class CraftBlockData implements BlockData {
|
|||||||
public static CraftBlockData fromData(IBlockData data) {
|
public static CraftBlockData fromData(IBlockData data) {
|
||||||
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
|
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundGroup getSoundGroup() {
|
||||||
|
return CraftSoundGroup.getSoundGroup(state.getStepSound());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
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;
|
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);
|
getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopSound(Sound sound, org.bukkit.SoundCategory category) {
|
public void stopSound(Sound sound, org.bukkit.SoundCategory category) {
|
||||||
stopSound(CraftSound.getSound(sound), category);
|
stopSound(sound.getKey().getKey(), category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,7 +13,7 @@ public class SoundTest extends AbstractTestingBase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetSound() {
|
public void testGetSound() {
|
||||||
for (Sound sound : Sound.values()) {
|
for (Sound sound : Sound.values()) {
|
||||||
assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
|
assertThat(sound.name(), CraftSound.getSoundEffect(sound), is(not(nullValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user