-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockDoor.java
More file actions
253 lines (234 loc) · 7.5 KB
/
BlockDoor.java
File metadata and controls
253 lines (234 loc) · 7.5 KB
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
package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.util.Random;
public class BlockDoor extends Block
{
protected BlockDoor(int i, Material material)
{
super(i, material);
blockIndexInTexture = 97;
if(material == Material.iron)
{
blockIndexInTexture++;
}
float f = 0.5F;
float f1 = 1.0F;
setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
}
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
if(i == 0 || i == 1)
{
return blockIndexInTexture;
}
int k = func_312_c(j);
if((k == 0 || k == 2) ^ (i <= 3))
{
return blockIndexInTexture;
}
int l = k / 2 + (i & 1 ^ k);
l += (j & 4) / 4;
int i1 = blockIndexInTexture - (j & 8) * 2;
if((l & 1) != 0)
{
i1 = -i1;
}
return i1;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public int getRenderType()
{
return 7;
}
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k)
{
setBlockBoundsBasedOnState(world, i, j, k);
return super.getSelectedBoundingBoxFromPool(world, i, j, k);
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
{
setBlockBoundsBasedOnState(world, i, j, k);
return super.getCollisionBoundingBoxFromPool(world, i, j, k);
}
public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, int i, int j, int k)
{
func_313_b(func_312_c(iblockaccess.getBlockMetadata(i, j, k)));
}
public void func_313_b(int i)
{
float f = 0.1875F;
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
if(i == 0)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
if(i == 1)
{
setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
if(i == 2)
{
setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
if(i == 3)
{
setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
{
blockActivated(world, i, j, k, entityplayer);
}
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
if(blockMaterial == Material.iron)
{
return true;
}
int l = world.getBlockMetadata(i, j, k);
if((l & 8) != 0)
{
if(world.getBlockId(i, j - 1, k) == blockID)
{
blockActivated(world, i, j - 1, k, entityplayer);
}
return true;
}
if(world.getBlockId(i, j + 1, k) == blockID)
{
world.setBlockMetadataWithNotify(i, j + 1, k, (l ^ 4) + 8);
}
world.setBlockMetadataWithNotify(i, j, k, l ^ 4);
world.markBlocksDirty(i, j - 1, k, i, j, k);
if(Math.random() < 0.5D)
{
world.playSoundEffect((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, "random.door_open", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
} else
{
world.playSoundEffect((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, "random.door_close", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
}
return true;
}
public void func_311_a(World world, int i, int j, int k, boolean flag)
{
int l = world.getBlockMetadata(i, j, k);
if((l & 8) != 0)
{
if(world.getBlockId(i, j - 1, k) == blockID)
{
func_311_a(world, i, j - 1, k, flag);
}
return;
}
boolean flag1 = (world.getBlockMetadata(i, j, k) & 4) > 0;
if(flag1 == flag)
{
return;
}
if(world.getBlockId(i, j + 1, k) == blockID)
{
world.setBlockMetadataWithNotify(i, j + 1, k, (l ^ 4) + 8);
}
world.setBlockMetadataWithNotify(i, j, k, l ^ 4);
world.markBlocksDirty(i, j - 1, k, i, j, k);
if(Math.random() < 0.5D)
{
world.playSoundEffect((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, "random.door_open", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
} else
{
world.playSoundEffect((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, "random.door_close", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
}
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
int i1 = world.getBlockMetadata(i, j, k);
if((i1 & 8) != 0)
{
if(world.getBlockId(i, j - 1, k) != blockID)
{
world.setBlockWithNotify(i, j, k, 0);
}
if(l > 0 && Block.blocksList[l].canProvidePower())
{
onNeighborBlockChange(world, i, j - 1, k, l);
}
} else
{
boolean flag = false;
if(world.getBlockId(i, j + 1, k) != blockID)
{
world.setBlockWithNotify(i, j, k, 0);
flag = true;
}
if(!world.isBlockOpaqueCube(i, j - 1, k))
{
world.setBlockWithNotify(i, j, k, 0);
flag = true;
if(world.getBlockId(i, j + 1, k) == blockID)
{
world.setBlockWithNotify(i, j + 1, k, 0);
}
}
if(flag)
{
if(!world.multiplayerWorld)
{
dropBlockAsItem(world, i, j, k, i1);
}
} else
if(l > 0 && Block.blocksList[l].canProvidePower())
{
boolean flag1 = world.isBlockIndirectlyGettingPowered(i, j, k) || world.isBlockIndirectlyGettingPowered(i, j + 1, k);
func_311_a(world, i, j, k, flag1);
}
}
}
public int idDropped(int i, Random random)
{
if((i & 8) != 0)
{
return 0;
}
if(blockMaterial == Material.iron)
{
return Item.doorSteel.shiftedIndex;
} else
{
return Item.doorWood.shiftedIndex;
}
}
public MovingObjectPosition collisionRayTrace(World world, int i, int j, int k, Vec3D vec3d, Vec3D vec3d1)
{
setBlockBoundsBasedOnState(world, i, j, k);
return super.collisionRayTrace(world, i, j, k, vec3d, vec3d1);
}
public int func_312_c(int i)
{
if((i & 4) == 0)
{
return i - 1 & 3;
} else
{
return i & 3;
}
}
public boolean canPlaceBlockAt(World world, int i, int j, int k)
{
if(j >= 127)
{
return false;
} else
{
return world.isBlockOpaqueCube(i, j - 1, k) && super.canPlaceBlockAt(world, i, j, k) && super.canPlaceBlockAt(world, i, j + 1, k);
}
}
}