summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/TileEntityPiston.java
blob: 3e5e8f085717adb82f264f132cd12106c95f63b6 (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
package net.minecraft.server;

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

public class TileEntityPiston extends TileEntity {

    private Block a;
    private int i;
    private int j;
    private boolean k;
    private boolean l;
    private float m;
    private float n;
    private List o = new ArrayList();

    public TileEntityPiston() {}

    public TileEntityPiston(Block block, int i, int j, boolean flag, boolean flag1) {
        this.a = block;
        this.i = i;
        this.j = j;
        this.k = flag;
        this.l = flag1;
    }

    public Block a() {
        return this.a;
    }

    public int p() {
        return this.i;
    }

    public boolean b() {
        return this.k;
    }

    public int c() {
        return this.j;
    }

    public float a(float f) {
        if (f > 1.0F) {
            f = 1.0F;
        }

        return this.n + (this.m - this.n) * f;
    }

    private void a(float f, float f1) {
        if (this.k) {
            f = 1.0F - f;
        } else {
            --f;
        }

        AxisAlignedBB axisalignedbb = Blocks.PISTON_MOVING.a(this.world, this.x, this.y, this.z, this.a, f, this.j);

        if (axisalignedbb != null) {
            List list = this.world.getEntities((Entity) null, axisalignedbb);

            if (!list.isEmpty()) {
                this.o.addAll(list);
                Iterator iterator = this.o.iterator();

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

                    entity.move((double) (f1 * (float) Facing.b[this.j]), (double) (f1 * (float) Facing.c[this.j]), (double) (f1 * (float) Facing.d[this.j]));
                }

                this.o.clear();
            }
        }
    }

    public void f() {
        if (this.n < 1.0F && this.world != null) {
            this.n = this.m = 1.0F;
            this.world.p(this.x, this.y, this.z);
            this.s();
            if (this.world.getType(this.x, this.y, this.z) == Blocks.PISTON_MOVING) {
                this.world.setTypeAndData(this.x, this.y, this.z, this.a, this.i, 3);
                this.world.e(this.x, this.y, this.z, this.a);
            }
        }
    }

    public void h() {
        if (this.world == null) return; // CraftBukkit

        this.n = this.m;
        if (this.n >= 1.0F) {
            this.a(1.0F, 0.25F);
            this.world.p(this.x, this.y, this.z);
            this.s();
            if (this.world.getType(this.x, this.y, this.z) == Blocks.PISTON_MOVING) {
                this.world.setTypeAndData(this.x, this.y, this.z, this.a, this.i, 3);
                this.world.e(this.x, this.y, this.z, this.a);
            }
        } else {
            this.m += 0.5F;
            if (this.m >= 1.0F) {
                this.m = 1.0F;
            }

            if (this.k) {
                this.a(this.m, this.m - this.n + 0.0625F);
            }
        }
    }

    public void a(NBTTagCompound nbttagcompound) {
        super.a(nbttagcompound);
        this.a = Block.e(nbttagcompound.getInt("blockId"));
        this.i = nbttagcompound.getInt("blockData");
        this.j = nbttagcompound.getInt("facing");
        this.n = this.m = nbttagcompound.getFloat("progress");
        this.k = nbttagcompound.getBoolean("extending");
    }

    public void b(NBTTagCompound nbttagcompound) {
        super.b(nbttagcompound);
        nbttagcompound.setInt("blockId", Block.b(this.a));
        nbttagcompound.setInt("blockData", this.i);
        nbttagcompound.setInt("facing", this.j);
        nbttagcompound.setFloat("progress", this.n);
        nbttagcompound.setBoolean("extending", this.k);
    }
}