summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/BlockDiodeAbstract.java
blob: 6d205d91806b2fc88b40921e50db600182277814 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package net.minecraft.server;

import java.util.Random;

import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit

public abstract class BlockDiodeAbstract extends BlockDirectional {

    protected final boolean a;

    protected BlockDiodeAbstract(int i, boolean flag) {
        super(i, Material.ORIENTABLE);
        this.a = flag;
        this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
    }

    public boolean b() {
        return false;
    }

    public boolean canPlace(World world, int i, int j, int k) {
        return !world.w(i, j - 1, k) ? false : super.canPlace(world, i, j, k);
    }

    public boolean f(World world, int i, int j, int k) {
        return !world.w(i, j - 1, k) ? false : super.f(world, i, j, k);
    }

    public void a(World world, int i, int j, int k, Random random) {
        int l = world.getData(i, j, k);

        if (!this.e((IBlockAccess) world, i, j, k, l)) {
            boolean flag = this.d(world, i, j, k, l);

            if (this.a && !flag) {
                // CraftBukkit start
                if (CraftEventFactory.callRedstoneChange(world, i, j, k, 15, 0).getNewCurrent() != 0) {
                    return;
                }
                // CraftBukkit end

                world.setTypeIdAndData(i, j, k, this.j().id, l, 2);
            } else if (!this.a) {
                // CraftBukkit start
                if (CraftEventFactory.callRedstoneChange(world, i, j, k, 0, 15).getNewCurrent() != 15) {
                    return;
                }
                // CraftBukkit end

                world.setTypeIdAndData(i, j, k, this.i().id, l, 2);
                if (!flag) {
                    world.a(i, j, k, this.i().id, this.h(l), -1);
                }
            }
        }
    }

    public int d() {
        return 36;
    }

    protected boolean c(int i) {
        return this.a;
    }

    public int c(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        return this.b(iblockaccess, i, j, k, l);
    }

    public int b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        int i1 = iblockaccess.getData(i, j, k);

