From 4a58702d1659bcbcb34c542ee1912e747356c89a Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 21:08:48 -0500 Subject: [PATCH] Implement IVillager Scripting (removed duplicate entity variable) --- src/api | 2 +- .../java/noppes/npcs/scripted/NpcAPI.java | 3 + .../npcs/scripted/constants/EntityType.java | 2 + .../npcs/scripted/entity/ScriptLiving.java | 10 ++- .../scripted/entity/ScriptLivingBase.java | 2 - .../npcs/scripted/entity/ScriptPixelmon.java | 63 +++++++++++-------- .../npcs/scripted/entity/ScriptVillager.java | 41 ++++++++++++ 7 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java diff --git a/src/api b/src/api index a520cc647..d497bb704 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a520cc647078e32ba2659e6400d86e95e62036dd +Subproject commit d497bb7045d9bcd1f40e24de8c2fd7ec98cd84ec diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 968e68543..4fe5f5150 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -13,6 +13,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.inventory.Container; @@ -200,6 +201,8 @@ public class NpcAPI extends AbstractNpcAPI { data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity)); else if(entity instanceof EntityMob) data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity)); + else if(entity instanceof EntityVillager) + data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity)); else if(entity instanceof EntityLiving) data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity)); else if(entity instanceof EntityLivingBase) diff --git a/src/main/java/noppes/npcs/scripted/constants/EntityType.java b/src/main/java/noppes/npcs/scripted/constants/EntityType.java index 4bd9cdfd5..76c21de71 100644 --- a/src/main/java/noppes/npcs/scripted/constants/EntityType.java +++ b/src/main/java/noppes/npcs/scripted/constants/EntityType.java @@ -9,4 +9,6 @@ public class EntityType { public static final int LIVING = 5; public static final int ITEM = 6; public static final int PROJECTILE = 7; + public static final int PIXELMON = 8; + public static final int VILLAGER = 9; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java index cb198413a..828803ed0 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java @@ -8,10 +8,8 @@ import noppes.npcs.scripted.NpcAPI; public class ScriptLiving extends ScriptLivingBase implements IEntityLiving { - private T entity; public ScriptLiving(T entity) { super(entity); - this.entity = entity; } @Override @@ -33,7 +31,7 @@ public class ScriptLiving extends ScriptLivingBase im IEntityLivingBase base = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity.getAttackTarget()); return (base != null)? base: super.getAttackTarget(); } - + /** * Start path finding toward this target * @param x Destination x position @@ -44,21 +42,21 @@ public class ScriptLiving extends ScriptLivingBase im public void navigateTo(double x, double y, double z, double speed){ entity.getNavigator().tryMoveToXYZ(x, y, z, speed); } - + /** * Stop navigating wherever this npc was walking to */ public void clearNavigation(){ entity.getNavigator().clearPathEntity(); } - + /** * @return Whether or not this entity is navigating somewhere */ public boolean isNavigating(){ return !entity.getNavigator().noPath(); } - + @Override public boolean canSeeEntity(IEntity entity){ return this.entity.getEntitySenses().canSee(entity.getMCEntity()); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 2c45b58eb..33e38d308 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -20,11 +20,9 @@ import java.util.ArrayList; import java.util.Collections; public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { - protected T entity; public ScriptLivingBase(T entity){ super(entity); - this.entity = entity; } /** diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java index 7bc01d080..702b9ad45 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java @@ -4,6 +4,7 @@ import net.minecraft.entity.passive.EntityTameable; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.api.entity.IPixelmon; import noppes.npcs.compat.PixelmonHelper; +import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; public class ScriptPixelmon extends ScriptAnimal implements IPixelmon { @@ -19,25 +20,25 @@ public class ScriptPixelmon extends ScriptAnimal im this(pixelmon); this.compound = compound; } - + public boolean getIsShiny(){ return compound.getBoolean("IsShiny"); } - + public void setIsShiny(boolean bo){ compound.setBoolean("IsShiny", bo); pixelmon.readEntityFromNBT(compound); } - + public int getLevel(){ return compound.getInteger("Level"); } - + public void setLevel(int level){ compound.setInteger("Level", level); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -54,11 +55,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("IVSpDef"); if(type == 5) return compound.getInteger("IVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -77,7 +78,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("IVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -94,11 +95,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("EVSpecialDefence"); if(type == 5) return compound.getInteger("EVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -117,7 +118,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("EVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -134,11 +135,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("StatsSpecialDefence"); if(type == 5) return compound.getInteger("StatsSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -157,14 +158,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("StatsSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ public int getSize(){ return compound.getShort("Growth"); } - + /** * @param type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ @@ -172,14 +173,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Growth", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0-255 */ public int getHapiness(){ return compound.getInteger("Friendship"); } - + /** * @param value 0-255 */ @@ -188,14 +189,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("Friendship", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ public int getNature(){ return compound.getShort("Nature"); } - + /** * @param type 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ @@ -203,7 +204,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Nature", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return -1:Uncaught, 0:Pokeball, 1:GreatBall, 2:UltraBall, 3:MasterBall, 4:LevelBall, 5:MoonBall, 6:FriendBall, 7:LoveBall, 8:SafariBall, 9:HeavyBall, 10:FastBall, 11:RepeatBall, 12:TimerBall, 13:NestBall, 14:NetBall, 15:DiveBall, 16:LuxuryBall, 17:HealBall, 18:DuskBall, 19:PremierBall, 20:SportBall, 21:QuickBall, 22:ParkBall, 23:LureBall, 24:CherishBall, 25:GSBall */ @@ -220,26 +221,26 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("CaughtBall", type); pixelmon.readEntityFromNBT(compound); } - + public String getNickname(){ return compound.getString("Nickname"); } - + public boolean hasNickname(){ return !getNickname().isEmpty(); } - + public void setNickname(String name){ compound.setString("Nickname", name); pixelmon.readEntityFromNBT(compound); } - + public String getMove(int slot){ if(!compound.hasKey("PixelmonMoveID" + slot)) return null; return PixelmonHelper.getAttackName(compound.getInteger("PixelmonMoveID" + slot)); } - + public void setMove(int slot, String move){ slot = ValueUtil.clamp(slot, 0, 3); int id = PixelmonHelper.getAttackID(move); @@ -257,7 +258,17 @@ public class ScriptPixelmon extends ScriptAnimal im size++; } compound.setInteger("PixelmonNumberMoves", size); - + pixelmon.readEntityFromNBT(compound); } + + @Override + public int getType(){ + return EntityType.PIXELMON; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.PIXELMON || super.typeOf(type); + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java new file mode 100644 index 000000000..cc3804651 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java @@ -0,0 +1,41 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.passive.EntityVillager; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.entity.IVillager; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.constants.EntityType; + +public class ScriptVillager extends ScriptLiving implements IVillager { + + public ScriptVillager(T entity) { + super(entity); + } + + @Override + public int getProfession() { + return entity.getProfession(); + } + + @Override + public boolean getIsTrading() { + return entity.isTrading(); + } + + @Override + public IEntityLivingBase getCustomer() + { + return (IEntityLivingBase) NpcAPI.Instance().getPlayer(entity.getCustomer().getCommandSenderName()); + } + + @Override + public int getType(){ + return EntityType.VILLAGER; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.VILLAGER || super.typeOf(type); + } + +}