2021-10-18 06:33:39 -05:00
|
|
|
package noppes.npcs.scripted.entity;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
2021-10-25 00:58:03 -05:00
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
|
import net.minecraft.util.EntityDamageSource;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2021-10-18 06:33:39 -05:00
|
|
|
import noppes.npcs.scripted.ScriptItemStack;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.scripted.constants.EntityType;
|
2021-10-18 06:33:39 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IEntityLivingBase;
|
2021-10-25 00:58:03 -05:00
|
|
|
import noppes.npcs.scripted.wrapper.ScriptDamageSource;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
|
2021-10-12 02:57:32 -05:00
|
|
|
protected T entity;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2021-10-12 02:57:32 -05:00
|
|
|
public ScriptLivingBase(T entity){
|
2018-09-13 12:03:28 -04:00
|
|
|
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);
|
|
|
|
|
}
|
2021-10-25 00:58:03 -05:00
|
|
|
|
|
|
|
|
public void hurt(float damage){
|
|
|
|
|
entity.attackEntityFrom(DamageSource.generic,damage);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 16:46:09 -05:00
|
|
|
public void hurt(float damage, ScriptEntity source) {
|
2021-10-25 00:58:03 -05:00
|
|
|
entity.attackEntityFrom(new EntityDamageSource(source.getTypeName(),source.getMCEntity()),damage);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 16:46:09 -05:00
|
|
|
public void hurt(float damage, ScriptDamageSource damageSource) {
|
2021-10-25 00:58:03 -05:00
|
|
|
entity.attackEntityFrom(damageSource.getMCDamageSource(),damage);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2021-10-12 02:57:32 -05:00
|
|
|
public T getMCEntity(){
|
2018-09-13 12:03:28 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if(duration < 0)
|
|
|
|
|
duration = 0;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|