Expose more data for MusicInstrument (#12415)
This commit is contained in:
@ -1,14 +1,16 @@
|
||||
package org.bukkit.craftbukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.util.Holderable;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.Instrument;
|
||||
import org.bukkit.MusicInstrument;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Sound;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftMusicInstrument extends MusicInstrument implements io.papermc.paper.util.Holderable<Instrument> {
|
||||
@ -26,19 +28,19 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
|
||||
}
|
||||
|
||||
public static Holder<Instrument> bukkitToMinecraftHolder(MusicInstrument bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.INSTRUMENT); // Paper - switch to Holder
|
||||
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.INSTRUMENT);
|
||||
}
|
||||
|
||||
public static Object bukkitToString(MusicInstrument bukkit) { // Paper - switch to Holder
|
||||
public static Object bukkitToString(MusicInstrument bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return ((CraftMusicInstrument) bukkit).toBukkitSerializationObject(Instrument.DIRECT_CODEC); // Paper - switch to Holder
|
||||
return ((CraftMusicInstrument) bukkit).toBukkitSerializationObject(Instrument.DIRECT_CODEC);
|
||||
}
|
||||
|
||||
public static MusicInstrument stringToBukkit(Object string) { // Paper - switch to Holder
|
||||
public static MusicInstrument stringToBukkit(Object string) {
|
||||
Preconditions.checkArgument(string != null);
|
||||
|
||||
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, RegistryKey.INSTRUMENT); // Paper - switch to Holder
|
||||
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, RegistryKey.INSTRUMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,8 +65,28 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Instrument> getHolder() { // Paper - switch to Holder
|
||||
return this.holder; // Paper - switch to Holder
|
||||
public Holder<Instrument> getHolder() {
|
||||
return this.holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDuration() {
|
||||
return this.getHandle().useDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRange() {
|
||||
return this.getHandle().range();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component description() {
|
||||
return PaperAdventure.asAdventure(this.getHandle().description());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getSound() {
|
||||
return CraftSound.minecraftHolderToBukkit(this.getHandle().soundEvent());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -76,7 +98,7 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
|
||||
@Override
|
||||
public @NotNull String translationKey() {
|
||||
if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
|
||||
throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
throw new UnsupportedOperationException("Description isn't translatable!");
|
||||
}
|
||||
return translatableContents.getKey();
|
||||
}
|
||||
|
||||
@ -14,6 +14,10 @@ public class CraftSound extends OldEnumHolderable<Sound, SoundEvent> implements
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT);
|
||||
}
|
||||
|
||||
public static Sound minecraftHolderToBukkit(Holder<SoundEvent> minecraft) {
|
||||
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.SOUND_EVENT);
|
||||
}
|
||||
|
||||
public static SoundEvent bukkitToMinecraft(Sound bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user