From 9b764fa5684f210c4f13068aec0e6974401885fb Mon Sep 17 00:00:00 2001 From: zeng-github01 <95841646+zeng-github01@users.noreply.github.com> Date: Thu, 2 Apr 2026 16:31:08 +0800 Subject: [PATCH] Fixes JobSpawner for legacy npc --- .../noppes/npcs/VersionCompatibility.java | 85 ++++++++++++++++++- .../npcs/client/renderer/RenderCustomNpc.java | 11 ++- .../noppes/npcs/entity/EntityCustomNpc.java | 9 ++ .../java/noppes/npcs/roles/JobSpawner.java | 2 + src/main/java/zengyj/ModelType.java | 33 +++++++ 5 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 src/main/java/zengyj/ModelType.java diff --git a/src/main/java/noppes/npcs/VersionCompatibility.java b/src/main/java/noppes/npcs/VersionCompatibility.java index 98dd6c20e..3b329379c 100644 --- a/src/main/java/noppes/npcs/VersionCompatibility.java +++ b/src/main/java/noppes/npcs/VersionCompatibility.java @@ -1,9 +1,9 @@ package noppes.npcs; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagInt; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.*; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; +import noppes.npcs.constants.EnumPotionType; import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Lines; import noppes.npcs.entity.EntityNPCInterface; @@ -49,6 +49,23 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound if (compound.hasKey("DialogDarkenScreen")) { compound.removeTag("DialogDarkenScreen"); } + + if (compound.hasKey("FiringDelay") && compound.hasKey("DelayVariance")) { + int min = compound.getInteger("FiringDelay"); + int max = compound.getInteger("DelayVariance"); + compound.setInteger("minDelay", min); + compound.setInteger("maxDelay", max); + compound.removeTag("FiringDelay"); + compound.removeTag("DelayVariance"); + } + + if (compound.hasKey("pEffect")) { + int effect = compound.getInteger("pEffect"); + EnumPotionType enumPotionType = EnumPotionType.fromOrdinal(effect); + if (enumPotionType == EnumPotionType.Fire) { + compound.setBoolean("pBurnItem", true); + } + } } if (npc.npcVersion < 12) { CompatabilityFix(compound, npc.advanced.writeToNBT(new NBTTagCompound())); @@ -110,6 +127,56 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound compound.setIntArray("StartPosNew", new int[]{x, y, z}); } + + NBTTagList movingPathLegacy = compound.getTagList("MovingPath", Constants.NBT.TAG_LIST); + + if (movingPathLegacy.tagCount() > 0) { + NBTTagList MovingPathNew = new NBTTagList(); + + for (int i = movingPathLegacy.tagCount() - 1; i >= 0; i--) { + NBTTagList array = (NBTTagList) movingPathLegacy.removeTag(i); + + if (array.tagCount() == 3) { + int x = array.getCompoundTagAt(0).getInteger("Slot"); + int y = array.getCompoundTagAt(1).getInteger("Slot"); + int z = array.getCompoundTagAt(2).getInteger("Slot"); + + NBTTagCompound pathPoint = new NBTTagCompound(); + pathPoint.setIntArray("Array", new int[]{x, y, z}); + + MovingPathNew.appendTag(pathPoint); + } + } + + NBTTagList finalList = new NBTTagList(); + for (int i = MovingPathNew.tagCount() - 1; i >= 0; i--) { + finalList.appendTag(MovingPathNew.getCompoundTagAt(i)); + } + + compound.setTag("MovingPathNew", finalList); + } + + if (compound.hasKey("NpcJob")) { + int npcJob = compound.getInteger("NpcJob"); + if (npcJob == 5) { + compound.setByte("BossBar", (byte) 1); + compound.setInteger("NpcJob", 0); + } + } + + if (compound.hasKey("SkinColor")) { + int skinColor = compound.getInteger("SkinColor"); + if (skinColor != 16777215) { + compound.setBoolean("TintEnabled", true); + compound.setInteger("GeneralTint", skinColor); + compound.setInteger("GeneralAlpha", 100); + compound.setBoolean("GeneralTintEnabled", true); + } + } + + if (!compound.getString("GlowTexture").isEmpty() && compound.getInteger("NpcVisible") == 1) { + compound.setInteger("NpcVisible", 2); + } } if (npc.npcVersion == 13) { boolean bo = compound.getBoolean("HealthRegen"); @@ -123,6 +190,16 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound npc.npcVersion = ModRev; } + public static void CheckSpawnerCompatibility(NBTTagCompound compound, int x, int y, int z, World world) { + for (int i = 1; i <= 6; i++) { + NBTTagCompound tag = compound.getCompoundTag("SpawnerNBT" + i); + if (tag.hasNoTags() || tag.getInteger("ModRev") == ModRev) continue; + + tag.setString("id", "customnpcs.CustomNpc"); + compound.setTag("SpawnerNBT" + i, tag); + } + } + public static void CheckModelCompatibility(EntityNPCInterface npc, NBTTagCompound compound) { if (npc.npcVersion == ModRev) return; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index a2be8c19c..a181ac118 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -2,6 +2,7 @@ import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.entity.NPCRendererHelper; +import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RendererLivingEntity; import net.minecraft.entity.EntityList; @@ -35,8 +36,14 @@ public void renderPlayer(EntityNPCInterface npcInterface, double d, double d1, d ModelBase model = null; renderEntity = null; if (entity != null) { - renderEntity = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); - model = NPCRendererHelper.getMainModel(renderEntity); + Render render = RenderManager.instance.getEntityRenderObject(entity); + if (render instanceof RendererLivingEntity) { + renderEntity = (RendererLivingEntity) render; + model = NPCRendererHelper.getMainModel(renderEntity); + } else { + renderEntity = null; + model = null; + } if (PixelmonHelper.isPixelmon(entity)) { try { Class c = Class.forName("com.pixelmonmod.pixelmon.entities.pixelmon.Entity2HasModel"); diff --git a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java index e1ff3544d..1998072e8 100644 --- a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java +++ b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java @@ -1,6 +1,7 @@ package noppes.npcs.entity; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -9,6 +10,7 @@ import noppes.npcs.client.EntityUtil; import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.data.ModelPartData; +import zengyj.ModelType; public class EntityCustomNpc extends EntityNPCFlying { public ModelData modelData = new ModelData(); @@ -25,6 +27,13 @@ public void readEntityFromNBT(NBTTagCompound compound) { VersionCompatibility.CheckModelCompatibility(this, compound); modelData.readFromNBT(compound.getCompoundTag("NpcModelData")); } + + //Fix Entity Class for Legacy Npc + if (compound.hasKey("ModelType")) { + int modelType = compound.getInteger("ModelType"); + Class clazz = (Class) EntityList.stringToClassMapping.get(ModelType.values()[modelType].entityName); + modelData.setEntityClass(clazz); + } } @Override diff --git a/src/main/java/noppes/npcs/roles/JobSpawner.java b/src/main/java/noppes/npcs/roles/JobSpawner.java index 11e71bc20..b0c2198b9 100644 --- a/src/main/java/noppes/npcs/roles/JobSpawner.java +++ b/src/main/java/noppes/npcs/roles/JobSpawner.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.VersionCompatibility; import noppes.npcs.compat.PixelmonHelper; import noppes.npcs.entity.EntityNPCInterface; import org.apache.commons.lang3.RandomStringUtils; @@ -100,6 +101,7 @@ private void saveCompound(NBTTagCompound save, String name, NBTTagCompound compo @Override public void readFromNBT(NBTTagCompound compound) { + VersionCompatibility.CheckSpawnerCompatibility(compound, MathHelper.floor_double(npc.posX), MathHelper.floor_double(npc.posY), MathHelper.floor_double(npc.posZ), npc.worldObj); compound1 = compound.getCompoundTag("SpawnerNBT1"); compound2 = compound.getCompoundTag("SpawnerNBT2"); compound3 = compound.getCompoundTag("SpawnerNBT3"); diff --git a/src/main/java/zengyj/ModelType.java b/src/main/java/zengyj/ModelType.java new file mode 100644 index 000000000..18faf542c --- /dev/null +++ b/src/main/java/zengyj/ModelType.java @@ -0,0 +1,33 @@ +package zengyj; + +public enum ModelType { + HumanMale("npchumanmale"), + Villager("npcvillager"), + Pony("npcpony"), + HumanFemale("npchumanfemale"), + DwarfMale("npcdwarfmale"), + FurryMale("npcfurrymale"), + MonsterMale("npczombiemale"), + MonsterFemale("npczombiefemale"), + Skeleton("npcskeleton"), + DwarfFemale("npcdwarffemale"), + FurryFemale("npcfurryfemale"), + OrcMale("npcorcfmale"), + OrcFemale("npcorcfemale"), + ElfMale("npcelfmale"), + ElfFemale("npcelffemale"), + Crystal("npccrystal"), + Golem("npcGolem"), + EnderChibi("npcenderchibi"), + EnderMan("npcEnderman"), + NagaMale("npcnagamale"), + NagaFemale("npcnagafemale"), + Slime("NpcSlime"), + Dragon("NpcDragon"); + + public String entityName; + + private ModelType(String entityName) { + this.entityName = entityName; + } +}