Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 81 additions & 4 deletions src/main/java/noppes/npcs/VersionCompatibility.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/noppes/npcs/entity/EntityCustomNpc.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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<? extends EntityLivingBase> clazz = (Class<? extends EntityLivingBase>) EntityList.stringToClassMapping.get(ModelType.values()[modelType].entityName);
modelData.setEntityClass(clazz);
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/noppes/npcs/roles/JobSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/zengyj/ModelType.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading