#1053: Add MusicInstrument fields for description, range, duration and sound

This commit is contained in:
Doc 2025-01-16 19:46:54 +11:00 committed by md_5
parent c16b696e41
commit 442838fdae
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 26 additions and 0 deletions

View File

@ -13,6 +13,8 @@ import net.minecraft.world.item.Instrument;
import org.bukkit.MusicInstrument; import org.bukkit.MusicInstrument;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.HolderHandleable; import org.bukkit.craftbukkit.util.HolderHandleable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -90,6 +92,26 @@ public class CraftMusicInstrument extends MusicInstrument implements HolderHandl
return handle; return handle;
} }
@Override
public String getDescription() {
return CraftChatMessage.fromComponent(this.getHandle().description());
}
@Override
public float getDuration() {
return this.getHandle().useDuration();
}
@Override
public float getRange() {
return this.getHandle().range();
}
@Override
public Sound getSoundEvent() {
return CraftSound.minecraftHolderToBukkit(this.getHandle().soundEvent());
}
@NotNull @NotNull
@Override @Override
public NamespacedKey getKey() { public NamespacedKey getKey() {

View File

@ -19,6 +19,10 @@ public class CraftSound extends CraftOldEnumRegistryItem<Sound, SoundEffect> imp
return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT, Registry.SOUNDS); return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT, Registry.SOUNDS);
} }
public static Sound minecraftHolderToBukkit(Holder<SoundEffect> minecraft) {
return minecraftToBukkit(minecraft.value());
}
public static SoundEffect bukkitToMinecraft(Sound bukkit) { public static SoundEffect bukkitToMinecraft(Sound bukkit) {
return CraftRegistry.bukkitToMinecraft(bukkit); return CraftRegistry.bukkitToMinecraft(bukkit);
} }