summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityFallingBlock.java
blob: 4142650ac8a33229ed388d6b17e5087a0b351f4b (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package net.minecraft.server;

import java.util.ArrayList;
import java.util.Iterator;

import org.bukkit.event.entity.EntityDamageEvent; // CraftBukkit

public class EntityFallingBlock extends Entity {

    public int id;
    public int data;
    public int c;
    public boolean dropItem;
    private boolean e;
    private boolean hurtEntities;
    private int fallHurtMax;
    private float fallHurtAmount;

    public EntityFallingBlock(World world) {
        super(world);
        this.c = 0;
        this.dropItem = true;
        this.e = false;
        this.hurtEntities = false;
        this.fallHurtMax = 20;
        this.fallHurtAmount = 2.0F;
    }

    public EntityFallingBlock(World world, double d0, double d1, double d2, int i) {
        this(world, d0, d1, d2, i, 0);
    }

    public EntityFallingBlock(World world, double d0, double d1, double d2, int i, int j) {
        super(world);
        this.c = 0;
        this.dropItem = true;
        this.e = false;
        this.hurtEntities = false;
        this.fallHurtMax = 20;
        this.fallHurtAmount = 2.0F;
        this.id = i;
        this.data = j;
        this.m = true;
        this.a(0.98F, 0.98F);
        this.height = this.length / 2.0F;
        this.setPosition(d0, d1, d2);
        this.motX = 0.0D;
        this.motY = 0.0D;
        this.motZ = 0.0D;
        this.lastX = d0;
        this.lastY = d1;
        this.lastZ = d2;
    }

    protected boolean f_() {
        return false;
    }

    protected void a() {}

    public boolean L() {
        return !this.dead;
    }

    public void j_() {
        if (this.id == 0) {
            this.die();
        } else {
            this.lastX = this.locX;
            this.lastY = this.locY;
            this.lastZ = this.locZ;
            ++this.c;
            this.motY -= 0.03999999910593033D;
            this.move(this.motX, this.motY, this.motZ);
            this.motX *= 0.9800000190734863D;
            this.motY *= 0.9800000190734863D;
            this.motZ *= 0.9800000190734863D;
            if (!this.world.isStatic) {
                int i = MathHelper.floor(this.locX);
                int j = MathHelper.floor(this.locY);
                int k = MathHelper.floor(this.locZ);

                if (this.c == 1) {
                    if (this.c == 1 && this.world.getTypeId(i, j, k) == this.id) {
                        this.world.setTypeId(i, j, k, 0);
                    } else {
                        this.die();
                        return; // CraftBukkit
                    }
                }

                if (this.onGround) {
                    this.motX *= 0.699999988079071D;
                    this.motZ *= 0.699999988079071D;
                    this.motY *= -0.5D;
                    if (this.world.getTypeId(i, j, k) != Block.PISTON_MOVING.id) {
                        this.die();
                        if (!this.e && this.world.mayPlace(this.id, i, j, k, true, 1, (Entity) null) && !BlockSand.canFall(this.world, i, j - 1, k) && this.world.setTypeIdAndData(i, j, k, this.id, this.data)) {
                            if (Block.byId[this.id] instanceof BlockSand) {
                                ((BlockSand) Block.byId[this.id]).a_(this.world, i, j, k, this.data);
                            }
                        } else if (this.dropItem && !this.e) {
                            this.a(new ItemStack(this.id, 1, Block.byId[this.id].getDropData(this.data)), 0.0F);
                        }
                    }
                } else if (this.c > 100 && !this.world.isStatic && (j < 1 || j > 256) || this.c > 600) {
                    if (this.dropItem) {
                        this.a(new ItemStack(this.id, 1, Block.byId[this.id].getDropData(this.data)), 0.0F);
                    }

                    this.die();
                }
            }
        }
    }

    protected void a(float f) {
        if (this.hurtEntities) {
            int i = MathHelper.f(f - 1.0F);

            if (i > 0) {
                ArrayList arraylist = new ArrayList(this.world.getEntities(this, this.boundingBox));
                DamageSource damagesource = this.id == Block.ANVIL.id ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;
                Iterator iterator = arraylist.iterator();

                while (iterator.hasNext()) {
                    Entity entity = (Entity) iterator.next();

                    // CraftBukkit start
                    int damage = Math.min(MathHelper.d((float) i * this.fallHurtAmount), this.fallHurtMax);

                    EntityDamageEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDamageEvent(this, entity, EntityDamageEvent.DamageCause.FALLING_BLOCK, damage);
                    if (event.isCancelled()) {
                        continue;
                    }

                    entity.damageEntity(damagesource, event.getDamage());
                    // CraftBukkit end
                }

                if (this.id == Block.ANVIL.id && (double) this.random.nextFloat() < 0.05000000074505806D + (double) i * 0.05D) {
                    int j = this.data >> 2;
                    int k = this.data & 3;

                    ++j;
                    if (j > 2) {
                        this.e = true;
                    } else {
                        this.data = k | j << 2;
                    }
                }
            }
        }
    }

    protected void b(NBTTagCompound nbttagcompound) {
        nbttagcompound.setByte("Tile", (byte) this.id);
        nbttagcompound.setByte("Data", (byte) this.data);
        nbttagcompound.setByte("Time", (byte) this.c);
        nbttagcompound.setBoolean("DropItem", this.dropItem);
        nbttagcompound.setBoolean("HurtEntities", this.hurtEntities);
        nbttagcompound.setFloat("FallHurtAmount", this.fallHurtAmount);
        nbttagcompound.setInt("FallHurtMax", this.fallHurtMax);
    }

    protected void a(NBTTagCompound nbttagcompound) {
        this.id = nbttagcompound.getByte("Tile") & 255;
        this.data = nbttagcompound.getByte("Data") & 255;
        this.c = nbttagcompound.getByte("Time") & 255;
        if (nbttagcompound.hasKey("HurtEntities")) {
            this.hurtEntities = nbttagcompound.getBoolean("HurtEntities");
            this.fallHurtAmount = nbttagcompound.getFloat("FallHurtAmount");
            this.fallHurtMax = nbttagcompound.getInt("FallHurtMax");
        } else if (this.id == Block.ANVIL.id) {
            this.hurtEntities = true;
        }

        if (nbttagcompound.hasKey("DropItem")) {
            this.dropItem = nbttagcompound.getBoolean("DropItem");
        }

        if (this.id == 0) {
            this.id = Block.SAND.id;
        }
    }

    public void e(boolean flag) {
        this.hurtEntities = flag;
    }
}