Added hurt functions to ScriptLivingBase

This commit is contained in:
luisc committed 2021-10-25 00:58:03 -05:00
1 parent 6fcf566ef7
commit 1478841098
2 files changed
+20

No files matched your search

@@ -4,10 +4,13 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntityLivingBase;
import noppes.npcs.scripted.wrapper.ScriptDamageSource;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
protected T entity;
@@ -30,6 +33,18 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
public void setHealth(float health){
entity.setHealth(health);
}
public void hurt(float damage){
entity.attackEntityFrom(DamageSource.generic,damage);
}
public void hurt(ScriptEntity source, float damage){
entity.attackEntityFrom(new EntityDamageSource(source.getTypeName(),source.getMCEntity()),damage);
}
public void hurt(ScriptDamageSource damageSource, float damage){
entity.attackEntityFrom(damageSource.getMCDamageSource(),damage);
}
/**
* @return Entity's max health
@@ -25,6 +25,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
@@ -201,6 +202,10 @@ public class WrapperNpcAPI extends NpcAPI {
return new ScriptDamageSource(damagesource);
}
public IDamageSource getIDamageSource(IEntity entity) {
return new ScriptDamageSource(new EntityDamageSource(entity.getTypeName(),entity.getMCEntity()));
}
public void executeCommand(IWorld world, String command) {
//if(!world.getMCWorld().isRemote)
NoppesUtilServer.runCommand(world.getMCWorld(), "API", command);