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

import java.util.Random;

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

public class BlockDiode extends BlockDirectional {

    public static final double[] a = new double[] { -0.0625D, 0.0625D, 0.1875D, 0.3125D};
    private static final int[] b = new int[] { 1, 2, 3, 4};
    private final boolean c;

    protected BlockDiode(int i, boolean flag) {
        super(i, 6, Material.ORIENTABLE);
        this.c = 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.v(i, j - 1, k) ? false : super.canPlace(world, i, j, k);
    }

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

    public void b(World world, int i, int j, int k, Random random) {
        int l = world.getData(i, j, k);
        boolean flag = this.e(world, i, j, k, l);

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

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

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

                world.setTypeIdAndData(i, j, k, Block.DIODE_ON.id, l);
                if (!flag1) {
                    int i1 = (l & 12) >> 2;

                    world.a(i, j, k, Block.DIODE_ON.id, b[i1] * 2);
                }
            }
        }
    }

    public int a(int i, int j) {
        return i == 0 ? (this.c ? 99 : 115) : (i == 1 ? (this.c ? 147 : 131) : 5);
    }

    public int d() {
        return 15;
    }

    public int a(int i) {
        return this.a(i, 0);
    }

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

    public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        if (!this.c) {
            return false;
        } else {
            int i1 = e(iblockaccess.getData(i, j, k));

            return i1 == 0 && l == 3 ? true : (i1 == 1 && l == 4 ? true : (i1 == 2 && l == 2 ? true : i1 == 3 && l == 5));
        }
    }

    public void doPhysics(World world, int i, int j, int k, int l) {
        if (!this.d(world, i, j, k)) {
            this.c(world, i, j, k, world.getData(i, j, k), 0);
            world.setTypeId(i, j, k, 0);
            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 {
            int i1 = world.getData(i, j, k);
            boolean flag = this.e(world, i, j, k, i1);

            if (!flag) {
                boolean flag1 = this.i(world, i, j, k, i1);
                int j1 = (i1 & 12) >> 2;

                if (this.c && !flag1 || !this.c && flag1) {
                    byte b0 = 0;

                    if (this.d(world, i, j, k, i1)) {
                        b0 = -1;
                    }

                    world.a(i, j, k, this.id, b[j1] * 2, b0);
                }
            }
        }
    }

    private boolean i(World world, int i, int j, int k, int l) {
        int i1 = e(l);

        switch (i1) {
        case 0:
            return world.isBlockFaceIndirectlyPowered(i, j, k + 1, 3) || world.getTypeId(i, j, k + 1) == Block.REDSTONE_WIRE.id && world.getData(i, j, k + 1) > 0;

        case 1:
            return world.isBlockFaceIndirectlyPowered(i - 1, j, k, 4) || world.getTypeId(i - 1, j, k) == Block.REDSTONE_WIRE.id && world.getData(i - 1, j, k) > 0;

        case 2:
            return world.isBlockFaceIndirectlyPowered(i, j, k - 1, 2) || world.getTypeId(i, j, k - 1) == Block.REDSTONE_WIRE.id && world.getData(i, j, k - 1) > 0;

        case 3:
            return world.isBlockFaceIndirectlyPowered(i + 1, j, k, 5) || world.getTypeId(i + 1, j, k) == Block.REDSTONE_WIRE.id && world.getData(i + 1, j, k) > 0;

        default:
            return false;
        }
    }

    public boolean e(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        int i1 = e(l);

        switch (i1) {
        case 0:
        case 2:
            return iblockaccess.isBlockFacePowered(i - 1, j, k, 4) && c(iblockaccess.getTypeId(i - 1, j, k)) || iblockaccess.isBlockFacePowered(i + 1, j, k, 5) && c(iblockaccess.getTypeId(i + 1, j, k));

        case 1:
        case 3:
            return iblockaccess.isBlockFacePowered(i, j, k + 1, 3) && c(iblockaccess.getTypeId(i, j, k + 1)) || iblockaccess.isBlockFacePowered(i, j, k - 1, 2) && c(iblockaccess.getTypeId(i, j, k - 1));

        default:
            return false;
        }
    }

    public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman, int l, float f, float f1, float f2) {
        int i1 = world.getData(i, j, k);
        int j1 = (i1 & 12) >> 2;

        j1 = j1 + 1 << 2 & 12;
        world.setData(i, j, k, j1 | i1 & 3);
        return true;
    }

    public boolean isPowerSource() {
        return true;
    }

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

        world.setData(i, j, k, l);
        boolean flag = this.i(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) {
        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);
    }

    public void postBreak(World world, int i, int j, int k, int l) {
        if (this.c) {
            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;
    }

    public int getDropType(int i, Random random, int j) {
        return Item.DIODE.id;
    }

    public static boolean c(int i) {
        return i == Block.DIODE_ON.id || i == Block.DIODE_OFF.id;
    }

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

        if (c(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 = e(j1);

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