BlockPistonExtension .java

net.minecraft.block.BlockPistonExtension (class): members: applyHeadBounds, EnumPistonType, SHORT, onBlockHarvested, TYPE, canPlaceBlockOnSide, getFacing.

net.minecraft.blockclass280 linescommonextends Block8.7 KB

API Surface (19)

void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
void breakBlock(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
int quantityDropped(Random random)
void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void applyHeadBounds(IBlockState state)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
EnumFacing getFacing(int meta)
Item getItem(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
String toString()
String getName()

Fields & Constants (3)

FACING
TYPE
SHORT

String literals (4)

"facing"
"short"
"normal"
"sticky"

Full Source

BlockPistonExtension.java280 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.List;
4
import java.util.Random;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyBool;
8
import net.minecraft.block.properties.PropertyDirection;
9
import net.minecraft.block.properties.PropertyEnum;
10
import net.minecraft.block.state.BlockState;
11
import net.minecraft.block.state.IBlockState;
12
import net.minecraft.entity.Entity;
13
import net.minecraft.entity.player.EntityPlayer;
14
import net.minecraft.init.Blocks;
15
import net.minecraft.item.Item;
16
import net.minecraft.util.AxisAlignedBB;
17
import net.minecraft.util.BlockPos;
18
import net.minecraft.util.EnumFacing;
19
import net.minecraft.util.IStringSerializable;
20
import net.minecraft.world.IBlockAccess;
21
import net.minecraft.world.World;
22
23
public class BlockPistonExtension extends Block
24
{
25
    public static final PropertyDirection FACING = PropertyDirection.create("facing");
26
    public static final PropertyEnum<BlockPistonExtension.EnumPistonType> TYPE = PropertyEnum.<BlockPistonExtension.EnumPistonType>create("type", BlockPistonExtension.EnumPistonType.class);
27
    public static final PropertyBool SHORT = PropertyBool.create("short");
28
29
    public BlockPistonExtension()
30
    {
31
        super(Material.piston);
32
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(TYPE, BlockPistonExtension.EnumPistonType.DEFAULT).withProperty(SHORT, Boolean.valueOf(false)));
33
        this.setStepSound(soundTypePiston);
34
        this.setHardness(0.5F);
35
    }
36
37
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
38
    {
39
        if (player.capabilities.isCreativeMode)
40
        {
41
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
42
43
            if (enumfacing != null)
44
            {
45
                BlockPos blockpos = pos.offset(enumfacing.getOpposite());
46
                Block block = worldIn.getBlockState(blockpos).getBlock();
47
48
                if (block == Blocks.piston || block == Blocks.sticky_piston)
49
                {
50
                    worldIn.setBlockToAir(blockpos);
51
                }
52
            }
53
        }
54
55
        super.onBlockHarvested(worldIn, pos, state, player);
56
    }
57
58
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
59
    {
60
        super.breakBlock(worldIn, pos, state);
61
        EnumFacing enumfacing = ((EnumFacing)state.getValue(FACING)).getOpposite();
62
        pos = pos.offset(enumfacing);
63
        IBlockState iblockstate = worldIn.getBlockState(pos);
64
65
        if ((iblockstate.getBlock() == Blocks.piston || iblockstate.getBlock() == Blocks.sticky_piston) && ((Boolean)iblockstate.getValue(BlockPistonBase.EXTENDED)).booleanValue())
66
        {
67
            iblockstate.getBlock().dropBlockAsItem(worldIn, pos, iblockstate, 0);
68
            worldIn.setBlockToAir(pos);
69
        }
70
    }
71
72
    /**
73
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
74
     */
75
    public boolean isOpaqueCube()
76
    {
77
        return false;
78
    }
79
80
    public boolean isFullCube()
81
    {
82
        return false;
83
    }
84
85
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
86
    {
87
        return false;
88
    }
89
90
    /**
91
     * Check whether this Block can be placed on the given side
92
     */
93
    public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
94
    {
95
        return false;
96
    }
97
98
    /**
99
     * Returns the quantity of items to drop on block destruction.
100
     */
101
    public int quantityDropped(Random random)
102
    {
103
        return 0;
104
    }
105
106
    /**
107
     * Add all collision boxes of this Block to the list that intersect with the given mask.
108
     */
109
    public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
110
    {
111
        this.applyHeadBounds(state);
112
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
113
        this.applyCoreBounds(state);
114
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
115
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
116
    }
117
118
    private void applyCoreBounds(IBlockState state)
119
    {
120
        float f = 0.25F;
121
        float f1 = 0.375F;
122
        float f2 = 0.625F;
123
        float f3 = 0.25F;
124
        float f4 = 0.75F;
125
126
        switch ((EnumFacing)state.getValue(FACING))
127
        {
128
            case DOWN:
129
                this.setBlockBounds(0.375F, 0.25F, 0.375F, 0.625F, 1.0F, 0.625F);
130
                break;
131
132
            case UP:
133
                this.setBlockBounds(0.375F, 0.0F, 0.375F, 0.625F, 0.75F, 0.625F);
134
                break;
135
136
            case NORTH:
137
                this.setBlockBounds(0.25F, 0.375F, 0.25F, 0.75F, 0.625F, 1.0F);
138
                break;
139
140
            case SOUTH:
141
                this.setBlockBounds(0.25F, 0.375F, 0.0F, 0.75F, 0.625F, 0.75F);
142
                break;
143
144
            case WEST:
145
                this.setBlockBounds(0.375F, 0.25F, 0.25F, 0.625F, 0.75F, 1.0F);
146
                break;
147
148
            case EAST:
149
                this.setBlockBounds(0.0F, 0.375F, 0.25F, 0.75F, 0.625F, 0.75F);
150
        }
151
    }
152
153
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
154
    {
155
        this.applyHeadBounds(worldIn.getBlockState(pos));
156
    }
157
158
    public void applyHeadBounds(IBlockState state)
159
    {
160
        float f = 0.25F;
161
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
162
163
        if (enumfacing != null)
164
        {
165
            switch (enumfacing)
166
            {
167
                case DOWN:
168
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
169
                    break;
170
171
                case UP:
172
                    this.setBlockBounds(0.0F, 0.75F, 0.0F, 1.0F, 1.0F, 1.0F);
173
                    break;
174
175
                case NORTH:
176
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.25F);
177
                    break;
178
179
                case SOUTH:
180
                    this.setBlockBounds(0.0F, 0.0F, 0.75F, 1.0F, 1.0F, 1.0F);
181
                    break;
182
183
                case WEST:
184
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.25F, 1.0F, 1.0F);
185
                    break;
186
187
                case EAST:
188
                    this.setBlockBounds(0.75F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
189
            }
190
        }
191
    }
192
193
    /**
194
     * Called when a neighboring block changes.
195
     */
196
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
197
    {
198
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
199
        BlockPos blockpos = pos.offset(enumfacing.getOpposite());
200
        IBlockState iblockstate = worldIn.getBlockState(blockpos);
201
202
        if (iblockstate.getBlock() != Blocks.piston && iblockstate.getBlock() != Blocks.sticky_piston)
203
        {
204
            worldIn.setBlockToAir(pos);
205
        }
206
        else
207
        {
208
            iblockstate.getBlock().onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
209
        }
210
    }
211
212
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
213
    {
214
        return true;
215
    }
216
217
    public static EnumFacing getFacing(int meta)
218
    {
219
        int i = meta & 7;
220
        return i > 5 ? null : EnumFacing.getFront(i);
221
    }
222
223
    public Item getItem(World worldIn, BlockPos pos)
224
    {
225
        return worldIn.getBlockState(pos).getValue(TYPE) == BlockPistonExtension.EnumPistonType.STICKY ? Item.getItemFromBlock(Blocks.sticky_piston) : Item.getItemFromBlock(Blocks.piston);
226
    }
227
228
    /**
229
     * Convert the given metadata into a BlockState for this Block
230
     */
231
    public IBlockState getStateFromMeta(int meta)
232
    {
233
        return this.getDefaultState().withProperty(FACING, getFacing(meta)).withProperty(TYPE, (meta & 8) > 0 ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT);
234
    }
235
236
    /**
237
     * Convert the BlockState into the correct metadata value
238
     */
239
    public int getMetaFromState(IBlockState state)
240
    {
241
        int i = 0;
242
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
243
244
        if (state.getValue(TYPE) == BlockPistonExtension.EnumPistonType.STICKY)
245
        {
246
            i |= 8;
247
        }
248
249
        return i;
250
    }
251
252
    protected BlockState createBlockState()
253
    {
254
        return new BlockState(this, new IProperty[] {FACING, TYPE, SHORT});
255
    }
256
257
    public static enum EnumPistonType implements IStringSerializable
258
    {
259
        DEFAULT("normal"),
260
        STICKY("sticky");
261
262
        private final String VARIANT;
263
264
        private EnumPistonType(String name)
265
        {
266
            this.VARIANT = name;
267
        }
268
269
        public String toString()
270
        {
271
            return this.VARIANT;
272
        }
273
274
        public String getName()
275
        {
276
            return this.VARIANT;
277
        }
278
    }
279
}
280

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