Implemented global Forge events. Reorganized NPC API files.

This commit is contained in:
luisc committed 2021-10-18 06:33:39 -05:00
1 parent c5ed7497c8
commit 72f2c3c60a
72 files changed
+321 -395

No files matched your search

@@ -0,0 +1,22 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.passive.EntityAnimal;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IAnimal;
public class ScriptAnimal<T extends EntityAnimal> extends ScriptLiving<T> implements IAnimal {
public ScriptAnimal(T entity) {
super(entity);
}
@Override
public int getType(){
return EntityType.ANIMAL;
}
@Override
public boolean typeOf(int type){
return type == EntityType.ANIMAL?true:super.typeOf(type);
}
}
@@ -0,0 +1,498 @@
package noppes.npcs.scripted.entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptEntityParticle;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.INbt;
public class ScriptEntity<T extends Entity> implements IEntity {
protected T entity;
private Map<String,Object> tempData = new HashMap<String,Object>();
public ScriptEntity(T entity){
this.entity = entity;
}
/**
* @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png"
* @param HEXcolor The particle's color as a HEX integer
* @param amount The amount of particles to spawn
* @param maxAge The particle's maximum age in MC ticks
* @param x The particle's x position
* @param y The particle's y position
* @param z The particle's z position
* @param motionX The particle's speed in the x axis
* @param motionY The particle's speed in the y axis
* @param motionZ The particle's speed in the z axis
* @param gravity The particle's gravity
* @param scale1 The particle's starting scale
* @param scale2 The particle's ending scale
* @param scaleRate Multiplier for the particle's scale growth rate
* @param scaleRateStart The time at which the particle begins growing/shrinking
* @param alpha1 The particle's starting transparency
* @param alpha2 The particle's ending transparency
* @param scaleRate Multiplier for the particle's transparency growth rate
* @param alphaRateStart The time at which the particle begins appearing/fading
*/
public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge,
double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart,
float alpha1, float alpha2, float alphaRate, int alphaRateStart
) {
int entityID = entity.getEntityId();
NoppesUtilServer.spawnScriptedParticle(entity, directory, HEXcolor, amount, maxAge,
x, y, z,
motionX, motionY, motionZ, gravity,
scale1, scale2, scaleRate, scaleRateStart,
alpha1, alpha2, alphaRate, alphaRateStart,
entityID
);
}
public void spawnParticle(ScriptEntityParticle entityParticle) { entityParticle.spawnOnEntity(this); }
public double getYOffset() { return entity.getYOffset(); }
/**
* @return The entities width
*/
public double getWidth(){ return entity.width; }
/**
* @return The entities height
*/
public double getHeight(){ return entity.height; }
/**
* @return The entities x position
*/
public double getX(){
return entity.posX;
}
/**
* @param x The entities x position
*/
public void setX(double x){
entity.posX = x;
}
/**
* @return The entities y position
*/
public double getY(){
return entity.posY;
}
/**
* @param y The entities y position
*/
public void setY(double y){
entity.posY = y;
}
/**
* @return The entities x position
*/
public double getZ(){
return entity.posZ;
}
/**
* @param z The entities x position
*/
public void setZ(double z){
entity.posZ = z;
}
/**
* @return The block x position
*/
public int getBlockX(){
return MathHelper.floor_double(entity.posX);
}
/**
* @return The block y position
*/
public int getBlockY(){
return MathHelper.floor_double(entity.posY);
}
/**
* @return The block z position
*/
public int getBlockZ(){
return MathHelper.floor_double(entity.posZ);
}
/**
* @param x The x position
* @param y The y position
* @param z The z position
*/
public void setPosition(double x, double y, double z){
entity.setPosition(x, y, z);
}
/**
* @param range The search range for entities around this entity
* @return Array of entities within range
*/
public ScriptEntity[] getSurroundingEntities(int range){
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(Entity.class, entity.boundingBox.expand(range, range, range));
List<ScriptEntity> list = new ArrayList<ScriptEntity>();
for(Entity living : entities){
if(living != entity)
list.add(ScriptController.Instance.getScriptForEntity(living));
}
return list.toArray(new ScriptEntity[list.size()]);
}
/**
* @param range The search range for entities around this entity
* @param type The EntityType you want to find
* @return Array of entities within range
*/
public ScriptEntity[] getSurroundingEntities(int range, int type){
Class cls = Entity.class;
if(type == EntityType.LIVING)
cls = EntityLivingBase.class;
else if(type == EntityType.PLAYER)
cls = EntityPlayer.class;
else if(type == EntityType.ANIMAL)
cls = EntityAnimal.class;
else if(type == EntityType.MONSTER)
cls = EntityMob.class;
else if(type == EntityType.NPC)
cls = EntityNPCInterface.class;
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
List<ScriptEntity> list = new ArrayList<ScriptEntity>();
for(Entity living : entities){
if(living != entity)
list.add(ScriptController.Instance.getScriptForEntity(living));
}
return list.toArray(new ScriptEntity[list.size()]);
}
/**
* @return Whether the entity is alive or not
*/
public boolean isAlive(){
return entity.isEntityAlive();
}
/**
* @param key Get temp data for this key
* @return Returns the stored temp data
*/
public Object getTempData(String key){
return tempData.get(key);
}
/**
* Tempdata gets cleared when the entity gets unloaded or the world restarts
* @param key The key for the data stored
* @param value The data stored
*/
public void setTempData(String key, Object value){
tempData.put(key, value);
}
/**
* @param key The key thats going to be tested against the temp data
* @return Whether or not temp data containes the key
*/
public boolean hasTempData(String key){
return tempData.containsKey(key);
}
/**
* @param key The key for the temp data to be removed
*/
public void removeTempData(String key){
tempData.remove(key);
}
/**
* Remove all tempdata
*/
public void clearTempData(){
tempData.clear();
}
/**
* @param key The key of the data to be returned
* @return Returns the stored data
*/
public Object getStoredData(String key){
NBTTagCompound compound = getStoredCompound();
if(!compound.hasKey(key))
return null;
NBTBase base = compound.getTag(key);
if(base instanceof NBTPrimitive)
return ((NBTPrimitive)base).func_150286_g();
return ((NBTTagString)base).func_150285_a_();
}
/**
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
* @param key The key for the data stored
* @param value The data stored. This data can be either a Number or a String. Other data is not stored
*/
public void setStoredData(String key, Object value){
NBTTagCompound compound = getStoredCompound();
if(value instanceof Number){
compound.setDouble(key, ((Number) value).doubleValue());
}
else if(value instanceof String)
compound.setString(key, (String)value);
saveStoredCompound(compound);
}
/**
* @param key The key of the data to be checked
* @return Returns whether or not the stored data contains the key
*/
public boolean hasStoredData(String key){
return getStoredCompound().hasKey(key);
}
/**
* @param key The key of the data to be removed
*/
public void removeStoredData(String key){
NBTTagCompound compound = getStoredCompound();
compound.removeTag(key);
saveStoredCompound(compound);
}
/**
* Remove all stored data
*/
public void clearStoredData(){
entity.getEntityData().removeTag("CNPCStoredData");
}
private NBTTagCompound getStoredCompound(){
NBTTagCompound compound = entity.getEntityData().getCompoundTag("CNPCStoredData");
if(compound == null)
entity.getEntityData().setTag("CNPCStoredData", compound = new NBTTagCompound());
return compound;
}
private void saveStoredCompound(NBTTagCompound compound){
entity.getEntityData().setTag("CNPCStoredData", compound);
}
/**
* @return The age of this entity in ticks
*/
public long getAge(){
return entity.ticksExisted;
}
/**
* Despawns this entity. Removes it permanently
*/
public void despawn(){
entity.isDead = true;
}
/**
* @return Return whether or not this entity is standing in water
*/
public boolean inWater(){
return entity.isInsideOfMaterial(Material.water);
}
/**
* @return Return whether or not this entity is standing in lava
*/
public boolean inLava(){
return entity.isInsideOfMaterial(Material.lava);
}
/**
* @return Return whether or not this entity is standing in fire
*/
public boolean inFire(){
return entity.isInsideOfMaterial(Material.fire);
}
/**
* @return Return whether or not this entity is on fire
*/
public boolean isBurning(){
return entity.isBurning();
}
/**
* @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second
*/
public void setBurning(int ticks){
entity.setFire(ticks);
}
/**
* Removes fire from this entity
*/
public void extinguish(){
entity.extinguish();
}
/**
* @return Name as which it's registered in minecraft
*/
public String getTypeName(){
return EntityList.getEntityString(entity);
}
/**
* @param item Item to be dropped
*/
public void dropItem(ScriptItemStack item){
entity.entityDropItem(item.item, 0);
}
/**
* @return Return the rider
*/
public ScriptEntity getRider(){
return ScriptController.Instance.getScriptForEntity(entity.riddenByEntity);
}
/**
* @param entity The entity to ride this entity
*/
public void setRider(ScriptEntity entity){
if(entity != null){
entity.entity.mountEntity(this.entity);;
}
else if(this.entity.riddenByEntity != null)
this.entity.riddenByEntity.mountEntity(null);
}
/**
* @return Return the entity, this entity is riding
*/
public ScriptEntity getMount(){
return ScriptController.Instance.getScriptForEntity(entity.ridingEntity);
}
/**
* @param entity The entity this entity will mount
*/
public void setMount(ScriptEntity entity){
if(entity == null)
this.entity.mountEntity(null);
else
this.entity.mountEntity(entity.entity);
}
/**
* @see noppes.npcs.scripted.constants.EntityType
* @return Returns the EntityType of this entity
*/
public int getType(){
return EntityType.UNKNOWN;
}
/**
* @since 1.7.10c
* @param type @EntityType to check
* @return Returns whether the entity is type of the given @EntityType
*/
public boolean typeOf(int type){
return type == EntityType.UNKNOWN;
}
/**
* @param rotation The rotation to be set (0-360)
*/
public void setRotation(float rotation){
entity.rotationYaw = rotation;
}
/**
* @return Current rotation of the npc
*/
public float getRotation(){
return entity.rotationYaw;
}
/**
* @param power How strong the knockback is
* @param direction The direction in which he flies back (0-360). Usually based on getRotation()
*/
public void knockback(int power, float direction){
float v = direction * (float)Math.PI / 180.0F;
entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power);
entity.motionX *= 0.6D;
entity.motionZ *= 0.6D;
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
}
/**
* @since 1.7.10c
* @return Returns whether or not this entity is sneaking
*/
public boolean isSneaking(){
return entity.isSneaking();
}
/**
* @since 1.7.10c
* @return Returns whether or not this entity is sprinting
*/
public boolean isSprinting(){
return entity.isSprinting();
}
/**
* @since 1.7.10c
* Expert users only
* @return Returns minecrafts entity
*/
public T getMCEntity(){
return entity;
}
public INbt getNbt() {
return NpcAPI.Instance().getINbt(this.entity.getEntityData());
}
public void setNbt(INbt nbt) {
this.entity.readFromNBT(nbt.getMCNBT());
}
}
@@ -0,0 +1,64 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.EntityLiving;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.interfaces.IEntityLiving;
public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> implements IEntityLiving {
private T entity;
public ScriptLiving(T entity) {
super(entity);
this.entity = entity;
}
@Override
public boolean isAttacking(){
return super.isAttacking() || entity.getAttackTarget() != null;
}
@Override
public void setAttackTarget(ScriptLivingBase living){
if(living == null)
entity.setAttackTarget(null);
else
entity.setAttackTarget(living.entity);
super.setAttackTarget(living);
}
@Override
public ScriptLivingBase getAttackTarget(){
ScriptLivingBase base = (ScriptLivingBase)ScriptController.Instance.getScriptForEntity(entity.getAttackTarget());
return (base != null)? base: super.getAttackTarget();
}
/**
* Start path finding toward this target
* @param x Destination x position
* @param y Destination x position
* @param z Destination x position
* @param speed Walking speed of the entity 0.7 is default
*/
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(ScriptEntity entity){
return this.entity.getEntitySenses().canSee(entity.entity);
}
}
@@ -0,0 +1,189 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntityLivingBase;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
protected T entity;
public ScriptLivingBase(T entity){
super(entity);
this.entity = entity;
}
/**
* @return The entity's current health
*/
public float getHealth(){
return entity.getHealth();
}
/**
* @param health The new health of this entity
*/
public void setHealth(float health){
entity.setHealth(health);
}
/**
* @return Entity's max health
*/
public float getMaxHealth(){
return entity.getMaxHealth();
}
/**
* @return Whether or not this entity is attacking something
*/
public boolean isAttacking(){
return entity.getAITarget() != null;
}
/**
* @param living Entity which this entity will attack
*/
public void setAttackTarget(ScriptLivingBase living){
if(living == null)
entity.setRevengeTarget(null);
else
entity.setRevengeTarget(living.entity);
}
/**
* @return The entity which this entity is attacking
*/
public ScriptLivingBase getAttackTarget(){
return (ScriptLivingBase)ScriptController.Instance.getScriptForEntity(entity.getAITarget());
}
@Override
public int getType(){
return EntityType.LIVING;
}
@Override
public boolean typeOf(int type){
return type == EntityType.LIVING?true:super.typeOf(type);
}
/**
* @param entity Entity to check
* @return Whether or not this entity can see the given entity
*/
public boolean canSeeEntity(ScriptEntity entity){
return this.entity.canEntityBeSeen(entity.entity);
}
/**
* Expert use only
* @return Returns the minecraft entity object
*/
public T getMCEntity(){
return entity;
}
/**
* Makes the entity swing its hand
*/
public void swingHand(){
entity.swingItem();
}
/**
* Works the same as the <a href="http://minecraft.gamepedia.com/Commands#effect">/effect command</a>
* @param effect
* @param duration The duration in seconds
* @param strength The amplifier of the potion effect
* @param hideParticles Whether or not you want to hide potion particles
*/
public void addPotionEffect(int effect, int duration, int strength, boolean hideParticles){
if (effect < 0 || effect >= Potion.potionTypes.length || Potion.potionTypes[effect] == null)
return;
if(strength < 0)
strength = 0;
else if(strength > 255)
strength = 255;
if(duration < 0)
duration = 0;
else if(duration > 1000000)
duration = 1000000;
if(!Potion.potionTypes[effect].isInstant())
duration *= 20;
if(duration == 0)
entity.removePotionEffect(effect);
else
entity.addPotionEffect(new PotionEffect(effect, duration, strength));
//TODO in 1.8 add hideParticles option
}
/**
* Clears all potion effects
*/
public void clearPotionEffects(){
entity.clearActivePotions();
}
/**
* @since 1.7.10c
* @param effect Potion effect to check
* @return Returns -1 if its not active. Otherwise returns the strenght of the potion
*/
public int getPotionEffect(int effect){
PotionEffect pf = entity.getActivePotionEffect(Potion.potionTypes[effect]);
if(pf == null)
return -1;
return pf.getAmplifier();
}
/**
* Note not all Living Entities support this
* @since 1.7.10c
* @return The item the entity is holding
*/
public ScriptItemStack getHeldItem(){
ItemStack item = entity.getHeldItem();
if(item == null)
return null;
return new ScriptItemStack(item);
}
/**
* Note not all Living Entities support this
* @since 1.7.10c
* @param item The item to be set
*/
public void setHeldItem(ScriptItemStack item){
entity.setCurrentItemOrArmor(0, item == null?null:item.item);
}
/**
* Note not all Living Entities support this
* @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head
* @return The item in the given slot
*/
public ScriptItemStack getArmor(int slot){
ItemStack item = entity.getEquipmentInSlot(slot + 1);
if(item == null)
return null;
return new ScriptItemStack(item);
}
/**
* Note not all Living Entities support this
* @since 1.7.10c
* @param slot Slot of what armor piece to set, 0:boots, 1:pants, 2:body, 3:head
* @param item Item to be set
*/
public void setArmor(int slot, ScriptItemStack item){
entity.setCurrentItemOrArmor(slot + 1, item == null?null:item.item);
}
}
@@ -0,0 +1,23 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.monster.EntityMob;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IMonster;
public class ScriptMonster<T extends EntityMob> extends ScriptLiving<T> implements IMonster {
public ScriptMonster(T entity) {
super(entity);
}
@Override
public int getType(){
return EntityType.MONSTER;
}
@Override
public boolean typeOf(int type){
return type == EntityType.MONSTER?true:super.typeOf(type);
}
}
@@ -0,0 +1,681 @@
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.EnumRoleType;
import noppes.npcs.controllers.Line;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.ScriptFaction;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.constants.AnimationType;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.ICustomNpc;
import noppes.npcs.scripted.roles.ScriptJobBard;
import noppes.npcs.scripted.roles.ScriptJobConversation;
import noppes.npcs.scripted.roles.ScriptJobFollower;
import noppes.npcs.scripted.roles.ScriptJobGuard;
import noppes.npcs.scripted.roles.ScriptJobHealer;
import noppes.npcs.scripted.roles.ScriptJobInterface;
import noppes.npcs.scripted.roles.ScriptJobItemGiver;
import noppes.npcs.scripted.roles.ScriptJobPuppet;
import noppes.npcs.scripted.roles.ScriptJobSpawner;
import noppes.npcs.scripted.roles.ScriptRoleBank;
import noppes.npcs.scripted.roles.ScriptRoleFollower;
import noppes.npcs.scripted.roles.ScriptRoleInterface;
import noppes.npcs.scripted.roles.ScriptRoleMailman;
import noppes.npcs.scripted.roles.ScriptRoleTrader;
import noppes.npcs.scripted.roles.ScriptRoleTransporter;
import noppes.npcs.util.ValueUtil;
public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> implements ICustomNpc {
protected EntityCustomNpc npc;
public ScriptNpc(T npc){
super(npc);
this.npc = (EntityCustomNpc)npc;
}
/**
* @return Returns the current npcs size 1-30
*/
public int getSize(){
return npc.display.modelSize;
}
/**
* @param size The size of the npc (1-30) default is 5
*/
public void setSize(int size){
if(size > 30)
size = 30;
else if(size < 1)
size = 1;
npc.display.modelSize = size;
npc.script.clientNeedsUpdate = true;
}
/**
* @return Returns the current npcs modelType of the NPC
*/
public int getModelType(){
return npc.display.modelType;
}
/**
* @param modelType The modelType of the NPC. 0: Steve, 1: Steve64, 2: Alex
*/
public void setModelType(int modelType){
if(modelType > 2)
modelType = 2;
else if(modelType < 0)
modelType = 0;
npc.display.modelType = modelType;
npc.script.clientNeedsUpdate = true;
}
/**
* @return The npcs name
*/
public String getName(){
return npc.display.name;
}
public void setRotation(float rotation){
npc.ai.orientation = (int)rotation;
super.setRotation(rotation);
}
/**
* @param name The name of the npc
*/
public void setName(String name){
npc.display.name = name;
npc.script.clientNeedsUpdate = true;
}
/**
* @since 1.7.10
* @return The npcs title
*/
public String getTitle(){
return npc.display.title;
}
/**
* @since 1.7.10
* @param title The title of the npc
*/
public void setTitle(String title){
npc.display.title = title;
npc.script.clientNeedsUpdate = true;
}
/**
* @return The npcs texture
*/
public String getTexture(){
return npc.display.texture;
}
/**
* @param texture The texture of the npc
*/
public void setTexture(String texture){
npc.display.texture = texture;
npc.script.clientNeedsUpdate = true;
}
/**
* @return Home position x
*/
public int getHomeX(){
return npc.getStartPos()[0];
}
/**
* @param x The home x position
*/
public void setHomeX(int x){
npc.ai.startPos[0] = x;
}
/**
* @return Home position x
*/
public int getHomeY(){
return npc.getStartPos()[1];
}
/**
* @param y The home y position
*/
public void setHomeY(int y){
npc.ai.startPos[1] = y;
}
/**
* @return Home position x
*/
public int getHomeZ(){
return npc.getStartPos()[2];
}
/**
* @param z The home x position
*/
public void setHomeZ(int z){
npc.ai.startPos[2] = z;
}
/**
* @param x The home x position
* @param y The home y position
* @param z The home z position
*/
public void setHome(int x, int y, int z){
npc.ai.startPos = new int[]{x, y, z};
}
/**
* @param health New max health
*/
public void setMaxHealth(int health){
npc.stats.setMaxHealth(health);
npc.script.clientNeedsUpdate = true;
}
/**
* @param bo Whether or not the npc will try to return to his home position
*/
public void setReturnToHome(boolean bo){
npc.ai.returnToStart = bo;
}
/**
* @return Whether or not the npc returns home
*/
public boolean getReturnToHome(){
return npc.ai.returnToStart;
}
/**
* @return The faction of the npc
*/
public ScriptFaction getFaction(){
return new ScriptFaction(npc.getFaction());
}
/**
* @param id The id of the new faction
*/
public void setFaction(int id){
npc.setFaction(id);
}
@Override
public int getType(){
return EntityType.NPC;
}
@Override
public boolean typeOf(int type){
return type == EntityType.NPC?true:super.typeOf(type);
}
/**
* @param target The targeted npc
* @param item The item you want to shoot
* @param accuracy Accuracy of the shot (0-100)
*/
public void shootItem(ScriptLivingBase target, ScriptItemStack item, int accuracy){
if(item == null)
return;
if(accuracy < 0)
accuracy = 0;
else if(accuracy > 100)
accuracy = 100;
npc.shoot(target.entity, accuracy, item.item, false);
}
/**
* @param message The message the npc will say
*/
public void say(String message){
npc.saySurrounding(new Line(message));
}
/**
* @param message The message the npc will say
*/
public void say(ScriptPlayer player, String message){
if(player == null || message == null || message.isEmpty())
return;
npc.say(player.player, new Line(message));
}
/**
* Kill the npc, doesnt't despawn it
*/
public void kill(){
npc.setDead();
}
/**
* Basically completely resets the npc. This will also call the Init script
*/
public void reset(){
npc.reset();
}
/**
* @return Returns the npcs current role
*/
public ScriptRoleInterface getRole(){
if(npc.advanced.role == EnumRoleType.Bank)
return new ScriptRoleBank(npc);
else if(npc.advanced.role == EnumRoleType.Follower)
return new ScriptRoleFollower(npc);
else if(npc.advanced.role == EnumRoleType.Postman)
return new ScriptRoleMailman(npc);
else if(npc.advanced.role == EnumRoleType.Trader)
return new ScriptRoleTrader(npc);
else if(npc.advanced.role == EnumRoleType.Transporter)
return new ScriptRoleTransporter(npc);
return new ScriptRoleInterface(npc);
}
/**
* @return Returns the npcs current job
*/
public ScriptJobInterface getJob(){
if(npc.advanced.job == EnumJobType.Bard)
return new ScriptJobBard(npc);
else if(npc.advanced.job == EnumJobType.Conversation)
return new ScriptJobConversation(npc);
else if(npc.advanced.job == EnumJobType.Follower)
return new ScriptJobFollower(npc);
else if(npc.advanced.job == EnumJobType.Guard)
return new ScriptJobGuard(npc);
else if(npc.advanced.job == EnumJobType.Healer)
return new ScriptJobHealer(npc);
else if(npc.advanced.job == EnumJobType.Puppet)
return new ScriptJobPuppet(npc);
else if(npc.advanced.job == EnumJobType.ItemGiver)
return new ScriptJobItemGiver(npc);
else if(npc.advanced.job == EnumJobType.Spawner)
return new ScriptJobSpawner(npc);
return new ScriptJobInterface(npc);
}
/**
* @return The item held in the right hand
*/
public ScriptItemStack getRightItem(){
ItemStack item = npc.inventory.getWeapon();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
}
/**
* @param item Item to be held in the right hand
*/
public void setRightItem(ScriptItemStack item){
if(item == null)
npc.inventory.setWeapon(null);
else
npc.inventory.setWeapon(item.item);
npc.script.clientNeedsUpdate = true;
}
/**
* @return The item held in the left hand
*/
public ScriptItemStack getLefttItem(){
ItemStack item = npc.getOffHand();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
}
/**
* @param item Item to be held in the left hand
*/
public void setLeftItem(ScriptItemStack item){
if(item == null)
npc.inventory.setOffHand(null);
else
npc.inventory.setOffHand(item.item);
npc.script.clientNeedsUpdate = true;
}
/**
* @return Returns the projectile the npc uses
*/
public ScriptItemStack getProjectileItem(){
ItemStack item = npc.inventory.getProjectile();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
}
/**
* @param item Item to be used as projectile
*/
public void setProjectileItem(ScriptItemStack item){
if(item == null)
npc.inventory.setProjectile(null);
else
npc.inventory.setProjectile(item.item);
npc.script.aiNeedsUpdate = true;
}
/**
* @param slot The armor slot to return. 0:head, 1:body, 2:legs, 3:boots
* @return Returns the worn armor in slot
*/
@Override
public ScriptItemStack getArmor(int slot){
ItemStack item = npc.inventory.armor.get(slot);
if(item == null)
return null;
return new ScriptItemStack(item);
}
/**
* @param slot The armor slot to set. 0:head, 1:body, 2:legs, 3:boots
* @param item Item to be set as armor
*/
@Override
public void setArmor(int slot, ScriptItemStack item){
if(item == null)
npc.inventory.armor.put(slot, null);
else
npc.inventory.armor.put(slot, item.item);
npc.script.clientNeedsUpdate = true;
}
/**
* @param type The AnimationType
*/
public void setAnimation(int type){
if(type == AnimationType.NORMAL)
npc.ai.animationType = EnumAnimation.NONE;
else if(type == AnimationType.SITTING)
npc.ai.animationType = EnumAnimation.SITTING;
else if(type == AnimationType.DANCING)
npc.ai.animationType = EnumAnimation.DANCING;
else if(type == AnimationType.SNEAKING)
npc.ai.animationType = EnumAnimation.SNEAKING;
else if(type == AnimationType.LYING)
npc.ai.animationType = EnumAnimation.LYING;
else if(type == AnimationType.HUGGING)
npc.ai.animationType = EnumAnimation.HUG;
}
/**
* @param type The visibility type of the npc, 0:visible, 1:invisible, 2:semi-visible
*/
public void setVisibleType(int type){
npc.display.visible = type;
npc.script.clientNeedsUpdate = true;
}
/**
* @return The visibility type of the npc, 0:visible, 1:invisible, 2:semi-visible
*/
public int getVisibleType(){
return npc.display.visible;
}
/**
* @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking
*/
public void setShowName(int type){
npc.display.showName = type;
npc.script.clientNeedsUpdate = true;
}
/**
* @return Returns the visibility type of the name, 0:visible, 1:invisible, 2:when-attacking
*/
public int getShowName(){
return npc.display.showName;
}
/**
* @return Returns the visiblity of the boss bar, 0:invisible, 1:visible, 2:when-attacking
*/
public int getShowBossBar(){
return npc.display.showBossBar;
}
/**
* @param type The visibility type of the boss bar, 0:invisible, 1:visible, 2:when-attacking
*/
public void setShowBossBar(int type){
npc.display.showBossBar = (byte) type;
npc.script.clientNeedsUpdate = true;
}
/**
* @return The melee strength
*/
public int getMeleeStrength(){
return npc.stats.getAttackStrength();
}
/**
* @param strength The melee strength
*/
public void setMeleeStrength(int strength){
npc.stats.setAttackStrength(strength);
}
/**
* @return The melee speed
*/
public int getMeleeSpeed(){
return npc.stats.attackSpeed;
}
/**
* @param speed The melee speed
*/
public void setMeleeSpeed(int speed){
npc.stats.attackSpeed = speed;
}
/**
* @return The ranged strength
*/
public int getRangedStrength(){
return npc.stats.pDamage;
}
/**
* @param strength The ranged strength
*/
public void setRangedStrength(int strength){
npc.stats.pDamage = strength;
}
/**
* @return The ranged speed
*/
public int getRangedSpeed(){
return npc.stats.pSpeed;
}
/**
* @param speed The ranged speed
*/
public void setRangedSpeed(int speed){
npc.stats.pSpeed = speed;
}
/**
* @return The ranged burst count
*/
public int getRangedBurst(){
return npc.stats.burstCount;
}
/**
* @param count The ranged burst count
*/
public void setRangedBurst(int count){
npc.stats.burstCount = count;
}
/**
* @param player The player to give the item to
* @param item The item given to the player
*/
public void giveItem(ScriptPlayer player, ScriptItemStack item){
npc.givePlayerItem(player.player, item.item);
}
/**
* On servers the enable-command-block option in the server.properties needs to be set to true
* @param command The command to be executed
*/
public void executeCommand(String command){
NoppesUtilServer.runCommand(npc, npc.getCommandSenderName(), command, null);
}
public void setHeadScale(float x, float y, float z){
npc.modelData.head.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
npc.modelData.head.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
npc.modelData.head.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
npc.script.clientNeedsUpdate = true;
}
public void setBodyScale(float x, float y, float z){
npc.modelData.body.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
npc.modelData.body.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
npc.modelData.body.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
npc.script.clientNeedsUpdate = true;
}
public void setArmsScale(float x, float y, float z){
npc.modelData.arms.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
npc.modelData.arms.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
npc.modelData.arms.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
npc.script.clientNeedsUpdate = true;
}
public void setLegsScale(float x, float y, float z){
npc.modelData.legs.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
npc.modelData.legs.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
npc.modelData.legs.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
npc.script.clientNeedsUpdate = true;
}
/**
* @since 1.7.10c
* @param resistance Explosion resistance (0-2) default is 1
*/
public void setExplosionResistance(float resistance){
npc.stats.resistances.explosion = ValueUtil.correctFloat(resistance, 0, 2);
}
/**
* @since 1.7.10c
* @return Returns Explosion Resistance
*/
public float getExplosionResistance(){
return npc.stats.resistances.explosion;
}
/**
* @param resistance Melee resistance (0-2) default is 1
*/
public void setMeleeResistance(float resistance){
npc.stats.resistances.playermelee = ValueUtil.correctFloat(resistance, 0, 2);
}
/**
* @return Returns Melee Resistance
*/
public float getMeleeResistance(){
return npc.stats.resistances.playermelee;
}
/**
* @param resistance Arrow resistance (0-2) default is 1
*/
public void setArrowResistance(float resistance){
npc.stats.resistances.arrow = ValueUtil.correctFloat(resistance, 0, 2);
}
/**
* @return Returns Arrow Resistance
*/
public float getArrowResistance(){
return npc.stats.resistances.arrow;
}
/**
* @param resistance Knockback resistance (0-2) default is 1
*/
public void setKnockbackResistance(float resistance){
npc.stats.resistances.knockback = ValueUtil.correctFloat(resistance, 0, 2);
}
/**
* @return Returns Knockback Resistance
*/
public float getKnockbackResistance(){
return npc.stats.resistances.knockback;
}
/**
* @param type Retaliation type. 0:normal, 1:panic, 2:retreat, 3:nothing
*/
public void setRetaliateType(int type){
npc.ai.onAttack = type;
npc.setResponse();
}
/**
* @return Returns the combat health regen per second
*/
public int getCombatRegen(){
return npc.stats.combatRegen;
}
/**
* @param regen The combat health regen per second
*/
public void setCombatRegen(int regen){
npc.stats.combatRegen = regen;
}
/**
* @return Returns the health regen per second when not in combat
*/
public int getHealthRegen(){
return npc.stats.healthRegen;
}
/**
* @param regen The health regen per second when not in combat
*/
public void setHealthRegen(int regen){
npc.stats.healthRegen = regen;
}
@Override
public long getAge(){
return npc.totalTicksAlive;
}
}
@@ -0,0 +1,263 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.PixelmonHelper;
import noppes.npcs.scripted.interfaces.IPixelmon;
import noppes.npcs.util.ValueUtil;
public class ScriptPixelmon<T extends EntityTameable> extends ScriptAnimal<T> implements IPixelmon {
private T pixelmon;
private NBTTagCompound compound = null;
public ScriptPixelmon(T pixelmon){
super(pixelmon);
this.pixelmon = pixelmon;
compound = new NBTTagCompound();
pixelmon.writeEntityToNBT(compound);
}
public ScriptPixelmon(T pixelmon, NBTTagCompound compound){
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
*/
public int getIV(int type){
if(type == 0)
return compound.getInteger("IVHP");
if(type == 1)
return compound.getInteger("IVAttack");
if(type == 2)
return compound.getInteger("IVDefence");
if(type == 3)
return compound.getInteger("IVSpAtt");
if(type == 4)
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
*/
public void setIV(int type, int value){
if(type == 0)
compound.setInteger("IVHP", value);
else if(type == 1)
compound.setInteger("IVAttack", value);
else if(type == 2)
compound.setInteger("IVDefence", value);
else if(type == 3)
compound.setInteger("IVSpAtt", value);
else if(type == 4)
compound.setInteger("IVSpDef", value);
else if(type == 5)
compound.setInteger("IVSpeed", value);
pixelmon.readEntityFromNBT(compound);
}
/**
* @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed
*/
public int getEV(int type){
if(type == 0)
return compound.getInteger("EVHP");
if(type == 1)
return compound.getInteger("EVAttack");
if(type == 2)
return compound.getInteger("EVDefence");
if(type == 3)
return compound.getInteger("EVSpecialAttack");
if(type == 4)
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
*/
public void setEV(int type, int value){
if(type == 0)
compound.setInteger("EVHP", value);
else if(type == 1)
compound.setInteger("EVAttack", value);
else if(type == 2)
compound.setInteger("EVDefence", value);
else if(type == 3)
compound.setInteger("EVSpecialAttack", value);
else if(type == 4)
compound.setInteger("EVSpecialDefence", value);
else if(type == 5)
compound.setInteger("EVSpeed", value);
pixelmon.readEntityFromNBT(compound);
}
/**
* @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed
*/
public int getStat(int type){
if(type == 0)
return compound.getInteger("StatsHP");
if(type == 1)
return compound.getInteger("StatsAttack");
if(type == 2)
return compound.getInteger("StatsDefence");
if(type == 3)
return compound.getInteger("StatsSpecialAttack");
if(type == 4)
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
*/
public void setStat(int type, int value){
if(type == 0)
compound.setInteger("StatsHP", value);
else if(type == 1)
compound.setInteger("StatsAttack", value);
else if(type == 2)
compound.setInteger("StatsDefence", value);
else if(type == 3)
compound.setInteger("StatsSpecialAttack", value);
else if(type == 4)
compound.setInteger("StatsSpecialDefence", value);
else if(type == 5)
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
*/
public void setSize(int type){
compound.setShort("Growth", (short) type);
pixelmon.readEntityFromNBT(compound);
}
/**
* @return 0-255
*/
public int getHapiness(){
return compound.getInteger("Friendship");
}
/**
* @param value 0-255
*/
public void setHapiness(int value){
value = ValueUtil.CorrectInt(value, 0, 255);
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
*/
public void setNature(int type){
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
*/
public int getPokeball(){
if(compound.hasKey("CaughtBall"))
return -1;
return compound.getInteger("CaughtBall");
}
/**
* @param type -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
*/
public void setPokeball(int type){
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.CorrectInt(slot, 0, 3);
int id = PixelmonHelper.getAttackID(move);
compound.removeTag("PixelmonMovePP" + slot);
compound.removeTag("PixelmonMovePPBase" + slot);
if(id < 0){
compound.removeTag("PixelmonMoveID" + slot);
}
else{
compound.setInteger("PixelmonMoveID" + slot, id);
}
int size = 0;
for(int i = 0; i < 4; i++){
if(compound.hasKey("PixelmonMoveID" + i))
size++;
}
compound.setInteger("PixelmonNumberMoves", size);
pixelmon.readEntityFromNBT(compound);
}
}
@@ -0,0 +1,353 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.stats.StatBase;
import net.minecraft.stats.StatList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.WorldSettings;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.PixelmonHelper;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerDialogData;
import noppes.npcs.controllers.PlayerQuestData;
import noppes.npcs.controllers.Quest;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.QuestData;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.ScriptPixelmonPlayerData;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IPlayer;
import noppes.npcs.util.ValueUtil;
public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T> implements IPlayer {
protected T player;
public ScriptPlayer(T player){
super(player);
this.player = player;
}
/**
* @return Returns the displayed name of the player
*/
public String getDisplayName(){
return player.getDisplayName();
}
/**
* @return Returns the players name
*/
public String getName(){
return player.getCommandSenderName();
}
@Override
public void setPosition(double x, double y, double z){
NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension);
}
public int getDimension(){
return player.dimension;
}
public boolean hasFinishedQuest(int id){
PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData;
return data.finishedQuests.containsKey(id);
}
public boolean hasActiveQuest(int id){
PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData;
return data.activeQuests.containsKey(id);
}
public boolean hasReadDialog(int id){
PlayerDialogData data = PlayerDataController.instance.getPlayerData(player).dialogData;
return data.dialogsRead.contains(id);
}
/**
* Add the quest from active quest list
* @param id The Quest ID
*/
public void startQuest(int id){
Quest quest = QuestController.instance.quests.get(id);
if (quest == null)
return;
PlayerData data = PlayerDataController.instance.getPlayerData(player);
if(data.questData.activeQuests.containsKey(id))
return;
QuestData questdata = new QuestData(quest);
data.questData.activeQuests.put(id, questdata);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
}
/**
* Add the quest from finished quest list
* @param id The Quest ID
*/
public void finishQuest(int id){
Quest quest = QuestController.instance.quests.get(id);
if (quest == null)
return;
PlayerData data = PlayerDataController.instance.getPlayerData(player);
data.questData.finishedQuests.put(id, System.currentTimeMillis());
}
/**
* Removes the quest from active quest list
* @param id The Quest ID
*/
public void stopQuest(int id){
Quest quest = QuestController.instance.quests.get(id);
if (quest == null)
return;
PlayerData data = PlayerDataController.instance.getPlayerData(player);
data.questData.activeQuests.remove(id);
}
/**
* Removes the quest from active and finished quest list
* @param id The Quest ID
*/
public void removeQuest(int id){
Quest quest = QuestController.instance.quests.get(id);
if (quest == null)
return;
PlayerData data = PlayerDataController.instance.getPlayerData(player);
data.questData.activeQuests.remove(id);
data.questData.finishedQuests.remove(id);
}
@Override
public int getType(){
return EntityType.PLAYER;
}
@Override
public boolean typeOf(int type){
return type == EntityType.PLAYER?true:super.typeOf(type);
}
/**
* @param faction The faction id
* @param points The points to increase. Use negative values to decrease
*/
public void addFactionPoints(int faction, int points){
PlayerData data = PlayerDataController.instance.getPlayerData(player);
data.factionData.increasePoints(faction, points);
}
/**
* @param faction The faction id
* @return points
*/
public int getFactionPoints(int faction) {
PlayerData data = PlayerDataController.instance.getPlayerData(player);
return data.factionData.getFactionPoints(faction);
}
/**
* @param message The message you want to send
*/
public void sendMessage(String message){
player.addChatMessage(new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)));
}
/**
* @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure
*/
public int getMode(){
return player.theItemInWorldManager.getGameType().getID();
}
/**
* @param type The gamemode type. 0:SURVIVAL, 1:CREATIVE, 2:ADVENTURE
*/
public void setMode(int type){
player.setGameType(WorldSettings.getGameTypeById(type));
}
/**
* @param item The item to be checked
* @return How many of this item the player has
*/
public int inventoryItemCount(ScriptItemStack item){
int i = 0;
for(ItemStack is : player.inventory.mainInventory){
if (is != null && is.isItemEqual(item.item))
i += is.stackSize;
}
return i;
}
/**
* @since 1.7.10d
* @return Returns a IItemStack array size 36
*/
public ScriptItemStack[] getInventory(){
ScriptItemStack[] items = new ScriptItemStack[36];
for(int i = 0; i < player.inventory.mainInventory.length; i++){
ItemStack item = player.inventory.mainInventory[i];
if(item != null)
items[i] = new ScriptItemStack(item);
}
return items;
}
/**
* @param item The Item type to be removed
* @param amount How many will be removed
* @return Returns true if the items were removed succesfully. Returns false incase a bigger amount than what the player has was given
*/
public boolean removeItem(ScriptItemStack item, int amount){
int count = inventoryItemCount(item);
if(amount > count)
return false;
else if(count == amount)
removeAllItems(item);
else{
for(int i = 0; i < player.inventory.mainInventory.length; i++){
ItemStack is = player.inventory.mainInventory[i];
if (is != null && is.isItemEqual(item.item)){
if(amount > is.stackSize){
player.inventory.mainInventory[i] = null;
amount -= is.stackSize;
}
else{
is.splitStack(amount);
break;
}
}
}
}
return true;
}
/**
* @since 1.7.10c
* @param id The items name
* @param damage The damage value
* @param amount How many will be removed
* @return Returns true if the items were removed succesfully. Returns false incase a bigger amount than what the player has was given or item doesnt exist
*/
public boolean removeItem(String id, int damage, int amount){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return false;
return removeItem(new ScriptItemStack(new ItemStack(item, 1, damage)), amount);
}
/**
* @since 1.7.10c
* @param item Item to be added
* @param amount The amount of the item to be added
* @return Returns whether or not it gave the item succesfully
*/
public boolean giveItem(ScriptItemStack item, int amount){
if(item != null && item.getMCItemStack() != null) {
item.setStackSize(amount);
return this.player.inventory.addItemStackToInventory(item.getMCItemStack());
} else {
return false;
}
}
/**
* @since 1.7.10c
* @param id The items name
* @param damage The damage value
* @param amount The amount of the item to be added
* @return Returns whether or not it gave the item succesfully
*/
public boolean giveItem(String id, int damage, int amount){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return false;
return player.inventory.addItemStackToInventory(new ItemStack(item, amount, damage));
}
/**
* Same as the /spawnpoint command
* @param x The x position
* @param y The y position
* @param z The z position
*/
public void setSpawnpoint(int x, int y, int z){
x = ValueUtil.CorrectInt(x, -30000000, 30000000);
z = ValueUtil.CorrectInt(z, -30000000, 30000000);
y = ValueUtil.CorrectInt(y, 0, 256);
player.setSpawnChunk(new ChunkCoordinates(x, y, z), true);
}
public void resetSpawnpoint(){
player.setSpawnChunk(null, false);
}
/**
* @param item The item to be removed from the players inventory
*/
public void removeAllItems(ScriptItemStack item){
for(int i = 0; i < player.inventory.mainInventory.length; i++){
ItemStack is = player.inventory.mainInventory[i];
if (is != null && is.isItemEqual(item.item))
player.inventory.mainInventory[i] = null;
}
}
/**
* @param achievement The achievement id. For a complete list see http://minecraft.gamepedia.com/Achievements
* @return Returns whether or not the player has this achievement
*/
public boolean hasAchievement(String achievement){
StatBase statbase = StatList.func_151177_a(achievement);
if(statbase == null || !(statbase instanceof Achievement)){
return false;
}
return player.func_147099_x().hasAchievementUnlocked((Achievement) statbase);
}
/**
* @param permission Bukkit/Cauldron permission
* @return Returns whether or not the player has the permission
*/
public boolean hasBukkitPermission(String permission){
return CustomNpcsPermissions.hasPermissionString(player, permission);
}
/**
* @since 1.7.10c
* @return Returns the exp level
*/
public int getExpLevel(){
return player.experienceLevel;
}
/**
* @since 1.7.10c
* @param level The new exp level you want to set
*/
public void setExpLevel(int level){
player.experienceLevel = level;
player.addExperienceLevel(0);
}
/**
* Requires pixelmon to be installed
* @since 1.7.10d
*/
public ScriptPixelmonPlayerData getPixelmonData(){
if(!PixelmonHelper.Enabled)
return null;
return new ScriptPixelmonPlayerData(player);
}
}