|
3 | 3 | import com.google.common.base.Preconditions;
|
4 | 4 | import net.minecraft.core.Holder;
|
5 | 5 | import net.minecraft.core.registries.Registries;
|
| 6 | +import net.minecraft.world.entity.animal.wolf.WolfSoundVariant; |
6 | 7 | import net.minecraft.world.entity.animal.wolf.WolfVariant;
|
7 | 8 | import org.bukkit.DyeColor;
|
8 | 9 | import org.bukkit.NamespacedKey;
|
@@ -77,6 +78,18 @@ public void setVariant(Variant variant) {
|
77 | 78 | this.getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant));
|
78 | 79 | }
|
79 | 80 |
|
| 81 | + @Override |
| 82 | + public SoundVariant getSoundVariant() { |
| 83 | + return CraftSoundVariant.minecraftHolderToBukkit(this.getHandle().getSoundVariant()); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void setSoundVariant(SoundVariant soundVariant) { |
| 88 | + Preconditions.checkArgument(soundVariant != null, "soundVariant cannot be null"); |
| 89 | + |
| 90 | + this.getHandle().setSoundVariant(CraftSoundVariant.bukkitToMinecraftHolder(soundVariant)); |
| 91 | + } |
| 92 | + |
80 | 93 | public static class CraftVariant implements Variant, Handleable<WolfVariant> {
|
81 | 94 |
|
82 | 95 | public static Variant minecraftToBukkit(WolfVariant minecraft) {
|
@@ -145,4 +158,73 @@ public int hashCode() {
|
145 | 158 | return this.getKey().hashCode();
|
146 | 159 | }
|
147 | 160 | }
|
| 161 | + |
| 162 | + public static class CraftSoundVariant implements SoundVariant, Handleable<WolfSoundVariant> { |
| 163 | + |
| 164 | + public static SoundVariant minecraftToBukkit(WolfSoundVariant minecraft) { |
| 165 | + return CraftRegistry.minecraftToBukkit(minecraft, Registries.WOLF_SOUND_VARIANT); |
| 166 | + } |
| 167 | + |
| 168 | + public static SoundVariant minecraftHolderToBukkit(Holder<WolfSoundVariant> minecraft) { |
| 169 | + return CraftSoundVariant.minecraftToBukkit(minecraft.value()); |
| 170 | + } |
| 171 | + |
| 172 | + public static WolfSoundVariant bukkitToMinecraft(SoundVariant bukkit) { |
| 173 | + return CraftRegistry.bukkitToMinecraft(bukkit); |
| 174 | + } |
| 175 | + |
| 176 | + public static Holder<WolfSoundVariant> bukkitToMinecraftHolder(SoundVariant bukkit) { |
| 177 | + Preconditions.checkArgument(bukkit != null); |
| 178 | + |
| 179 | + net.minecraft.core.Registry<WolfSoundVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_SOUND_VARIANT); |
| 180 | + |
| 181 | + if (registry.wrapAsHolder(CraftSoundVariant.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<WolfSoundVariant> holder) { |
| 182 | + return holder; |
| 183 | + } |
| 184 | + |
| 185 | + throw new IllegalArgumentException("No Reference holder found for " + bukkit |
| 186 | + + ", this can happen if a plugin creates its own wolf sound variant with out properly registering it."); |
| 187 | + } |
| 188 | + |
| 189 | + private final NamespacedKey key; |
| 190 | + private final WolfSoundVariant soundVariant; |
| 191 | + |
| 192 | + public CraftSoundVariant(NamespacedKey key, WolfSoundVariant soundVariant) { |
| 193 | + this.key = key; |
| 194 | + this.soundVariant = soundVariant; |
| 195 | + } |
| 196 | + |
| 197 | + @Override |
| 198 | + public WolfSoundVariant getHandle() { |
| 199 | + return this.soundVariant; |
| 200 | + } |
| 201 | + |
| 202 | + @Override |
| 203 | + public NamespacedKey getKey() { |
| 204 | + return this.key; |
| 205 | + } |
| 206 | + |
| 207 | + @Override |
| 208 | + public String toString() { |
| 209 | + return this.key.toString(); |
| 210 | + } |
| 211 | + |
| 212 | + @Override |
| 213 | + public boolean equals(Object other) { |
| 214 | + if (this == other) { |
| 215 | + return true; |
| 216 | + } |
| 217 | + |
| 218 | + if (!(other instanceof CraftSoundVariant otherVariant)) { |
| 219 | + return false; |
| 220 | + } |
| 221 | + |
| 222 | + return this.getKey().equals(otherVariant.getKey()); |
| 223 | + } |
| 224 | + |
| 225 | + @Override |
| 226 | + public int hashCode() { |
| 227 | + return this.getKey().hashCode(); |
| 228 | + } |
| 229 | + } |
148 | 230 | }
|
0 commit comments