BlockDoor .java

net.minecraft.block.BlockDoor (class): members: EnumHingePosition, combineMetadata, removeHalfBit, EnumDoorHalf, isHingeLeft, toggleDoor, isOpen, HINGE.

net.minecraft.blockclass478 linescommonextends Block15.9 KB

API Surface (33)

String getLocalizedName()
boolean isOpaqueCube()
boolean isPassable(IBlockAccess worldIn, BlockPos pos)
boolean isFullCube()
AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void toggleDoor(World worldIn, BlockPos pos, boolean open)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
Item getItemDropped(IBlockState state, Random rand, int fortune)
MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
int getMobilityFlag()
int combineMetadata(IBlockAccess worldIn, BlockPos pos)
Item getItem(World worldIn, BlockPos pos)
void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
EnumWorldBlockLayer getBlockLayer()
IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
int removeHalfBit(int meta)
boolean isOpen(IBlockAccess worldIn, BlockPos pos)
EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
EnumFacing getFacing(int combinedMeta)
boolean isOpen(int combinedMeta)
boolean isTop(int meta)
boolean isHingeLeft(int combinedMeta)
BlockState createBlockState()
String toString()
String getName()
String toString()
String getName()

Fields & Constants (5)

FACING
OPEN
HINGE
POWERED
HALF

String literals (12)

"facing"
"open"
"hinge"
"powered"
"half"
".name"
"tile"
"item"
"upper"
"lower"
"left"
"right"

Full Source

BlockDoor.java478 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.properties.IProperty;
6
import net.minecraft.block.properties.PropertyBool;
7
import net.minecraft.block.properties.PropertyDirection;
8
import net.minecraft.block.properties.PropertyEnum;
9
import net.minecraft.block.state.BlockState;
10
import net.minecraft.block.state.IBlockState;
11
import net.minecraft.entity.player.EntityPlayer;
12
import net.minecraft.init.Blocks;
13
import net.minecraft.init.Items;
14
import net.minecraft.item.Item;
15
import net.minecraft.util.AxisAlignedBB;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.util.EnumWorldBlockLayer;
19
import net.minecraft.util.IStringSerializable;
20
import net.minecraft.util.MovingObjectPosition;
21
import net.minecraft.util.StatCollector;
22
import net.minecraft.util.Vec3;
23
import net.minecraft.world.IBlockAccess;
24
import net.minecraft.world.World;
25
26
public class BlockDoor extends Block
27
{
28
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
29
    public static final PropertyBool OPEN = PropertyBool.create("open");
30
    public static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = PropertyEnum.<BlockDoor.EnumHingePosition>create("hinge", BlockDoor.EnumHingePosition.class);
31
    public static final PropertyBool POWERED = PropertyBool.create("powered");
32
    public static final PropertyEnum<BlockDoor.EnumDoorHalf> HALF = PropertyEnum.<BlockDoor.EnumDoorHalf>create("half", BlockDoor.EnumDoorHalf.class);
33
34
    protected BlockDoor(Material materialIn)
35
    {
36
        super(materialIn);
37
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
38
    }
39
40
    /**
41
     * Gets the localized name of this block. Used for the statistics page.
42
     */
43
    public String getLocalizedName()
44
    {
45
        return StatCollector.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
46
    }
47
48
    /**
49
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
50
     */
51
    public boolean isOpaqueCube()
52
    {
53
        return false;
54
    }
55
56
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
57
    {
58
        return isOpen(combineMetadata(worldIn, pos));
59
    }
60
61
    public boolean isFullCube()
62
    {
63
        return false;
64
    }
65
66
    public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
67
    {
68
        this.setBlockBoundsBasedOnState(worldIn, pos);
69
        return super.getSelectedBoundingBox(worldIn, pos);
70
    }
71
72
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
73
    {
74
        this.setBlockBoundsBasedOnState(worldIn, pos);
75
        return super.getCollisionBoundingBox(worldIn, pos, state);
76
    }
77
78
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
79
    {
80
        this.setBoundBasedOnMeta(combineMetadata(worldIn, pos));
81
    }
82
83
    private void setBoundBasedOnMeta(int combinedMeta)
84
    {
85
        float f = 0.1875F;
86
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
87
        EnumFacing enumfacing = getFacing(combinedMeta);
88
        boolean flag = isOpen(combinedMeta);
89
        boolean flag1 = isHingeLeft(combinedMeta);
90
91
        if (flag)
92
        {
93
            if (enumfacing == EnumFacing.EAST)
94
            {
95
                if (!flag1)
96
                {
97
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
98
                }
99
                else
100
                {
101
                    this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
102
                }
103
            }
104
            else if (enumfacing == EnumFacing.SOUTH)
105
            {
106
                if (!flag1)
107
                {
108
                    this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
109
                }
110
                else
111
                {
112
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
113
                }
114
            }
115
            else if (enumfacing == EnumFacing.WEST)
116
            {
117
                if (!flag1)
118
                {
119
                    this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
120
                }
121
                else
122
                {
123
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
124
                }
125
            }
126
            else if (enumfacing == EnumFacing.NORTH)
127
            {
128
                if (!flag1)
129
                {
130
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
131
                }
132
                else
133
                {
134
                    this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
135
                }
136
            }
137
        }
138
        else if (enumfacing == EnumFacing.EAST)
139
        {
140
            this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
141
        }
142
        else if (enumfacing == EnumFacing.SOUTH)
143
        {
144
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
145
        }
146
        else if (enumfacing == EnumFacing.WEST)
147
        {
148
            this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
149
        }
150
        else if (enumfacing == EnumFacing.NORTH)
151
        {
152
            this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
153
        }
154
    }
155
156
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
157
    {
158
        if (this.blockMaterial == Material.iron)
159
        {
160
            return true;
161
        }
162
        else
163
        {
164
            BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
165
            IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
166
167
            if (iblockstate.getBlock() != this)
168
            {
169
                return false;
170
            }
171
            else
172
            {
173
                state = iblockstate.cycleProperty(OPEN);
174
                worldIn.setBlockState(blockpos, state, 2);
175
                worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
176
                worldIn.playAuxSFXAtEntity(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1003 : 1006, pos, 0);
177
                return true;
178
            }
179
        }
180
    }
181
182
    public void toggleDoor(World worldIn, BlockPos pos, boolean open)
183
    {
184
        IBlockState iblockstate = worldIn.getBlockState(pos);
185
186
        if (iblockstate.getBlock() == this)
187
        {
188
            BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
189
            IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
190
191
            if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
192
            {
193
                worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 2);
194
                worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
195
                worldIn.playAuxSFXAtEntity((EntityPlayer)null, open ? 1003 : 1006, pos, 0);
196
            }
197
        }
198
    }