        if (!this.c(i1)) {
            return 0;
        } else {
            int j1 = j(i1);

            return j1 == 0 && l == 3 ? this.d(iblockaccess, i, j, k, i1) : (j1 == 1 && l == 4 ? this.d(iblockaccess, i, j, k, i1) : (j1 == 2 && l == 2 ? this.d(iblockaccess, i, j, k, i1) : (j1 == 3 && l == 5 ? this.d(iblockaccess, i, j, k, i1) : 0)));
        }
    }

    public void doPhysics(World world, int i, int j, int k, int l) {
        if (!this.f(world, i, j, k)) {
            this.c(world, i, j, k, world.getData(i, j, k), 0);
            world.setAir(i, j, k);
            world.applyPhysics(i + 1, j, k, this.id);
            world.applyPhysics(i - 1, j, k, this.id);
            world.applyPhysics(i, j, k + 1, this.id);
            world.applyPhysics(i, j, k - 1, this.id);
            world.applyPhysics(i, j - 1, k, this.id);
            world.applyPhysics(i, j + 1, k, this.id);
        } else {
            this.f(world, i, j, k, l);
        }
    }

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

        if (!this.e((IBlockAccess) world, i, j, k, i1)) {
            boolean flag = this.d(world, i, j, k, i1);

            if ((this.a && !flag || !this.a && flag) && !world.a(i, j, k, this.id)) {
                byte b0 = -1;

                if (this.h(world, i, j, k, i1)) {
                    b0 = -3;
                } else if (this.a) {
                    b0 = -2;
                }

                world.a(i, j, k, this.id, this.k_(i1), b0);
            }
        }
    }

    public boolean e(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        return false;
    }

    protected boolean d(World world, int i, int j, int k, int l) {
        return this.e(world, i, j, k, l) > 0;
    }

    protected int e(World world, int i, int j, int k, int l) {
        int i1 = j(l);
        int j1 = i + Direction.a[i1];
        int k1 = k + Direction.b[i1];
        int l1 = world.getBlockFacePower(j1, j, k1, Direction.d[i1]);

        return l1 >= 15 ? l1 : Math.max(l1, world.getTypeId(j1, j, k1) == Block.REDSTONE_WIRE.id ? world.getData(j1, j, k1) : 0);
    }

    protected int f(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        int i1 = j(l);

        switch (i1) {
        case 0:
        case 2:
            return Math.max(this.g(iblockaccess, i - 1, j, k, 4), this.g(iblockaccess, i + 1, j, k, 5));

        case 1:
        case 3:
            return Math.max(this.g(iblockaccess, i, j, k + 1, 3), this.g(iblockaccess, i, j, k - 1, 2));

        default:
            return 0;
        }
    }

    protected int g(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        int i1 = iblockaccess.getTypeId(i, j, k);

        return this.e(i1) ? (i1 == Block.REDSTONE_WIRE.id ? iblockaccess.getData(i, j, k) : iblockaccess.getBlockPower(i, j, k, l)) : 0;
    }

    public boolean isPowerSource() {
        return true;
    }

    public void postPlace(World world, int i, int j, int k, EntityLiving entityliving, ItemStack itemstack) {
        int l = ((MathHelper.floor((double) (entityliving.yaw * 4.0F / 360.0F) + 0.5D) & 3) + 2) % 4;

        world.setData(i, j, k, l, 3);
        boolean flag = this.d(world, i, j, k, l);

        if (flag) {
            world.a(i, j, k, this.id, 1);
        }
    }

    public void onPlace(World world, int i, int j, int k) {
        this.h_(world, i, j, k);
    }

    protected void h_(World world, int i, int j, int k) {
        int l = j(world.getData(i, j, k));

        if (l == 1) {
            world.g(i + 1, j, k, this.id);
            world.c(i + 1, j, k, this.id, 4);
        }

        if (l == 3) {
            world.g(i - 1, j, k, this.id);
            world.c(i - 1, j, k, this.id, 5);
        }

        if (l == 2) {
            world.g(i, j, k + 1, this.id);
            world.c(i, j, k + 1, this.id, 2);
        }

        if (l == 0) {
            world.g(i, j, k - 1, this.id);
            world.c(i, j, k - 1, this.id, 3);
        }
    }

    public void postBreak(World world, int i, int j, int k, int l) {
        if (this.a) {
            world.applyPhysics(i + 1, j, k, this.id);
            world.applyPhysics(i - 1, j, k, this.id);
            world.applyPhysics(i, j, k + 1, this.id);
            world.applyPhysics(i, j, k - 1, this.id);
            world.applyPhysics(i, j - 1, k, this.id);
            world.applyPhysics(i, j + 1, k, this.id);
        }

        super.postBreak(world, i, j, k, l);
    }

    public boolean c() {
        return false;
    }

    protected boolean e(int i) {
        Block block = Block.byId[i];

        return block != null && block.isPowerSource();
    }

    protected int d(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        return 15;
    }

    public static boolean f(int i) {
        return Block.DIODE_OFF.g(i) || Block.REDSTONE_COMPARATOR_OFF.g(i);
    }

    public boolean g(int i) {
        return i == this.i().id || i == this.j().id;
    }

    public boolean h(World world, int i, int j, int k, int l) {
        int i1 = j(l);

        if (f(world.getTypeId(i - Direction.a[i1], j, k - Direction.b[i1]))) {
            int j1 = world.getData(i - Direction.a[i1], j, k - Direction.b[i1]);
            int k1 = j(j1);

            return k1 != i1;
        } else {
            return false;
        }
    }

    protected int h(int i) {
        return this.k_(i);
    }

    protected abstract int k_(int i);

    protected abstract BlockDiodeAbstract i();

    protected abstract BlockDiodeAbstract j();

    public boolean i(int i) {
        return this.g(i);
    }
}