From e6f97784ff68fd64e599b9e4f993676d64116625 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 29 Dec 2021 16:22:05 -0600 Subject: [PATCH] Added get/setRotationType to ScriptNpc. Added get/setMotion for x, y, z components to ScriptEntity. Fixed an NPC wand crash. --- src/main/java/noppes/npcs/DataScript.java | 7 +-- .../npcs/controllers/ScriptController.java | 10 +--- .../npcs/scripted/entity/ScriptEntity.java | 51 +++++++++++++++++-- .../npcs/scripted/entity/ScriptNpc.java | 16 ++++-- .../scripted/roles/ScriptJobFollower.java | 2 +- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 9 +--- 6 files changed, 68 insertions(+), 27 deletions(-) diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/DataScript.java index 6b6bcfdef..d4074bda2 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/DataScript.java @@ -23,6 +23,7 @@ import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.ICustomNpc; import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; @@ -36,7 +37,7 @@ public class DataScript implements IScriptHandler { private EntityNPCInterface npc; public boolean enabled = false; - public ScriptNpc dummyNpc; + public ICustomNpc dummyNpc; public IWorld dummyWorld; public boolean clientNeedsUpdate = false; public boolean aiNeedsUpdate = false; @@ -48,8 +49,8 @@ public class DataScript implements IScriptHandler { } this.npc = npc; - if(npc instanceof EntityCustomNpc) - dummyNpc = new ScriptNpc((EntityCustomNpc) npc); + dummyNpc = new ScriptNpc<>(npc); + if(npc.worldObj instanceof WorldServer) dummyWorld = NpcAPI.Instance().getIWorld((WorldServer) npc.worldObj);//new ScriptWorld((WorldServer) npc.worldObj); } diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 83415bd1a..e27828a06 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -31,13 +31,7 @@ import noppes.npcs.LogWriter; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.entity.ScriptAnimal; -import noppes.npcs.scripted.entity.ScriptEntity; -import noppes.npcs.scripted.entity.ScriptLiving; -import noppes.npcs.scripted.entity.ScriptLivingBase; -import noppes.npcs.scripted.entity.ScriptMonster; -import noppes.npcs.scripted.entity.ScriptPixelmon; -import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.entity.*; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.util.JsonException; import noppes.npcs.util.NBTJsonUtil; @@ -256,7 +250,7 @@ public class ScriptController { if(entity == null) return null; if(entity instanceof EntityNPCInterface) - return ((EntityNPCInterface) entity).script.dummyNpc; + return (ScriptNpc)((EntityNPCInterface) entity).script.dummyNpc; else{ ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject"); if(data != null) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index b5a77d44e..8454d9894 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -101,7 +101,7 @@ public class ScriptEntity implements IEntity { * @param x The entities x position */ public void setX(double x){ - entity.posX = x; + entity.setPosition(x, entity.posY, entity.posZ);; } /** @@ -115,7 +115,7 @@ public class ScriptEntity implements IEntity { * @param y The entities y position */ public void setY(double y){ - entity.posY = y; + entity.setPosition(entity.posX, y, entity.posZ); } /** @@ -129,7 +129,52 @@ public class ScriptEntity implements IEntity { * @param z The entities x position */ public void setZ(double z){ - entity.posZ = z; + entity.setPosition(entity.posX, entity.posY, z);; + } + + /** + * @return The entities z motion + */ + public double getMotionX(){ + return entity.motionX; + } + + /** + * @param x The entities x motion + */ + public void setMotionX(double x){ + entity.motionX = x; + entity.velocityChanged = true; + } + + /** + * @return The entities x motion + */ + public double getMotionY(){ + return entity.motionY; + } + + /** + * @param y The entities y motion + */ + public void setMotionY(double y){ + entity.motionY = y; + entity.velocityChanged = true; + } + + /** + * @return The entities y motion + */ + public double getMotionZ(){ + return entity.motionZ; + } + + /** + * @param z The entities z motion + */ + public void setMotionZ(double z){ + entity.motionZ = z; + entity.velocityChanged = true; } /** diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 9b7cc2dd8..135293909 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -2,10 +2,7 @@ package noppes.npcs.scripted.entity; import net.minecraft.item.ItemStack; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.constants.EnumAnimation; -import noppes.npcs.constants.EnumJobType; -import noppes.npcs.constants.EnumNavType; -import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.constants.*; import noppes.npcs.controllers.Line; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -90,6 +87,17 @@ public class ScriptNpc extends ScriptLiving imp npc.ai.orientation = (int)rotation; super.setRotation(rotation); } + public void setRotationType(int rotationType){ + for (EnumStandingType e : EnumStandingType.values()) { + if (e.ordinal() == rotationType) { + npc.ai.standingType = e; + break; + } + } + } + public int getRotationType(){ + return npc.ai.standingType.ordinal(); + } /** * @param name The name of the npc */ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java index c2ddd5d82..610ef99e3 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java @@ -23,7 +23,7 @@ public class ScriptJobFollower extends ScriptJobInterface{ public ScriptNpc getFollowingNpc(){ if(!isFollowing()) return null; - return job.following.script.dummyNpc; + return (ScriptNpc)job.following.script.dummyNpc; } public boolean isFollowing(){ diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 9bdfe6d21..e6833c195 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -59,17 +59,10 @@ public class WrapperNpcAPI extends NpcAPI { } public IEntity getIEntity(Entity entity) { - /* - if (entity != null && !entity.worldObj.isRemote) { - return (entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : entity instanceof EntityPlayerMP ? getIPlayer((EntityPlayerMP) entity) : WrapperEntityData.get(entity)); - } else { - return null; - } - */ if(entity == null) return null; if(entity instanceof EntityNPCInterface) - return ((EntityNPCInterface) entity).script.dummyNpc; + return ((EntityNPCInterface)entity).wrappedNPC; else{ ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject"); if(data != null)