diff --git a/src/main/java/com/mohistmc/forge/ForgeInjectBukkit.java b/src/main/java/com/mohistmc/forge/ForgeInjectBukkit.java index 6152eca679..7b1af097df 100644 --- a/src/main/java/com/mohistmc/forge/ForgeInjectBukkit.java +++ b/src/main/java/com/mohistmc/forge/ForgeInjectBukkit.java @@ -63,6 +63,7 @@ import org.bukkit.craftbukkit.v1_16_R3.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.v1_16_R3.potion.CraftPotionUtil; import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; import org.bukkit.permissions.PermissionDefault; @@ -231,17 +232,16 @@ public static WorldType addEnumWorldType(String name) } public static void addEnumEntity() { - Map NAME_MAP = ObfuscationReflectionHelper.getPrivateValue(EntityType.class, null, "NAME_MAP"); - Map ID_MAP = ObfuscationReflectionHelper.getPrivateValue(EntityType.class, null, "ID_MAP"); - for (Map.Entry>, net.minecraft.entity.EntityType> entity : ForgeRegistries.ENTITIES.getEntries()) { ResourceLocation resourceLocation = entity.getValue().getRegistryName(); + NamespacedKey key = CraftNamespacedKey.fromMinecraft(resourceLocation); if (!resourceLocation.getNamespace().equals(NamespacedKey.MINECRAFT)) { String entityType = normalizeName(resourceLocation.toString()); int typeId = entityType.hashCode(); EntityType bukkitType = MohistEnumHelper.addEnum0(EntityType.class, entityType, new Class[]{String.class, Class.class, Integer.TYPE, Boolean.TYPE}, entityType.toLowerCase(), CraftCustomEntity.class, typeId, false); - NAME_MAP.put(entityType.toLowerCase(), bukkitType); - ID_MAP.put((short) typeId, bukkitType); + bukkitType.key = key; + EntityType.NAME_MAP.put(entityType.toLowerCase(), bukkitType); + EntityType.ID_MAP.put((short) typeId, bukkitType); ServerAPI.entityTypeMap.put(entity.getValue(), entityType); } } diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java index bda8c7b884..d86af9f943 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java +++ b/src/main/java/org/bukkit/entity/EntityType.java @@ -292,10 +292,10 @@ public enum EntityType implements Keyed { private final Class clazz; private final short typeId; private final boolean independent, living; - private final NamespacedKey key; + public NamespacedKey key; - private static final Map NAME_MAP = new HashMap(); - private static final Map ID_MAP = new HashMap(); + public static final Map NAME_MAP = new HashMap(); + public static final Map ID_MAP = new HashMap(); static { for (EntityType type : values()) { @@ -345,7 +345,7 @@ private EntityType(/*@Nullable*/ String name, /*@Nullable*/ Class