Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Fixed #2707
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Dec 1, 2023
1 parent 8d2c796 commit 28e40bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/mohistmc/forge/ForgeInjectBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,17 +232,16 @@ public static WorldType addEnumWorldType(String name)
}

public static void addEnumEntity() {
Map<String, EntityType> NAME_MAP = ObfuscationReflectionHelper.getPrivateValue(EntityType.class, null, "NAME_MAP");
Map<Short, EntityType> ID_MAP = ObfuscationReflectionHelper.getPrivateValue(EntityType.class, null, "ID_MAP");

for (Map.Entry<RegistryKey<net.minecraft.entity.EntityType<?>>, 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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/bukkit/entity/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ public enum EntityType implements Keyed {
private final Class<? extends Entity> clazz;
private final short typeId;
private final boolean independent, living;
private final NamespacedKey key;
public NamespacedKey key;

private static final Map<String, EntityType> NAME_MAP = new HashMap<String, EntityType>();
private static final Map<Short, EntityType> ID_MAP = new HashMap<Short, EntityType>();
public static final Map<String, EntityType> NAME_MAP = new HashMap<String, EntityType>();
public static final Map<Short, EntityType> ID_MAP = new HashMap<Short, EntityType>();

static {
for (EntityType type : values()) {
Expand Down Expand Up @@ -345,7 +345,7 @@ private EntityType(/*@Nullable*/ String name, /*@Nullable*/ Class<? extends Enti
@Deprecated
@Nullable
public String getName() {
return name;
return name == null ? name() : name; // Mohist
}

@NotNull
Expand Down

0 comments on commit 28e40bf

Please sign in to comment.