summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/entity/EntityMagicDig.java
blob: 3b38d4a4f15917f754d7d10fe15732df2bbe0983 (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
package jp.plusplus.fbs.entity;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

/**
 * Createdby pluslus_Fon 2015/06/07.
 */
public class EntityMagicDig extends EntityMagicProjectileBase {
    protected int till;
    protected boolean isPenetrate;

    public EntityMagicDig(World p_i1582_1_) {
        super(p_i1582_1_);
        till=10;
    }
    public EntityMagicDig(World par1World, EntityLivingBase par2EntityLivingBase, float speed, float speed2, int till, boolean isPenetrate) {
        super(par1World, par2EntityLivingBase, speed, speed2, 0, 0, 0);
        this.till=10+till;
        this.isPenetrate=isPenetrate;
    }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbt) {
        super.readEntityFromNBT(nbt);
        isPenetrate=nbt.getBoolean("IsPenetrate");
        till=nbt.getInteger("magicTill");
    }
    @Override
    protected void writeEntityToNBT(NBTTagCompound nbt) {
        super.writeEntityToNBT(nbt);
        nbt.setBoolean("IsPenetrate", isPenetrate);
        nbt.setInteger("magicTill", till);
    }

    public boolean canExist(){ return worldObj.isRemote || ticksExisted<till; }
    public void onCollideWithBlock(MovingObjectPosition pos, Block block) {
        if (!worldObj.isRemote) {
            float h = block.getBlockHardness(worldObj, xTile, yTile, zTile);
            if (h <= 30.0f && h != -1.0f){
                worldObj.func_147480_a(xTile, yTile, zTile, true);
            }
            else{
                setDead();
                return;
            }
        }
        if (isPenetrate) {
            inTile = Blocks.air;
            inData = 0;
        } else {
            setDead();
        }
    }

    @Override
    protected void setParticleColor(){
        particleRed=0.5f+0.5f*rand.nextFloat();
        particleGreen=0.25f+0.2f*rand.nextFloat();
        particleBlue=0.2f*rand.nextFloat();
    }
}