summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/entity/EntityMagicWedge.java
blob: fdbd0683e42602389d5ce8e86ab2fbd58f137c21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jp.plusplus.fbs.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

/**
 * Createdby pluslus_Fon 2015/06/14.
 */
public class EntityMagicWedge extends EntityMagicProjectileBase {
    protected int encLv;
    protected int encDur;

    public EntityMagicWedge(World p_i1582_1_) {
        super(p_i1582_1_);
    }
    public EntityMagicWedge(World par1World, EntityLivingBase par2EntityLivingBase, float speed, float speed2, float damage, int lv, int du) {
        super(par1World, par2EntityLivingBase, speed, speed2, 0, 0, 0);
        setDamage(damage);
        encLv=lv;
        encDur=du;
    }

    public boolean canExist(){ return worldObj.isRemote || ticksExisted<20*3; }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbt) {
        super.readEntityFromNBT(nbt);
        encLv=nbt.getInteger("EnchantLv");
        encDur=nbt.getInteger("EnchantDur");
    }
    @Override
    protected void writeEntityToNBT(NBTTagCompound nbt) {
        super.writeEntityToNBT(nbt);
        nbt.setInteger("EnchantLv", encLv);
        nbt.setInteger("EnchantDur", encDur);
    }

    public void onCollideWithPlayer(MovingObjectPosition pos, EntityPlayer entity){
        if(!worldObj.isRemote && !shootingEntity.isEntityEqual(entity)) {
            entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), encDur, encLv));
            entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(shootingEntity, entity), getDamage());
            setDead();
        }
    }
    public void onCollideWithMob(MovingObjectPosition pos, EntityMob entity){
        if(!worldObj.isRemote) {
            hitAt(entity);
        }
    }
    public void onCollideWithLiving(MovingObjectPosition pos, EntityLiving entity){
        if(!worldObj.isRemote) {
            hitAt(entity);
        }
    }

    protected void hitAt(EntityLiving entity){
        entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), encDur, encLv));
        entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(shootingEntity, entity), getDamage());
        setDead();
    }
}