Improve break sound retrieval

This commit is contained in:
ThisTestUser
2024-09-21 20:58:30 -04:00
parent 9ac2491cd3
commit a6adcd0926
3 changed files with 1 additions and 25 deletions

View File

@@ -1,6 +1,5 @@
package net.nuggetmc.tplus.api; package net.nuggetmc.tplus.api;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
/** /**
@@ -8,6 +7,4 @@ import org.bukkit.block.Block;
*/ */
public interface InternalBridge { public interface InternalBridge {
void sendBlockDestructionPacket(short entityId, Block block, int progress); void sendBlockDestructionPacket(short entityId, Block block, int progress);
Sound breakBlockSound(Block block);
} }

View File

@@ -1,6 +1,5 @@
package net.nuggetmc.tplus.api.agent.legacyagent; package net.nuggetmc.tplus.api.agent.legacyagent;
import net.nuggetmc.tplus.api.TerminatorPlusAPI;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -32,6 +31,6 @@ public class LegacyUtils {
} }
public static Sound breakBlockSound(Block block) { public static Sound breakBlockSound(Block block) {
return TerminatorPlusAPI.getInternalBridge().breakBlockSound(block); return block.getBlockData().getSoundGroup().getBreakSound();
} }
} }

View File

@@ -2,13 +2,8 @@ package net.nuggetmc.tplus.bridge;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.nuggetmc.tplus.api.InternalBridge; import net.nuggetmc.tplus.api.InternalBridge;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -20,19 +15,4 @@ public class InternalBridgeImpl implements InternalBridge {
((CraftPlayer) all).getHandle().connection.send(crack); ((CraftPlayer) all).getHandle().connection.send(crack);
} }
} }
@Override
public Sound breakBlockSound(Block block) {
try {
Level nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
BlockState blockState = nmsWorld.getBlockState(new BlockPos(block.getX(), block.getY(), block.getZ()));
net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
SoundType soundEffectType = nmsBlock.getSoundType(blockState);
return Sound.valueOf(soundEffectType.getBreakSound().getLocation().getPath().replace(".", "_").toUpperCase());
} catch (Exception e) { // potentially unsafe, just fallback to stone break sound
return Sound.BLOCK_STONE_BREAK;
}
}
} }