mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 11:29:05 +00:00
Implement IVillager Scripting (removed duplicate entity variable)
This commit is contained in:
1 parent
6f5fd25a24
commit
4a58702d16
7 files changed
+88
-35
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -8,10 +8,8 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> implements IEntityLiving {
|
||||
|
||||
private T entity;
|
||||
public ScriptLiving(T entity) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +31,7 @@ public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> 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<T extends EntityLiving> extends ScriptLivingBase<T> 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());
|
||||
|
||||
@@ -20,11 +20,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
|
||||
protected T entity;
|
||||
|
||||
public ScriptLivingBase(T entity){
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<T extends EntityTameable> extends ScriptAnimal<T> implements IPixelmon {
|
||||
@@ -19,25 +20,25 @@ public class ScriptPixelmon<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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<T extends EntityTameable> extends ScriptAnimal<T> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<T extends EntityVillager> extends ScriptLiving<T> 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user