Skip to content

Commit 9b764fa

Browse files
committed
Fixes JobSpawner for legacy npc
1 parent b2c279f commit 9b764fa

5 files changed

Lines changed: 134 additions & 6 deletions

File tree

src/main/java/noppes/npcs/VersionCompatibility.java

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package noppes.npcs;
22

3-
import net.minecraft.nbt.NBTBase;
4-
import net.minecraft.nbt.NBTTagCompound;
5-
import net.minecraft.nbt.NBTTagInt;
6-
import net.minecraft.nbt.NBTTagList;
3+
import net.minecraft.nbt.*;
4+
import net.minecraft.world.World;
5+
import net.minecraftforge.common.util.Constants;
6+
import noppes.npcs.constants.EnumPotionType;
77
import noppes.npcs.controllers.data.Line;
88
import noppes.npcs.controllers.data.Lines;
99
import noppes.npcs.entity.EntityNPCInterface;
@@ -49,6 +49,23 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound
4949
if (compound.hasKey("DialogDarkenScreen")) {
5050
compound.removeTag("DialogDarkenScreen");
5151
}
52+
53+
if (compound.hasKey("FiringDelay") && compound.hasKey("DelayVariance")) {
54+
int min = compound.getInteger("FiringDelay");
55+
int max = compound.getInteger("DelayVariance");
56+
compound.setInteger("minDelay", min);
57+
compound.setInteger("maxDelay", max);
58+
compound.removeTag("FiringDelay");
59+
compound.removeTag("DelayVariance");
60+
}
61+
62+
if (compound.hasKey("pEffect")) {
63+
int effect = compound.getInteger("pEffect");
64+
EnumPotionType enumPotionType = EnumPotionType.fromOrdinal(effect);
65+
if (enumPotionType == EnumPotionType.Fire) {
66+
compound.setBoolean("pBurnItem", true);
67+
}
68+
}
5269
}
5370
if (npc.npcVersion < 12) {
5471
CompatabilityFix(compound, npc.advanced.writeToNBT(new NBTTagCompound()));
@@ -110,6 +127,56 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound
110127

111128
compound.setIntArray("StartPosNew", new int[]{x, y, z});
112129
}
130+
131+
NBTTagList movingPathLegacy = compound.getTagList("MovingPath", Constants.NBT.TAG_LIST);
132+
133+
if (movingPathLegacy.tagCount() > 0) {
134+
NBTTagList MovingPathNew = new NBTTagList();
135+
136+
for (int i = movingPathLegacy.tagCount() - 1; i >= 0; i--) {
137+
NBTTagList array = (NBTTagList) movingPathLegacy.removeTag(i);
138+
139+
if (array.tagCount() == 3) {
140+
int x = array.getCompoundTagAt(0).getInteger("Slot");
141+
int y = array.getCompoundTagAt(1).getInteger("Slot");
142+
int z = array.getCompoundTagAt(2).getInteger("Slot");
143+
144+
NBTTagCompound pathPoint = new NBTTagCompound();
145+
pathPoint.setIntArray("Array", new int[]{x, y, z});
146+
147+
MovingPathNew.appendTag(pathPoint);
148+
}
149+
}
150+
151+
NBTTagList finalList = new NBTTagList();
152+
for (int i = MovingPathNew.tagCount() - 1; i >= 0; i--) {
153+
finalList.appendTag(MovingPathNew.getCompoundTagAt(i));
154+
}
155+
156+
compound.setTag("MovingPathNew", finalList);
157+
}
158+
159+
if (compound.hasKey("NpcJob")) {
160+
int npcJob = compound.getInteger("NpcJob");
161+
if (npcJob == 5) {
162+
compound.setByte("BossBar", (byte) 1);
163+
compound.setInteger("NpcJob", 0);
164+
}
165+
}
166+
167+
if (compound.hasKey("SkinColor")) {
168+
int skinColor = compound.getInteger("SkinColor");
169+
if (skinColor != 16777215) {
170+
compound.setBoolean("TintEnabled", true);
171+
compound.setInteger("GeneralTint", skinColor);
172+
compound.setInteger("GeneralAlpha", 100);
173+
compound.setBoolean("GeneralTintEnabled", true);
174+
}
175+
}
176+
177+
if (!compound.getString("GlowTexture").isEmpty() && compound.getInteger("NpcVisible") == 1) {
178+
compound.setInteger("NpcVisible", 2);
179+
}
113180
}
114181
if (npc.npcVersion == 13) {
115182
boolean bo = compound.getBoolean("HealthRegen");
@@ -123,6 +190,16 @@ public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound
123190
npc.npcVersion = ModRev;
124191
}
125192