199
200
    /**
201
     * Called when a neighboring block changes.
202
     */
203
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
204
    {
205
        if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
206
        {
207
            BlockPos blockpos = pos.down();
208
            IBlockState iblockstate = worldIn.getBlockState(blockpos);
209
210
            if (iblockstate.getBlock() != this)
211
            {
212
                worldIn.setBlockToAir(pos);
213
            }
214
            else if (neighborBlock != this)
215
            {
216
                this.onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
217
            }
218
        }
219
        else
220
        {
221
            boolean flag1 = false;
222
            BlockPos blockpos1 = pos.up();
223
            IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
224
225
            if (iblockstate1.getBlock() != this)
226
            {
227
                worldIn.setBlockToAir(pos);
228
                flag1 = true;
229
            }
230
231
            if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()))
232
            {
233
                worldIn.setBlockToAir(pos);
234
                flag1 = true;
235
236
                if (iblockstate1.getBlock() == this)
237
                {
238
                    worldIn.setBlockToAir(blockpos1);
239
                }
240
            }
241
242
            if (flag1)
243
            {
244
                if (!worldIn.isRemote)
245
                {
246
                    this.dropBlockAsItem(worldIn, pos, state, 0);
247
                }
248
            }
249
            else
250
            {
251
                boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
252
253
                if ((flag || neighborBlock.canProvidePower()) && neighborBlock != this && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
254
                {
255
                    worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
256
257
                    if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
258
                    {
259
                        worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
260
                        worldIn.markBlockRangeForRenderUpdate(pos, pos);
261
                        worldIn.playAuxSFXAtEntity((EntityPlayer)null, flag ? 1003 : 1006, pos, 0);
262
                    }
263
                }
264
            }
265
        }
266
    }
267
268
    /**
269
     * Get the Item that this Block should drop when harvested.
270
     */
271
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
272
    {
273
        return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : this.getItem();
274
    }
275
276
    /**
277
     * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit.
278
     */
279
    public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
280
    {
281
        this.setBlockBoundsBasedOnState(worldIn, pos);
282
        return super.collisionRayTrace(worldIn, pos, start, end);
283
    }
284
285
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
286
    {
287
        return pos.getY() >= 255 ? false : World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up());
288
    }
289
290
    public int getMobilityFlag()
291
    {
292
        return 1;
293
    }
294
295
    public static int combineMetadata(IBlockAccess worldIn, BlockPos pos)
