BloodMagic/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySentientArrow.java

67 lines
2.2 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.entity.projectile;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.soul.EnumDemonWillType;
import WayofTime.bloodmagic.soul.PlayerDemonWillHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityTippedArrow;
2016-03-18 16:57:57 -04:00
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import java.util.Locale;
2017-08-15 21:30:48 -07:00
public class EntitySentientArrow extends EntityTippedArrow {
public double reimbursedAmountOnHit = 0;
public EnumDemonWillType type = EnumDemonWillType.DEFAULT;
2017-08-15 21:30:48 -07:00
public EntitySentientArrow(World worldIn) {
super(worldIn);
}
2017-08-15 21:30:48 -07:00
public EntitySentientArrow(World worldIn, double x, double y, double z) {
super(worldIn, x, y, z);
}
2017-08-15 21:30:48 -07:00
public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reinburseAmount) {
super(worldIn, shooter);
this.reimbursedAmountOnHit = reinburseAmount;
this.type = type;
}
2017-08-15 21:30:48 -07:00
public void reimbursePlayer(EntityLivingBase hitEntity, float damage) {
if (this.shootingEntity instanceof EntityPlayer) {
if (hitEntity.getEntityWorld().getDifficulty() != EnumDifficulty.PEACEFUL && !(hitEntity instanceof IMob)) {
return;
}
PlayerDemonWillHandler.addDemonWill(type, (EntityPlayer) this.shootingEntity, reimbursedAmountOnHit * damage / 20f);
}
}
@Override
2017-08-15 21:30:48 -07:00
public void writeEntityToNBT(NBTTagCompound tag) {
super.writeEntityToNBT(tag);
tag.setDouble("reimbursement", reimbursedAmountOnHit);
tag.setString(Constants.NBT.WILL_TYPE, type.toString());
}
@Override
2017-08-15 21:30:48 -07:00
public void readEntityFromNBT(NBTTagCompound tag) {
super.readEntityFromNBT(tag);
reimbursedAmountOnHit = tag.getDouble("reimbursement");
type = EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE).toUpperCase(Locale.ENGLISH));
}
2016-03-18 16:57:57 -04:00
@Override
2017-08-15 21:30:48 -07:00
protected ItemStack getArrowStack() {
2016-04-24 10:06:28 -07:00
return new ItemStack(Items.ARROW);
2016-03-18 16:57:57 -04:00
}
}