193+
public static void CheckSpawnerCompatibility(NBTTagCompound compound, int x, int y, int z, World world) {
194+
for (int i = 1; i <= 6; i++) {
195+
NBTTagCompound tag = compound.getCompoundTag("SpawnerNBT" + i);
196+
if (tag.hasNoTags() || tag.getInteger("ModRev") == ModRev) continue;
197+
198+
tag.setString("id", "customnpcs.CustomNpc");
199+
compound.setTag("SpawnerNBT" + i, tag);
200+
}
201+
}
202+
126203
public static void CheckModelCompatibility(EntityNPCInterface npc, NBTTagCompound compound) {
127204
if (npc.npcVersion == ModRev)
128205
return;

src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.client.model.ModelBase;
44
import net.minecraft.client.renderer.entity.NPCRendererHelper;
5+
import net.minecraft.client.renderer.entity.Render;
56
import net.minecraft.client.renderer.entity.RenderManager;
67
import net.minecraft.client.renderer.entity.RendererLivingEntity;
78
import net.minecraft.entity.EntityList;
@@ -35,8 +36,14 @@ public void renderPlayer(EntityNPCInterface npcInterface, double d, double d1, d
3536
ModelBase model = null;
3637
renderEntity = null;
3738
if (entity != null) {
38-
renderEntity = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity);
39-
model = NPCRendererHelper.getMainModel(renderEntity);
39+
Render render = RenderManager.instance.getEntityRenderObject(entity);
40+
if (render instanceof RendererLivingEntity) {
41+
renderEntity = (RendererLivingEntity) render;
42+
model = NPCRendererHelper.getMainModel(renderEntity);
43+
} else {
44+
renderEntity = null;
45+
model = null;
46+
}
4047
if (PixelmonHelper.isPixelmon(entity)) {
4148
try {
4249
Class c = Class.forName("com.pixelmonmod.pixelmon.entities.pixelmon.Entity2HasModel");

src/main/java/noppes/npcs/entity/EntityCustomNpc.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package noppes.npcs.entity;
22

33
import net.minecraft.entity.Entity;
4+
import net.minecraft.entity.EntityList;
45
import net.minecraft.entity.EntityLivingBase;
56
import net.minecraft.nbt.NBTTagCompound;
67
import net.minecraft.world.World;
@@ -9,6 +10,7 @@
910
import noppes.npcs.client.EntityUtil;
1011
import noppes.npcs.entity.data.ModelData;
1112
import noppes.npcs.entity.data.ModelPartData;
13+
import zengyj.ModelType;
1214

1315
public class EntityCustomNpc extends EntityNPCFlying {
1416
public ModelData modelData = new ModelData();
@@ -25,6 +27,13 @@ public void readEntityFromNBT(NBTTagCompound compound) {
2527
VersionCompatibility.CheckModelCompatibility(this, compound);
2628
modelData.readFromNBT(compound.getCompoundTag("NpcModelData"));
2729
}
30+
31+
//Fix Entity Class for Legacy Npc
32+
if (compound.hasKey("ModelType")) {
33+
int modelType = compound.getInteger("ModelType");
34+
Class<? extends EntityLivingBase> clazz = (Class<? extends EntityLivingBase>) EntityList.stringToClassMapping.get(ModelType.values()[modelType].entityName);
35+
modelData.setEntityClass(clazz);
36+
}
2837
}
2938

3039
@Override

src/main/java/noppes/npcs/roles/JobSpawner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.nbt.NBTTagCompound;
88
import net.minecraft.util.MathHelper;
99
import noppes.npcs.NoppesUtilServer;
10+
import noppes.npcs.VersionCompatibility;
1011
import noppes.npcs.compat.PixelmonHelper;
1112
import noppes.npcs.entity.EntityNPCInterface;
1213
import org.apache.commons.lang3.RandomStringUtils;
@@ -100,6 +101,7 @@ private void saveCompound(NBTTagCompound save, String name, NBTTagCompound compo
100101

101102
@Override
102103
public void readFromNBT(NBTTagCompound compound) {
104+
VersionCompatibility.CheckSpawnerCompatibility(compound, MathHelper.floor_double(npc.posX), MathHelper.floor_double(npc.posY), MathHelper.floor_double(npc.posZ), npc.worldObj);
103105
compound1 = compound.getCompoundTag("SpawnerNBT1");
104106
compound2 = compound.getCompoundTag("SpawnerNBT2");
105107
compound3 = compound.getCompoundTag("SpawnerNBT3");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package zengyj;
2+
3+
public enum ModelType {
4+
HumanMale("npchumanmale"),
5+
Villager("npcvillager"),
6+
Pony("npcpony"),
7+
HumanFemale("npchumanfemale"),
8+
DwarfMale("npcdwarfmale"),
9+
FurryMale("npcfurrymale"),
10+
MonsterMale("npczombiemale"),
11+
MonsterFemale("npczombiefemale"),
12+
Skeleton("npcskeleton"),
13+
DwarfFemale("npcdwarffemale"),
14+
FurryFemale("npcfurryfemale"),
15+
OrcMale("npcorcfmale"),
16+
OrcFemale("npcorcfemale"),
17+
ElfMale("npcelfmale"),
18+
ElfFemale("npcelffemale"),
19+
Crystal("npccrystal"),
20+
Golem("npcGolem"),
21+
EnderChibi("npcenderchibi"),
22+
EnderMan("npcEnderman"),
23+
NagaMale("npcnagamale"),
24+
NagaFemale("npcnagafemale"),
25+
Slime("NpcSlime"),
26+
Dragon("NpcDragon");
27+
28+
public String entityName;
29+
30+
private ModelType(String entityName) {
31+
this.entityName = entityName;
32+
}
33+
}

0 commit comments

Comments
 (0)