From dc997626c104ce9b904fb3a545da43c3f1ecb809 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 30 Dec 2025 02:41:45 +0800 Subject: [PATCH 01/11] Refactor getEntity method to handle abstract classes --- .../java/codechicken/nei/ItemMobSpawner.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index 4b5433c3..e124201b 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.lang.reflect.Modifier; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -81,24 +83,36 @@ public class ItemMobSpawner extends ItemBlock { + IDtoNameMap.get(meta)); } - public static EntityLiving getEntity(int ID) { - EntityLiving e = entityHashMap.get(ID); - if (e == null) { - loadSpawners(); - Class clazz = EntityList.IDtoClassMapping.get(ID); - World world = NEIClientUtils.mc().theWorld; - try { - e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); - } catch (Throwable t) { - if (clazz == null) - NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); - else NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); +public static EntityLiving getEntity(int ID) { + EntityLiving e = entityHashMap.get(ID); + if (e == null) { + loadSpawners(); + Class clazz = EntityList.IDtoClassMapping.get(ID); + World world = NEIClientUtils.mc().theWorld; + if (clazz != null) { + int modifiers = clazz.getModifiers(); + if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { + NEIClientConfig.logger.warn("Skipping abstract entity class: " + clazz.getName()); e = getEntity(idPig); + if (e != null) { + entityHashMap.put(ID, e); + } + return e; } - entityHashMap.put(ID, e); } - return e; + + try { + e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); + } catch (Throwable t) { + if (clazz == null) + NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); + else NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); + e = getEntity(idPig); + } + entityHashMap.put(ID, e); } + return e; +} public static void clearEntityReferences() { entityHashMap.clear(); From 7445d96531118f34e013e5e1c4ebf67452212b57 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 30 Dec 2025 02:42:47 +0800 Subject: [PATCH 02/11] Add workflow_dispatch trigger to release-tags.yml --- .github/workflows/release-tags.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml index e4c0be6b..cfcc277a 100644 --- a/.github/workflows/release-tags.yml +++ b/.github/workflows/release-tags.yml @@ -2,6 +2,7 @@ name: Release tagged build on: + workflow_dispatch: push: tags: [ '*' ] From 73eea57d114e29bcf09db8296eea7cf0695f7ffe Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:34:47 +0800 Subject: [PATCH 03/11] Update ItemMobSpawner.java --- .../java/codechicken/nei/ItemMobSpawner.java | 197 ++++++++++-------- 1 file changed, 112 insertions(+), 85 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index e124201b..551af24d 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -1,11 +1,10 @@ package codechicken.nei; +import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.lang.reflect.Modifier; - import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -28,122 +27,150 @@ import cpw.mods.fml.relauncher.SideOnly; public class ItemMobSpawner extends ItemBlock { - private static final Map entityHashMap = new HashMap<>(); - private static final Map IDtoNameMap = new HashMap<>(); - public static int idPig; - private static boolean loaded; + private static final Map ENTITY_CACHE = new HashMap<>(); + private static final Map ID_TO_NAME_MAP = new HashMap<>(); + private static final int DEFAULT_ID_PIG = 90; // 猪的默认ID + public static final int PIG_ID = DEFAULT_ID_PIG; + private static boolean loaded = false; public ItemMobSpawner() { super(Blocks.mob_spawner); - hasSubtypes = true; + this.hasSubtypes = true; MinecraftForgeClient.registerItemRenderer(this, new SpawnerRenderer()); } - /** - * These are ASM translated from BlockMobSpawner - */ public static int placedX; public static int placedY; public static int placedZ; @Override - public IIcon getIconFromDamage(int par1) { + public IIcon getIconFromDamage(int damage) { return Blocks.mob_spawner.getBlockTextureFromSide(0); } - public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, - float par8, float par9, float par10) { - if (super.onItemUse(itemstack, entityplayer, world, x, y, z, par7, par8, par9, par10) && world.isRemote) { - TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world - .getTileEntity(placedX, placedY, placedZ); - if (tileentitymobspawner != null) { - setDefaultTag(itemstack); - String mobtype = IDtoNameMap.get(itemstack.getItemDamage()); - if (mobtype != null) { - NEICPH.sendMobSpawnerID(placedX, placedY, placedZ, mobtype); - tileentitymobspawner.func_145881_a().setEntityName(mobtype); + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, + int x, int y, int z, int side, + float hitX, float hitY, float hitZ) { + boolean result = super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ); + + if (result && world.isRemote) { + TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getTileEntity(placedX, placedY, placedZ); + if (spawner != null) { + ensureValidDamage(stack); + String mobType = ID_TO_NAME_MAP.get(stack.getItemDamage()); + if (mobType != null && spawner.func_145881_a() != null) { + // 发送数据包 + if (NEICPH.instance != null) { + NEICPH.instance.sendMobSpawnerID(placedX, placedY, placedZ, mobType); + } + spawner.func_145881_a().setEntityName(mobType); } } - return true; } - return false; + return result; } @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) { - setDefaultTag(itemstack); - int meta = itemstack.getItemDamage(); + public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { + ensureValidDamage(stack); + int meta = stack.getItemDamage(); if (meta == 0) { - meta = idPig; + meta = PIG_ID; + } + + String mobName = ID_TO_NAME_MAP.get(meta); + if (mobName != null) { + Entity e = getEntity(meta); + EnumChatFormatting color = (e instanceof IMob) + ? EnumChatFormatting.DARK_RED + : EnumChatFormatting.DARK_AQUA; + tooltip.add(color + mobName); } - Entity e = getEntity(meta); - list.add( - (e instanceof IMob ? EnumChatFormatting.DARK_RED : EnumChatFormatting.DARK_AQUA) - + IDtoNameMap.get(meta)); } -public static EntityLiving getEntity(int ID) { - EntityLiving e = entityHashMap.get(ID); - if (e == null) { - loadSpawners(); - Class clazz = EntityList.IDtoClassMapping.get(ID); - World world = NEIClientUtils.mc().theWorld; - if (clazz != null) { - int modifiers = clazz.getModifiers(); + public static EntityLiving getEntity(int id) { + EntityLiving entity = ENTITY_CACHE.get(id); + if (entity == null) { + loadSpawners(); + + Class entityClass = EntityList.getClassFromID(id); + if (entityClass == null) { + NEIClientConfig.logger.warn("Invalid entity ID: " + id); + return getEntity(PIG_ID); + } + + int modifiers = entityClass.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { - NEIClientConfig.logger.warn("Skipping abstract entity class: " + clazz.getName()); - e = getEntity(idPig); - if (e != null) { - entityHashMap.put(ID, e); + NEIClientConfig.logger.warn("Skipping abstract entity class: " + entityClass.getName()); + entity = getEntity(PIG_ID); + ENTITY_CACHE.put(id, entity); + return entity; + } + + try { + World world = NEIClientUtils.getClientWorld(); + if (world != null) { + entity = (EntityLiving) entityClass.getConstructor(World.class).newInstance(world); + } else { + NEIClientConfig.logger.error("World is null, cannot create entity instance"); + return getEntity(PIG_ID); + } + } catch (Exception e) { + NEIClientConfig.logger.error("Error creating instance of entity: " + entityClass.getName(), e); + return getEntity(PIG_ID); + } + + ENTITY_CACHE.put(id, entity); + } + return entity; + } + + public static void clearEntityReferences() { + ENTITY_CACHE.clear(); + } + + private void ensureValidDamage(ItemStack stack) { + int damage = stack.getItemDamage(); + if (!ID_TO_NAME_MAP.containsKey(damage) || damage == 0) { + stack.setItemDamage(PIG_ID); + } + } + + public static synchronized void loadSpawners() { + if (loaded) return; + + for (Object entry : EntityList.IDtoClassMapping.entrySet()) { + Map.Entry> mapEntry = (Map.Entry>) entry; + Integer id = mapEntry.getKey(); + Class clazz = mapEntry.getValue(); + + if (EntityLiving.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { + String name = EntityList.getStringFromID(id); + if (name != null && !"EnderDragon".equals(name)) { + if ("Pig".equals(name)) { + // PIG_ID 已经在静态变量中设置 + } + ID_TO_NAME_MAP.put(id, name); } - return e; } } - try { - e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); - } catch (Throwable t) { - if (clazz == null) - NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); - else NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); - e = getEntity(idPig); - } - entityHashMap.put(ID, e); - } - return e; -} - - public static void clearEntityReferences() { - entityHashMap.clear(); - } - - private void setDefaultTag(ItemStack itemstack) { - if (!IDtoNameMap.containsKey(itemstack.getItemDamage())) itemstack.setItemDamage(idPig); - } - - public static void loadSpawners() { - if (loaded) return; loaded = true; - for (Map.Entry, String> entry : EntityList.classToStringMapping.entrySet()) { - final Class clazz = entry.getKey(); - if (EntityLiving.class.isAssignableFrom(clazz)) { - Integer id = (Integer) EntityList.classToIDMapping.get(clazz); - if (id == null) continue; - String name = entry.getValue(); - if (name == null) continue; - if (name.equals("EnderDragon")) continue; - if (name.equals("Pig")) idPig = id; - if (clazz != EntityPig.class || name.equals("Pig")) { - IDtoNameMap.put(id, name); + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List list) { + if (!NEIClientConfig.hasSMPCounterPart()) { + list.add(new ItemStack(item)); + } else { + for (int id : ID_TO_NAME_MAP.keySet()) { + if (id > 0) { // 跳过无效ID + list.add(new ItemStack(item, 1, id)); } } } } - - @Override - public void getSubItems(Item item, CreativeTabs tab, List list) { - if (!NEIClientConfig.hasSMPCounterPart()) list.add(new ItemStack(item)); - else for (int i : IDtoNameMap.keySet()) list.add(new ItemStack(item, 1, i)); - } } From 2a1aff073b19bcbf9629fad0c352de1cf2dfed25 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:39:49 +0800 Subject: [PATCH 04/11] Update ItemMobSpawner.java --- .../java/codechicken/nei/ItemMobSpawner.java | 176 ++++++++---------- 1 file changed, 81 insertions(+), 95 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index 551af24d..f38bda95 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -27,150 +27,136 @@ import cpw.mods.fml.relauncher.SideOnly; public class ItemMobSpawner extends ItemBlock { - private static final Map ENTITY_CACHE = new HashMap<>(); - private static final Map ID_TO_NAME_MAP = new HashMap<>(); - private static final int DEFAULT_ID_PIG = 90; // 猪的默认ID - public static final int PIG_ID = DEFAULT_ID_PIG; - private static boolean loaded = false; + private static final Map entityHashMap = new HashMap<>(); + private static final Map IDtoNameMap = new HashMap<>(); + public static int idPig; // 改回 public 静态变量,供 SpawnerRenderer 使用 + private static boolean loaded; public ItemMobSpawner() { super(Blocks.mob_spawner); - this.hasSubtypes = true; + hasSubtypes = true; MinecraftForgeClient.registerItemRenderer(this, new SpawnerRenderer()); } + /** + * These are ASM translated from BlockMobSpawner + */ public static int placedX; public static int placedY; public static int placedZ; @Override - public IIcon getIconFromDamage(int damage) { + public IIcon getIconFromDamage(int par1) { return Blocks.mob_spawner.getBlockTextureFromSide(0); } - @Override - public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, - int x, int y, int z, int side, - float hitX, float hitY, float hitZ) { - boolean result = super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ); - - if (result && world.isRemote) { - TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getTileEntity(placedX, placedY, placedZ); - if (spawner != null) { - ensureValidDamage(stack); - String mobType = ID_TO_NAME_MAP.get(stack.getItemDamage()); - if (mobType != null && spawner.func_145881_a() != null) { - // 发送数据包 - if (NEICPH.instance != null) { - NEICPH.instance.sendMobSpawnerID(placedX, placedY, placedZ, mobType); - } - spawner.func_145881_a().setEntityName(mobType); + public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, + float par8, float par9, float par10) { + if (super.onItemUse(itemstack, entityplayer, world, x, y, z, par7, par8, par9, par10) && world.isRemote) { + TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world + .getTileEntity(placedX, placedY, placedZ); + if (tileentitymobspawner != null) { + setDefaultTag(itemstack); + String mobtype = IDtoNameMap.get(itemstack.getItemDamage()); + if (mobtype != null) { + // 直接调用静态方法,而不是通过 instance + NEICPH.sendMobSpawnerID(placedX, placedY, placedZ, mobtype); + tileentitymobspawner.func_145881_a().setEntityName(mobtype); } } + return true; } - return result; + return false; } @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { - ensureValidDamage(stack); - int meta = stack.getItemDamage(); + public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) { + setDefaultTag(itemstack); + int meta = itemstack.getItemDamage(); if (meta == 0) { - meta = PIG_ID; + meta = idPig; } - - String mobName = ID_TO_NAME_MAP.get(meta); - if (mobName != null) { - Entity e = getEntity(meta); - EnumChatFormatting color = (e instanceof IMob) - ? EnumChatFormatting.DARK_RED - : EnumChatFormatting.DARK_AQUA; - tooltip.add(color + mobName); + Entity e = getEntity(meta); + if (e != null) { + list.add( + (e instanceof IMob ? EnumChatFormatting.DARK_RED : EnumChatFormatting.DARK_AQUA) + + IDtoNameMap.get(meta)); } } - public static EntityLiving getEntity(int id) { - EntityLiving entity = ENTITY_CACHE.get(id); - if (entity == null) { + public static EntityLiving getEntity(int ID) { + EntityLiving e = entityHashMap.get(ID); + if (e == null) { loadSpawners(); + Class clazz = (Class) EntityList.IDtoClassMapping.get(ID); + World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null; - Class entityClass = EntityList.getClassFromID(id); - if (entityClass == null) { - NEIClientConfig.logger.warn("Invalid entity ID: " + id); - return getEntity(PIG_ID); - } - - int modifiers = entityClass.getModifiers(); - if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { - NEIClientConfig.logger.warn("Skipping abstract entity class: " + entityClass.getName()); - entity = getEntity(PIG_ID); - ENTITY_CACHE.put(id, entity); - return entity; + if (clazz != null) { + int modifiers = clazz.getModifiers(); + if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { + NEIClientConfig.logger.warn("Skipping abstract entity class: " + clazz.getName()); + e = getEntity(idPig); + if (e != null) { + entityHashMap.put(ID, e); + } + return e; + } } try { - World world = NEIClientUtils.getClientWorld(); - if (world != null) { - entity = (EntityLiving) entityClass.getConstructor(World.class).newInstance(world); + if (clazz != null && world != null) { + e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); } else { - NEIClientConfig.logger.error("World is null, cannot create entity instance"); - return getEntity(PIG_ID); + // 如果无法创建实体,返回猪实体 + e = getEntity(idPig); } - } catch (Exception e) { - NEIClientConfig.logger.error("Error creating instance of entity: " + entityClass.getName(), e); - return getEntity(PIG_ID); + } catch (Throwable t) { + if (clazz == null) { + NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); + } else { + NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); + } + e = getEntity(idPig); + } + if (e != null) { + entityHashMap.put(ID, e); } - - ENTITY_CACHE.put(id, entity); } - return entity; + return e; } public static void clearEntityReferences() { - ENTITY_CACHE.clear(); + entityHashMap.clear(); } - private void ensureValidDamage(ItemStack stack) { - int damage = stack.getItemDamage(); - if (!ID_TO_NAME_MAP.containsKey(damage) || damage == 0) { - stack.setItemDamage(PIG_ID); - } + private void setDefaultTag(ItemStack itemstack) { + if (!IDtoNameMap.containsKey(itemstack.getItemDamage())) itemstack.setItemDamage(idPig); } - public static synchronized void loadSpawners() { + public static void loadSpawners() { if (loaded) return; - - for (Object entry : EntityList.IDtoClassMapping.entrySet()) { - Map.Entry> mapEntry = (Map.Entry>) entry; - Integer id = mapEntry.getKey(); - Class clazz = mapEntry.getValue(); - - if (EntityLiving.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { - String name = EntityList.getStringFromID(id); - if (name != null && !"EnderDragon".equals(name)) { - if ("Pig".equals(name)) { - // PIG_ID 已经在静态变量中设置 - } - ID_TO_NAME_MAP.put(id, name); + loaded = true; + for (Object entry : EntityList.classToStringMapping.entrySet()) { + Map.Entry, String> mapEntry = (Map.Entry, String>) entry; + final Class clazz = mapEntry.getKey(); + if (EntityLiving.class.isAssignableFrom(clazz)) { + Integer id = (Integer) EntityList.classToIDMapping.get(clazz); + if (id == null) continue; + String name = mapEntry.getValue(); + if (name == null) continue; + if (name.equals("EnderDragon")) continue; + if (name.equals("Pig")) idPig = id; + if (clazz != EntityPig.class || name.equals("Pig")) { + IDtoNameMap.put(id, name); } } } - - loaded = true; } @Override - @SideOnly(Side.CLIENT) public void getSubItems(Item item, CreativeTabs tab, List list) { - if (!NEIClientConfig.hasSMPCounterPart()) { - list.add(new ItemStack(item)); - } else { - for (int id : ID_TO_NAME_MAP.keySet()) { - if (id > 0) { // 跳过无效ID - list.add(new ItemStack(item, 1, id)); - } - } - } + if (!NEIClientConfig.hasSMPCounterPart()) list.add(new ItemStack(item)); + else for (int i : IDtoNameMap.keySet()) list.add(new ItemStack(item, 1, i)); } } From c533f6f1b565e4d65a09458d1c4d58927cd27a7f Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:51:51 +0800 Subject: [PATCH 05/11] Refactor ItemMobSpawner for thread safety and clarity --- .../java/codechicken/nei/ItemMobSpawner.java | 325 ++++++++++++------ 1 file changed, 225 insertions(+), 100 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index f38bda95..289b2ada 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -1,9 +1,12 @@ package codechicken.nei; import java.lang.reflect.Modifier; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; @@ -26,137 +29,259 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemMobSpawner extends ItemBlock { - - private static final Map entityHashMap = new HashMap<>(); - private static final Map IDtoNameMap = new HashMap<>(); - public static int idPig; // 改回 public 静态变量,供 SpawnerRenderer 使用 - private static boolean loaded; - + + private static final Map entityHashMap = + Collections.synchronizedMap(new WeakHashMap<>()); + private static final Map IDtoNameMap = + new ConcurrentHashMap<>(); + + public static int idPig = 90; + private static boolean loaded = false; + + private static final ThreadLocal placementContext = + ThreadLocal.withInitial(PlacementContext::new); + + private static class PlacementContext { + int x, y, z; + } + public ItemMobSpawner() { super(Blocks.mob_spawner); hasSubtypes = true; MinecraftForgeClient.registerItemRenderer(this, new SpawnerRenderer()); } - - /** - * These are ASM translated from BlockMobSpawner - */ - public static int placedX; - public static int placedY; - public static int placedZ; - + @Override - public IIcon getIconFromDamage(int par1) { + public IIcon getIconFromDamage(int meta) { return Blocks.mob_spawner.getBlockTextureFromSide(0); } - - public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int par7, - float par8, float par9, float par10) { - if (super.onItemUse(itemstack, entityplayer, world, x, y, z, par7, par8, par9, par10) && world.isRemote) { - TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world - .getTileEntity(placedX, placedY, placedZ); - if (tileentitymobspawner != null) { - setDefaultTag(itemstack); - String mobtype = IDtoNameMap.get(itemstack.getItemDamage()); - if (mobtype != null) { - // 直接调用静态方法,而不是通过 instance - NEICPH.sendMobSpawnerID(placedX, placedY, placedZ, mobtype); - tileentitymobspawner.func_145881_a().setEntityName(mobtype); + + public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, + int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + boolean placed = super.onItemUse(itemstack, entityplayer, world, x, y, z, side, hitX, hitY, hitZ); + + if (placed && world.isRemote) { + TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getTileEntity(x, y, z); + if (spawner != null) { + String mobType = getMobTypeFromItemStack(itemstack); + if (mobType != null) { + NEICPH.sendMobSpawnerID(x, y, z, mobType); + spawner.getSpawnerLogic().setEntityName(mobType); } } return true; } - return false; + return placed; } - + + private String getMobTypeFromItemStack(ItemStack stack) { + int meta = getValidMetaData(stack); + return IDtoNameMap.get(meta); + } + + private int getValidMetaData(ItemStack stack) { + int meta = stack.getItemDamage(); + if (meta == 0 || !IDtoNameMap.containsKey(meta)) { + return idPig; + } + return meta; + } + @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) { - setDefaultTag(itemstack); - int meta = itemstack.getItemDamage(); - if (meta == 0) { - meta = idPig; - } - Entity e = getEntity(meta); - if (e != null) { - list.add( - (e instanceof IMob ? EnumChatFormatting.DARK_RED : EnumChatFormatting.DARK_AQUA) - + IDtoNameMap.get(meta)); + public void addInformation(ItemStack itemstack, EntityPlayer player, + List tooltip, boolean advanced) { + int meta = getValidMetaData(itemstack); + EntityLiving entity = getEntity(meta); + String mobName = IDtoNameMap.get(meta); + + if (entity != null && mobName != null) { + EnumChatFormatting color = (entity instanceof IMob) + ? EnumChatFormatting.DARK_RED + : EnumChatFormatting.DARK_AQUA; + tooltip.add(color + mobName); } } - - public static EntityLiving getEntity(int ID) { - EntityLiving e = entityHashMap.get(ID); - if (e == null) { - loadSpawners(); - Class clazz = (Class) EntityList.IDtoClassMapping.get(ID); - World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null; + + public static EntityLiving getEntity(int id) { + EntityLiving cached = entityHashMap.get(id); + if (cached != null) { + return cached; + } + + loadSpawners(); + + Class entityClass = (Class) EntityList.IDtoClassMapping.get(id); + World world = NEIClientUtils.mc() != null + ? NEIClientUtils.mc().theWorld + : null; + + if (isInvalidEntityClass(entityClass)) { + return cacheFallback(id); + } + + EntityLiving entity = createEntityInstance(entityClass, world, id); + if (entity != null) { + entityHashMap.put(id, entity); + } + + return entity; + } + + private static boolean isInvalidEntityClass(Class entityClass) { + if (entityClass == null) { + return false; + } + + int modifiers = entityClass.getModifiers(); + if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { + NEIClientConfig.logger.warn( + "Skipping abstract entity class: " + entityClass.getName() + ); + return true; + } + + return false; + } + + private static EntityLiving createEntityInstance(Class entityClass, World world, int id) { + if (entityClass == null || world == null) { + return getFallbackEntity(id); + } + + try { + return (EntityLiving) entityClass + .getConstructor(World.class) + .newInstance(world); + } catch (Throwable t) { + logEntityCreationError(entityClass, id, t); + return getFallbackEntity(id); + } + } + + private static void logEntityCreationError(Class entityClass, int id, Throwable t) { + if (entityClass == null) { + NEIClientConfig.logger.error( + "Null class for entity (ID: {}, Name: {})", + id, IDtoNameMap.getOrDefault(id, "unknown") + ); + } else { + NEIClientConfig.logger.error( + "Error creating instance of entity: " + entityClass.getName(), t + ); + } + } + + private static EntityLiving cacheFallback(int id) { + EntityLiving fallback = getFallbackEntity(id); + if (fallback != null) { + entityHashMap.put(id, fallback); + } + return fallback; + } + + private static EntityLiving getFallbackEntity(int originalId) { + EntityLiving pig = entityHashMap.get(idPig); + if (pig == null) { + World world = NEIClientUtils.mc() != null + ? NEIClientUtils.mc().theWorld + : null; - if (clazz != null) { - int modifiers = clazz.getModifiers(); - if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { - NEIClientConfig.logger.warn("Skipping abstract entity class: " + clazz.getName()); - e = getEntity(idPig); - if (e != null) { - entityHashMap.put(ID, e); - } - return e; + if (world != null) { + try { + pig = new EntityPig(world); + entityHashMap.put(idPig, pig); + } catch (Exception e) { + NEIClientConfig.logger.error( + "Failed to create fallback pig entity", e + ); } } - - try { - if (clazz != null && world != null) { - e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); - } else { - // 如果无法创建实体,返回猪实体 - e = getEntity(idPig); - } - } catch (Throwable t) { - if (clazz == null) { - NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); - } else { - NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); - } - e = getEntity(idPig); - } - if (e != null) { - entityHashMap.put(ID, e); - } } - return e; + + if (pig == null && originalId != idPig) { + NEIClientConfig.logger.warn( + "Using null fallback for entity ID: {}, original fallback ID: {}", + originalId, idPig + ); + } + + return pig; } - + public static void clearEntityReferences() { entityHashMap.clear(); } - - private void setDefaultTag(ItemStack itemstack) { - if (!IDtoNameMap.containsKey(itemstack.getItemDamage())) itemstack.setItemDamage(idPig); - } - + public static void loadSpawners() { - if (loaded) return; - loaded = true; - for (Object entry : EntityList.classToStringMapping.entrySet()) { - Map.Entry, String> mapEntry = (Map.Entry, String>) entry; - final Class clazz = mapEntry.getKey(); - if (EntityLiving.class.isAssignableFrom(clazz)) { - Integer id = (Integer) EntityList.classToIDMapping.get(clazz); - if (id == null) continue; - String name = mapEntry.getValue(); - if (name == null) continue; - if (name.equals("EnderDragon")) continue; - if (name.equals("Pig")) idPig = id; - if (clazz != EntityPig.class || name.equals("Pig")) { - IDtoNameMap.put(id, name); + if (loaded) { + return; + } + + synchronized (ItemMobSpawner.class) { + if (loaded) { + return; + } + + try { + for (Object entry : EntityList.classToStringMapping.entrySet()) { + Map.Entry, String> mapEntry = + (Map.Entry, String>) entry; + + Class clazz = mapEntry.getKey(); + String name = mapEntry.getValue(); + + if (shouldRegisterEntity(clazz, name)) { + Integer id = (Integer) EntityList.classToIDMapping.get(clazz); + if (id != null) { + IDtoNameMap.put(id, name); + if ("Pig".equals(name)) { + idPig = id; + } + } + } } + loaded = true; + } catch (Exception e) { + NEIClientConfig.logger.error("Error loading spawners", e); } } } - + + private static boolean shouldRegisterEntity(Class clazz, String name) { + if (clazz == null || name == null) { + return false; + } + + if (!EntityLiving.class.isAssignableFrom(clazz)) { + return false; + } + + if ("EnderDragon".equals(name)) { + return false; + } + + return true; + } + @Override public void getSubItems(Item item, CreativeTabs tab, List list) { - if (!NEIClientConfig.hasSMPCounterPart()) list.add(new ItemStack(item)); - else for (int i : IDtoNameMap.keySet()) list.add(new ItemStack(item, 1, i)); + if (!NEIClientConfig.hasSMPCounterPart()) { + list.add(new ItemStack(item)); + } else { + for (int id : IDtoNameMap.keySet()) { + list.add(new ItemStack(item, 1, id)); + } + } + } + + public static String getEntityNameForMeta(int meta) { + loadSpawners(); + return IDtoNameMap.getOrDefault(meta, IDtoNameMap.getOrDefault(idPig, "Pig")); + } + + public static boolean isValidEntityMeta(int meta) { + loadSpawners(); + return IDtoNameMap.containsKey(meta) || meta == 0; } } From e0b34e8b9a864407520379dc88895aa27d2e10f1 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:58:06 +0800 Subject: [PATCH 06/11] Update method call for setting entity name in spawner --- src/main/java/codechicken/nei/ItemMobSpawner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index 289b2ada..08481713 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -66,7 +66,7 @@ public class ItemMobSpawner extends ItemBlock { String mobType = getMobTypeFromItemStack(itemstack); if (mobType != null) { NEICPH.sendMobSpawnerID(x, y, z, mobType); - spawner.getSpawnerLogic().setEntityName(mobType); + spawner.func_145881_a().setEntityName(mobType); } } return true; From 41a6cc071113c6a82d47ebcf51b1ea479383a8cf Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:27:17 +0800 Subject: [PATCH 07/11] Update build-and-test.yml --- .github/workflows/build-and-test.yml | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 3ee2f686..bff9a446 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,13 +1,23 @@ - -name: Build and test - -on: - pull_request: - branches: [ master, main ] - push: - branches: [ master, main ] +name: Fix Spotless Formatting +on: + workflow_dispatch: # 允许手动触发 jobs: - build-and-test: - uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master - secrets: inherit + spotless-fix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '8' + - name: Run spotlessApply + run: ./gradlew spotlessApply + - name: Commit changes + run: | + git config --global user.name 'GitHub Action' + git config --global user.email 'action@github.com' + git add -A + git commit -m 'Apply spotless formatting' || exit 0 + git push From b9cac67ec7c83fd645a1910583407092995d99b2 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:40:05 +0800 Subject: [PATCH 08/11] Update GitHub Actions workflow for release builds --- .github/workflows/build-and-test.yml | 76 +++++++++++++++++++++------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index bff9a446..f6775bfe 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,23 +1,61 @@ -name: Fix Spotless Formatting -on: - workflow_dispatch: # 允许手动触发 +name: Release tagged build + +on: + workflow_dispatch: + push: + tags: [ '*' ] + +permissions: + contents: write jobs: - spotless-fix: + spotless-format: runs-on: ubuntu-latest + outputs: + formatted: ${{ steps.spotless.outputs.formatted }} steps: - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '8' - - name: Run spotlessApply - run: ./gradlew spotlessApply - - name: Commit changes - run: | - git config --global user.name 'GitHub Action' - git config --global user.email 'action@github.com' - git add -A - git commit -m 'Apply spotless formatting' || exit 0 - git push + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Run spotlessApply + id: spotless + run: | + chmod +x gradlew || true + ./gradlew spotlessApply || true + + # 检查是否有文件被格式化 + if [ -n "$(git status --porcelain)" ]; then + echo "Files were formatted by spotless" + echo "formatted=true" >> $GITHUB_OUTPUT + + # 配置 git + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + # 提交格式化更改 + git add . + git commit -m "Apply spotless formatting [skip ci]" + + # 更新 tag 指向新的提交 + # 获取当前 tag + TAG_NAME=${GITHUB_REF#refs/tags/} + git tag -f "${TAG_NAME}" + git push origin "${TAG_NAME}" --force + else + echo "No files needed formatting" + echo "formatted=false" >> $GITHUB_OUTPUT + fi + + release-tags: + needs: spotless-format + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master + secrets: inherit From 80f7455e7fb7614a52111157a51042a7f068e5ef Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:44:05 +0800 Subject: [PATCH 09/11] Refactor spotless-format job and git tagging Removed output for formatted files in spotless-format job and adjusted git tag handling. --- .github/workflows/build-and-test.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f6775bfe..31c88e6f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -11,8 +11,6 @@ permissions: jobs: spotless-format: runs-on: ubuntu-latest - outputs: - formatted: ${{ steps.spotless.outputs.formatted }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -27,7 +25,6 @@ jobs: java-version: '17' - name: Run spotlessApply - id: spotless run: | chmod +x gradlew || true ./gradlew spotlessApply || true @@ -35,7 +32,6 @@ jobs: # 检查是否有文件被格式化 if [ -n "$(git status --porcelain)" ]; then echo "Files were formatted by spotless" - echo "formatted=true" >> $GITHUB_OUTPUT # 配置 git git config --local user.email "github-actions[bot]@users.noreply.github.com" @@ -48,11 +44,19 @@ jobs: # 更新 tag 指向新的提交 # 获取当前 tag TAG_NAME=${GITHUB_REF#refs/tags/} - git tag -f "${TAG_NAME}" + + # 删除旧的标签(本地和远程) + git tag -d "${TAG_NAME}" || true + git push --delete origin "${TAG_NAME}" || true + + # 创建新的标签指向当前提交 + git tag "${TAG_NAME}" + + # 推送更改和标签 + git push origin HEAD:${GITHUB_REF_NAME} --force git push origin "${TAG_NAME}" --force else echo "No files needed formatting" - echo "formatted=false" >> $GITHUB_OUTPUT fi release-tags: From fa4411ad2e313ec8dd5296d2c8eab9a818539627 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 27 Jan 2026 20:46:02 +0000 Subject: [PATCH 10/11] Apply spotless formatting [skip ci] --- .../java/codechicken/nei/ItemMobSpawner.java | 149 ++++++++---------- 1 file changed, 64 insertions(+), 85 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index 08481713..d0d7d72e 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -2,7 +2,6 @@ package codechicken.nei; import java.lang.reflect.Modifier; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -29,37 +28,36 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemMobSpawner extends ItemBlock { - - private static final Map entityHashMap = - Collections.synchronizedMap(new WeakHashMap<>()); - private static final Map IDtoNameMap = - new ConcurrentHashMap<>(); - - public static int idPig = 90; + + private static final Map entityHashMap = Collections.synchronizedMap(new WeakHashMap<>()); + private static final Map IDtoNameMap = new ConcurrentHashMap<>(); + + public static int idPig = 90; private static boolean loaded = false; - - private static final ThreadLocal placementContext = - ThreadLocal.withInitial(PlacementContext::new); - + + private static final ThreadLocal placementContext = ThreadLocal + .withInitial(PlacementContext::new); + private static class PlacementContext { + int x, y, z; } - + public ItemMobSpawner() { super(Blocks.mob_spawner); hasSubtypes = true; MinecraftForgeClient.registerItemRenderer(this, new SpawnerRenderer()); } - + @Override public IIcon getIconFromDamage(int meta) { return Blocks.mob_spawner.getBlockTextureFromSide(0); } - - public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, - int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + + public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side, + float hitX, float hitY, float hitZ) { boolean placed = super.onItemUse(itemstack, entityplayer, world, x, y, z, side, hitX, hitY, hitZ); - + if (placed && world.isRemote) { TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getTileEntity(x, y, z); if (spawner != null) { @@ -73,12 +71,12 @@ public class ItemMobSpawner extends ItemBlock { } return placed; } - + private String getMobTypeFromItemStack(ItemStack stack) { int meta = getValidMetaData(stack); return IDtoNameMap.get(meta); } - + private int getValidMetaData(ItemStack stack) { int meta = stack.getItemDamage(); if (meta == 0 || !IDtoNameMap.containsKey(meta)) { @@ -86,92 +84,80 @@ public class ItemMobSpawner extends ItemBlock { } return meta; } - + @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack itemstack, EntityPlayer player, - List tooltip, boolean advanced) { + public void addInformation(ItemStack itemstack, EntityPlayer player, List tooltip, boolean advanced) { int meta = getValidMetaData(itemstack); EntityLiving entity = getEntity(meta); String mobName = IDtoNameMap.get(meta); - + if (entity != null && mobName != null) { - EnumChatFormatting color = (entity instanceof IMob) - ? EnumChatFormatting.DARK_RED - : EnumChatFormatting.DARK_AQUA; + EnumChatFormatting color = (entity instanceof IMob) ? EnumChatFormatting.DARK_RED + : EnumChatFormatting.DARK_AQUA; tooltip.add(color + mobName); } } - + public static EntityLiving getEntity(int id) { EntityLiving cached = entityHashMap.get(id); if (cached != null) { return cached; } - + loadSpawners(); - + Class entityClass = (Class) EntityList.IDtoClassMapping.get(id); - World world = NEIClientUtils.mc() != null - ? NEIClientUtils.mc().theWorld - : null; - + World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null; + if (isInvalidEntityClass(entityClass)) { return cacheFallback(id); } - + EntityLiving entity = createEntityInstance(entityClass, world, id); if (entity != null) { entityHashMap.put(id, entity); } - + return entity; } - + private static boolean isInvalidEntityClass(Class entityClass) { if (entityClass == null) { return false; } - + int modifiers = entityClass.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { - NEIClientConfig.logger.warn( - "Skipping abstract entity class: " + entityClass.getName() - ); + NEIClientConfig.logger.warn("Skipping abstract entity class: " + entityClass.getName()); return true; } - + return false; } - + private static EntityLiving createEntityInstance(Class entityClass, World world, int id) { if (entityClass == null || world == null) { return getFallbackEntity(id); } - + try { - return (EntityLiving) entityClass - .getConstructor(World.class) - .newInstance(world); + return (EntityLiving) entityClass.getConstructor(World.class).newInstance(world); } catch (Throwable t) { logEntityCreationError(entityClass, id, t); return getFallbackEntity(id); } } - + private static void logEntityCreationError(Class entityClass, int id, Throwable t) { if (entityClass == null) { - NEIClientConfig.logger.error( - "Null class for entity (ID: {}, Name: {})", - id, IDtoNameMap.getOrDefault(id, "unknown") - ); + NEIClientConfig.logger + .error("Null class for entity (ID: {}, Name: {})", id, IDtoNameMap.getOrDefault(id, "unknown")); } else { - NEIClientConfig.logger.error( - "Error creating instance of entity: " + entityClass.getName(), t - ); + NEIClientConfig.logger.error("Error creating instance of entity: " + entityClass.getName(), t); } } - + private static EntityLiving cacheFallback(int id) { EntityLiving fallback = getFallbackEntity(id); if (fallback != null) { @@ -179,58 +165,51 @@ public class ItemMobSpawner extends ItemBlock { } return fallback; } - + private static EntityLiving getFallbackEntity(int originalId) { EntityLiving pig = entityHashMap.get(idPig); if (pig == null) { - World world = NEIClientUtils.mc() != null - ? NEIClientUtils.mc().theWorld - : null; - + World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null; + if (world != null) { try { pig = new EntityPig(world); entityHashMap.put(idPig, pig); } catch (Exception e) { - NEIClientConfig.logger.error( - "Failed to create fallback pig entity", e - ); + NEIClientConfig.logger.error("Failed to create fallback pig entity", e); } } } - + if (pig == null && originalId != idPig) { - NEIClientConfig.logger.warn( - "Using null fallback for entity ID: {}, original fallback ID: {}", - originalId, idPig - ); + NEIClientConfig.logger + .warn("Using null fallback for entity ID: {}, original fallback ID: {}", originalId, idPig); } - + return pig; } - + public static void clearEntityReferences() { entityHashMap.clear(); } - + public static void loadSpawners() { if (loaded) { return; } - + synchronized (ItemMobSpawner.class) { if (loaded) { return; } - + try { for (Object entry : EntityList.classToStringMapping.entrySet()) { - Map.Entry, String> mapEntry = - (Map.Entry, String>) entry; - + Map.Entry, String> mapEntry = (Map.Entry, String>) entry; + Class clazz = mapEntry.getKey(); String name = mapEntry.getValue(); - + if (shouldRegisterEntity(clazz, name)) { Integer id = (Integer) EntityList.classToIDMapping.get(clazz); if (id != null) { @@ -247,23 +226,23 @@ public class ItemMobSpawner extends ItemBlock { } } } - + private static boolean shouldRegisterEntity(Class clazz, String name) { if (clazz == null || name == null) { return false; } - + if (!EntityLiving.class.isAssignableFrom(clazz)) { return false; } - + if ("EnderDragon".equals(name)) { return false; } - + return true; } - + @Override public void getSubItems(Item item, CreativeTabs tab, List list) { if (!NEIClientConfig.hasSMPCounterPart()) { @@ -274,12 +253,12 @@ public class ItemMobSpawner extends ItemBlock { } } } - + public static String getEntityNameForMeta(int meta) { loadSpawners(); return IDtoNameMap.getOrDefault(meta, IDtoNameMap.getOrDefault(idPig, "Pig")); } - + public static boolean isValidEntityMeta(int meta) { loadSpawners(); return IDtoNameMap.containsKey(meta) || meta == 0; From 1db5809cde7fdace8649c02976d0553cfd139e9b Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:48:32 +0800 Subject: [PATCH 11/11] Update build-and-test.yml --- .github/workflows/build-and-test.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 31c88e6f..c9c49153 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -41,20 +41,25 @@ jobs: git add . git commit -m "Apply spotless formatting [skip ci]" - # 更新 tag 指向新的提交 - # 获取当前 tag + # 获取当前 tag 名称 TAG_NAME=${GITHUB_REF#refs/tags/} + echo "Current tag: $TAG_NAME" + + # 检查并处理可能的引用冲突 + # 删除本地同名的分支引用(如果存在) + git show-ref --verify --quiet refs/heads/"${TAG_NAME}" && git branch -D "${TAG_NAME}" || true # 删除旧的标签(本地和远程) - git tag -d "${TAG_NAME}" || true - git push --delete origin "${TAG_NAME}" || true + git tag -d "${TAG_NAME}" 2>/dev/null || true + git push --delete origin "refs/tags/${TAG_NAME}" 2>/dev/null || true # 创建新的标签指向当前提交 - git tag "${TAG_NAME}" + git tag -f "${TAG_NAME}" - # 推送更改和标签 - git push origin HEAD:${GITHUB_REF_NAME} --force - git push origin "${TAG_NAME}" --force + # 只推送标签,不推送分支引用 + git push origin "refs/tags/${TAG_NAME}" --force + + echo "Spotless formatting applied and tag updated successfully" else echo "No files needed formatting" fi