From 7bae78f2dd97e887c447b99576eb9afbe77e7a41 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 14 Jul 2024 02:22:37 +1200 Subject: [PATCH] Fix wolf variants --- .../v1_20_R4/ReflectionManager.java | 21 ++++++------------- .../v1_21_R1/ReflectionManager.java | 21 ++++++------------- .../disguise/disguisetypes/AnimalColor.java | 5 ++--- .../disguise/disguisetypes/MetaIndex.java | 4 ++++ 4 files changed, 18 insertions(+), 33 deletions(-) diff --git a/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java b/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java index ac2e75f8..9ca588a3 100644 --- a/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java +++ b/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java @@ -10,7 +10,6 @@ import io.netty.buffer.PooledByteBufAllocator; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.SneakyThrows; import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract; -import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.registries.BuiltInRegistries; @@ -323,7 +322,7 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getEntityTypeId(Object entityTypes) { net.minecraft.world.entity.EntityType entityType = (net.minecraft.world.entity.EntityType) entityTypes; - return BuiltInRegistries.ENTITY_TYPE.getId(entityType); + return BuiltInRegistries.ENTITY_TYPE.getIdOrThrow(entityType); } @Override @@ -401,8 +400,6 @@ public class ReflectionManager implements ReflectionManagerAbstract { public Cat.Type getCatTypeFromInt(int catType) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.CAT_VARIANT); - Holder.Reference ref = registry.getHolder(catType).get(); - return CraftCat.CraftType.minecraftHolderToBukkit(registry.getHolder(catType).get()); } @@ -410,15 +407,13 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getCatVariantAsInt(Cat.Type type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.CAT_VARIANT); - return registry.getId(CraftCat.CraftType.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftCat.CraftType.bukkitToMinecraft(type)); } @Override public Frog.Variant getFrogVariantFromInt(int frogType) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.FROG_VARIANT); - Holder.Reference ref = registry.getHolder(frogType).get(); - return CraftFrog.CraftVariant.minecraftHolderToBukkit(registry.getHolder(frogType).get()); } @@ -426,15 +421,13 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getFrogVariantAsInt(Frog.Variant type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.FROG_VARIANT); - return registry.getId(CraftFrog.CraftVariant.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftFrog.CraftVariant.bukkitToMinecraft(type)); } @Override public Art getPaintingFromInt(int paintingId) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.PAINTING_VARIANT); - Holder.Reference ref = registry.getHolder(paintingId).get(); - return CraftArt.minecraftHolderToBukkit(registry.getHolder(paintingId).get()); } @@ -442,23 +435,21 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getPaintingAsInt(Art type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.PAINTING_VARIANT); - return registry.getId(CraftArt.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftArt.bukkitToMinecraft(type)); } @Override public Wolf.Variant getWolfVariantFromInt(int wolfVariant) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.WOLF_VARIANT); - Holder.Reference ref = registry.getHolder(wolfVariant).get(); - - return CraftWolf.CraftVariant.minecraftHolderToBukkit(registry.getHolder(wolfVariant).get()); + return CraftWolf.CraftVariant.minecraftHolderToBukkit(registry.getHolder(wolfVariant - 1).get()); } @Override public int getWolfVariantAsInt(Wolf.Variant type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.WOLF_VARIANT); - return registry.getId(CraftWolf.CraftVariant.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftWolf.CraftVariant.bukkitToMinecraft(type)) + 1; } @Override diff --git a/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java b/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java index 9b681c49..f3f742b2 100644 --- a/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java +++ b/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java @@ -10,7 +10,6 @@ import io.netty.buffer.PooledByteBufAllocator; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.SneakyThrows; import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract; -import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.registries.BuiltInRegistries; @@ -323,7 +322,7 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getEntityTypeId(Object entityTypes) { net.minecraft.world.entity.EntityType entityType = (net.minecraft.world.entity.EntityType) entityTypes; - return BuiltInRegistries.ENTITY_TYPE.getId(entityType); + return BuiltInRegistries.ENTITY_TYPE.getIdOrThrow(entityType); } @Override @@ -401,8 +400,6 @@ public class ReflectionManager implements ReflectionManagerAbstract { public Cat.Type getCatTypeFromInt(int catType) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.CAT_VARIANT); - Holder.Reference ref = registry.getHolder(catType).get(); - return CraftCat.CraftType.minecraftHolderToBukkit(registry.getHolder(catType).get()); } @@ -410,15 +407,13 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getCatVariantAsInt(Cat.Type type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.CAT_VARIANT); - return registry.getId(CraftCat.CraftType.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftCat.CraftType.bukkitToMinecraft(type)); } @Override public Frog.Variant getFrogVariantFromInt(int frogType) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.FROG_VARIANT); - Holder.Reference ref = registry.getHolder(frogType).get(); - return CraftFrog.CraftVariant.minecraftHolderToBukkit(registry.getHolder(frogType).get()); } @@ -426,15 +421,13 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getFrogVariantAsInt(Frog.Variant type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.FROG_VARIANT); - return registry.getId(CraftFrog.CraftVariant.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftFrog.CraftVariant.bukkitToMinecraft(type)); } @Override public Art getPaintingFromInt(int paintingId) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.PAINTING_VARIANT); - Holder.Reference ref = registry.getHolder(paintingId).get(); - return CraftArt.minecraftHolderToBukkit(registry.getHolder(paintingId).get()); } @@ -442,23 +435,21 @@ public class ReflectionManager implements ReflectionManagerAbstract { public int getPaintingAsInt(Art type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.PAINTING_VARIANT); - return registry.getId(CraftArt.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftArt.bukkitToMinecraft(type)); } @Override public Wolf.Variant getWolfVariantFromInt(int wolfVariant) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.WOLF_VARIANT); - Holder.Reference ref = registry.getHolder(wolfVariant).get(); - - return CraftWolf.CraftVariant.minecraftHolderToBukkit(registry.getHolder(wolfVariant).get()); + return CraftWolf.CraftVariant.minecraftHolderToBukkit(registry.getHolder(wolfVariant - 1).get()); } @Override public int getWolfVariantAsInt(Wolf.Variant type) { Registry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.WOLF_VARIANT); - return registry.getId(CraftWolf.CraftVariant.bukkitToMinecraft(type)); + return registry.getIdOrThrow(CraftWolf.CraftVariant.bukkitToMinecraft(type)) + 1; } @Override diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java index 3c903d4d..270ab969 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.disguisetypes; +import lombok.Getter; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -102,6 +103,7 @@ public enum AnimalColor { return null; } + @Getter private final DyeColor dyeColor; private final Material material; @@ -114,7 +116,4 @@ public enum AnimalColor { return material; } - public DyeColor getDyeColor() { - return dyeColor; - } } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index c7513bb6..db10b518 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -1281,4 +1281,8 @@ public class MetaIndex { return this == ARMORSTAND_BODY || this == ARMORSTAND_HEAD || this == ARMORSTAND_LEFT_ARM || this == ARMORSTAND_RIGHT_ARM || this == ARMORSTAND_LEFT_LEG || this == ARMORSTAND_RIGHT_LEG; } + + public boolean isUsed() { + return getIndex() >= 0; + } }