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

import java.util.Random;

public class BlockTorch extends Block {

    protected BlockTorch(int i, int j) {
        super(i, j, Material.ORIENTABLE);
        this.a(true);
    }

    public AxisAlignedBB e(World world, int i, int j, int k) {
        return null;
    }

    public boolean a() {
        return false;
    }

    public boolean b() {
        return false;
    }

    public int c() {
        return 2;
    }

    private boolean g(World world, int i, int j, int k) {
        if (world.b(i, j, k, true)) {
            return true;
        } else {
            int l = world.getTypeId(i, j, k);

            return l == Block.FENCE.id || l == Block.NETHER_FENCE.id;
        }
    }

    public boolean canPlace(World world, int i, int j, int k) {
        return world.b(i - 1, j, k, true) ? true : (world.b(i + 1, j, k, true) ? true : (world.b(i, j, k - 1, true) ? true : (world.b(i, j, k + 1, true) ? true : this.g(world, i, j - 1, k))));
    }

    public void postPlace(World world, int i, int j, int k, int l) {
        int i1 = world.getData(i, j, k);

        if (l == 1 && this.g(world, i, j - 1, k)) {
            i1 = 5;
        }

        if (l == 2 && world.b(i, j, k + 1, true)) {
            i1 = 4;
        }

        if (l == 3 && world.b(i, j, k - 1, true)) {
            i1 = 3;
        }

        if (l == 4 && world.b(i + 1, j, k, true)) {
            i1 = 2;
        }

        if (l == 5 && world.b(i - 1, j, k, true)) {
            i1 = 1;
        }

        world.setData(i, j, k, i1);
    }

    public void a(World world, int i, int j, int k, Random random) {
        super.a(world, i, j, k, random);
        if (world.getData(i, j, k) == 0) {
            this.onPlace(world, i, j, k);
        }
    }

    public void onPlace(World world, int i, int j, int k) {
        /* // CraftBukkit start - we do this, correctly, in postPlace
        if (world.b(i - 1, j, k, true)) {
            world.setData(i, j, k, 1);
        } else if (world.b(i + 1, j, k, true)) {
            world.setData(i, j, k, 2);
        } else if (world.b(i, j, k - 1, true)) {
            world.setData(i, j, k, 3);
        } else if (world.b(i, j, k + 1, true)) {
            world.setData(i, j, k, 4);
        } else if (this.g(world, i, j - 1, k)) {
            world.setData(i, j, k, 5);
        }

        this.h(world, i, j, k);
        */ // CraftBukkit end
    }

    public void doPhysics(World world, int i, int j, int k, int l) {
        if (this.h(world, i, j, k)) {
            int i1 = world.getData(i, j, k);
            boolean flag = false;

            if (!world.b(i - 1, j, k, true) && i1 == 1) {
                flag = true;
            }

            if (!world.b(i + 1, j, k, true) && i1 == 2) {
                flag = true;
            }

            if (!world.b(i, j, k - 1, true) && i1 == 3) {
                flag = true;
            }

            if (!world.b(i, j, k + 1, true) && i1 == 4) {
                flag = true;
            }

            if (!this.g(world, i, j - 1, k) && i1 == 5) {
                flag = true;
            }

            if (flag) {
                this.b(world, i, j, k, world.getData(i, j, k), 0);
                world.setTypeId(i, j, k, 0);
            }
        }
    }

    private boolean h(World world, int i, int j, int k) {
        if (!this.canPlace(world, i, j, k)) {
            if (world.getTypeId(i, j, k) == this.id) {
                this.b(world, i, j, k, world.getData(i, j, k), 0);
                world.setTypeId(i, j, k, 0);
            }

            return false;
        } else {
            return true;
        }
    }

    public MovingObjectPosition a(World world, int i, int j, int k, Vec3D vec3d, Vec3D vec3d1) {
        int l = world.getData(i, j, k) & 7;
        float f = 0.15F;

        if (l == 1) {
            this.a(0.0F, 0.2F, 0.5F - f, f * 2.0F, 0.8F, 0.5F + f);
        } else if (l == 2) {
            this.a(1.0F - f * 2.0F, 0.2F, 0.5F - f, 1.0F, 0.8F, 0.5F + f);
        } else if (l == 3) {
            this.a(0.5F - f, 0.2F, 0.0F, 0.5F + f, 0.8F, f * 2.0F);
        } else if (l == 4) {
            this.a(0.5F - f, 0.2F, 1.0F - f * 2.0F, 0.5F + f, 0.8F, 1.0F);
        } else {
            f = 0.1F;
            this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.6F, 0.5F + f);
        }

        return super.a(world, i, j, k, vec3d, vec3d1);
    }
}