Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: MiniDigger | Martin <admin@minidigger.dev> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
84 lines
2.9 KiB
Java
84 lines
2.9 KiB
Java
package org.bukkit.craftbukkit;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import io.papermc.paper.registry.RegistryKey;
|
|
import io.papermc.paper.util.Holderable;
|
|
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.jetbrains.annotations.NotNull;
|
|
|
|
public class CraftMusicInstrument extends MusicInstrument implements io.papermc.paper.util.Holderable<Instrument> {
|
|
|
|
public static MusicInstrument minecraftToBukkit(Instrument minecraft) {
|
|
return CraftRegistry.minecraftToBukkit(minecraft, Registries.INSTRUMENT);
|
|
}
|
|
|
|
public static MusicInstrument minecraftHolderToBukkit(Holder<Instrument> minecraft) {
|
|
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.INSTRUMENT); // Paper - switch to Holder
|
|
}
|
|
|
|
public static Instrument bukkitToMinecraft(MusicInstrument bukkit) {
|
|
return CraftRegistry.bukkitToMinecraft(bukkit);
|
|
}
|
|
|
|
public static Holder<Instrument> bukkitToMinecraftHolder(MusicInstrument bukkit) {
|
|
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.INSTRUMENT); // Paper - switch to Holder
|
|
}
|
|
|
|
public static Object bukkitToString(MusicInstrument bukkit) { // Paper - switch to Holder
|
|
Preconditions.checkArgument(bukkit != null);
|
|
|
|
return ((CraftMusicInstrument) bukkit).toBukkitSerializationObject(Instrument.DIRECT_CODEC); // Paper - switch to Holder
|
|
}
|
|
|
|
public static MusicInstrument stringToBukkit(Object string) { // Paper - switch to Holder
|
|
Preconditions.checkArgument(string != null);
|
|
|
|
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, RegistryKey.INSTRUMENT); // Paper - switch to Holder
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(final Object o) {
|
|
return this.implEquals(o);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return this.implHashCode();
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return this.implToString();
|
|
}
|
|
|
|
private final Holder<Instrument> holder;
|
|
|
|
public CraftMusicInstrument(Holder<Instrument> holder) {
|
|
this.holder = holder;
|
|
}
|
|
|
|
@Override
|
|
public Holder<Instrument> getHolder() { // Paper - switch to Holder
|
|
return this.holder; // Paper - switch to Holder
|
|
}
|
|
|
|
@NotNull
|
|
@Override
|
|
public NamespacedKey getKey() {
|
|
return Holderable.super.getKey();
|
|
}
|
|
|
|
@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
|
|
}
|
|
return translatableContents.getKey();
|
|
}
|
|
}
|