#1303: Create registry for banner pattern and cat type

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-12-08 19:26:30 +11:00
parent aacf3bd308
commit a5594be1c7
2 changed files with 10 additions and 4 deletions

View file

@ -7,8 +7,10 @@ import net.minecraft.world.entity.animal.CatVariant;
import net.minecraft.world.entity.animal.EntityCat;
import net.minecraft.world.item.EnumColor;
import org.bukkit.DyeColor;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Cat;
public class CraftCat extends CraftTameableAnimal implements Cat {
@ -56,14 +58,15 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
IRegistry<CatVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT);
return Type.values()[registry.getId(minecraft)];
return Registry.CAT_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getKey(minecraft)));
}
public static CatVariant bukkitToMinecraft(Type bukkit) {
Preconditions.checkArgument(bukkit != null);
return CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT)
.byId(bukkit.ordinal());
IRegistry<CatVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT);
return registry.get(CraftNamespacedKey.toMinecraft(bukkit.getKey()));
}
}
}

View file

@ -3,6 +3,8 @@ package org.bukkit.block.banner;
import static org.junit.jupiter.api.Assertions.*;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.entity.EnumBannerPatternType;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.support.AbstractTestingBase;
import org.junit.jupiter.api.Test;
@ -22,7 +24,8 @@ public class PatternTypeTest extends AbstractTestingBase {
for (PatternType bukkit : PatternType.values()) {
EnumBannerPatternType found = null;
for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) {
if (bukkit.getIdentifier().equals(nms.getHashname())) {
NamespacedKey nmsKey = CraftNamespacedKey.fromMinecraft(BuiltInRegistries.BANNER_PATTERN.getKey(nms));
if (bukkit.getIdentifier().equals(nms.getHashname()) && bukkit.getKey().equals(nmsKey)) {
found = nms;
break;
}