296
    {
297
        IBlockState iblockstate = worldIn.getBlockState(pos);
298
        int i = iblockstate.getBlock().getMetaFromState(iblockstate);
299
        boolean flag = isTop(i);
300
        IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
301
        int j = iblockstate1.getBlock().getMetaFromState(iblockstate1);
302
        int k = flag ? j : i;
303
        IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
304
        int l = iblockstate2.getBlock().getMetaFromState(iblockstate2);
305
        int i1 = flag ? i : l;
306
        boolean flag1 = (i1 & 1) != 0;
307
        boolean flag2 = (i1 & 2) != 0;
308
        return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0);
309
    }
310
311
    public Item getItem(World worldIn, BlockPos pos)
312
    {
313
        return this.getItem();
314
    }
315
316
    private Item getItem()
317
    {
318
        return this == Blocks.iron_door ? Items.iron_door : (this == Blocks.spruce_door ? Items.spruce_door : (this == Blocks.birch_door ? Items.birch_door : (this == Blocks.jungle_door ? Items.jungle_door : (this == Blocks.acacia_door ? Items.acacia_door : (this == Blocks.dark_oak_door ? Items.dark_oak_door : Items.oak_door)))));
319
    }
320
321
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
322
    {
323
        BlockPos blockpos = pos.down();
324
325
        if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
326
        {
327
            worldIn.setBlockToAir(blockpos);
328
        }
329
    }
330
331
    public EnumWorldBlockLayer getBlockLayer()
332
    {
333
        return EnumWorldBlockLayer.CUTOUT;
334
    }
335
336
    /**
337
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
338
     * metadata, such as fence connections.
339
     */
340
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
341
    {
342
        if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER)
343
        {
344
            IBlockState iblockstate = worldIn.getBlockState(pos.up());
345
346
            if (iblockstate.getBlock() == this)
347
            {
348
                state = state.withProperty(HINGE, iblockstate.getValue(HINGE)).withProperty(POWERED, iblockstate.getValue(POWERED));
349
            }
350
        }
351
        else
352
        {
353
            IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
354
355
            if (iblockstate1.getBlock() == this)
356
            {
357
                state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN));
358
            }
359
        }
360
361
        return state;
362
    }
363
364
    /**
365
     * Convert the given metadata into a BlockState for this Block
366
     */
367
    public IBlockState getStateFromMeta(int meta)
368
    {
369
        return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf((meta & 2) > 0)) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
370
    }
371
372
    /**
373
     * Convert the BlockState into the correct metadata value
374
     */
375
    public int getMetaFromState(IBlockState state)
376
    {
377
        int i = 0;
378
379
        if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
380
        {
381
            i = i | 8;
382
383
            if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
384
            {
385
                i |= 1;
386
            }
387
388
            if (((Boolean)state.getValue(POWERED)).booleanValue())
389
            {
390
                i |= 2;
391
            }
392
        }
393
        else
394
        {
395
            i = i | ((EnumFacing)state.getValue(FACING)).rotateY().getHorizontalIndex();
396
397
            if (((Boolean)state.getValue(OPEN)).booleanValue())
398
            {
399
                i |= 4;
400
            }
401
        }
402
403
        return i;
404
    }
405
406
    protected static int removeHalfBit(int meta)
407
    {
408
        return meta & 7;
409
    }
410
411
    public static boolean isOpen(IBlockAccess worldIn, BlockPos pos)
412
    {
413
        return isOpen(combineMetadata(worldIn, pos));
414
    }
415
416
    public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
417
    {
418
        return getFacing(combineMetadata(worldIn, pos));
419
    }
420
421
    public static EnumFacing getFacing(int combinedMeta)
422
    {
423
        return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
424
    }
425
426
    protected static boolean isOpen(int combinedMeta)
427
    {
428
        return (combinedMeta & 4) != 0;
429
    }
430
431
    protected static boolean isTop(int meta)
432
    {
433
        return (meta & 8) != 0;
434
    }
435
436
    protected static boolean isHingeLeft(int combinedMeta)
437
    {
438
        return (combinedMeta & 16) != 0;
439
    }
440
441
    protected BlockState createBlockState()
442
    {
443
        return new BlockState(this, new IProperty[] {HALF, FACING, OPEN, HINGE, POWERED});
444
    }
445
446
    public static enum EnumDoorHalf implements IStringSerializable
447
    {
448
        UPPER,
449
        LOWER;
450
451
        public String toString()
452
        {
453
            return this.getName();
454
        }
455
456
        public String getName()
457
        {
458
            return this == UPPER ? "upper" : "lower";
459
        }
460
    }
461
462
    public static enum EnumHingePosition implements IStringSerializable
463
    {
464
        LEFT,
465
        RIGHT;
466
467
        public String toString()
468
        {
469
            return this.getName();
470
        }
471
472
        public String getName()
473
        {
474
            return this == LEFT ? "left" : "right";
475
        }
476
    }
477
}
478

Deobfuscated MCP 1.8.9 source of BlockDoor from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/BlockDoor.java), stored verbatim.