BlockPistonMoving .java

net.minecraft.block.BlockPistonMoving (class): members: newTileEntity, getBoundingBox, onBlockDestroyedByPlayer, collisionRayTrace, TYPE, FACING, getItem.

net.minecraft.blockclass313 linescommonextends BlockContainer9.9 KB

API Surface (20)

TileEntity createNewTileEntity(World worldIn, int meta)
TileEntity newTileEntity(IBlockState state, EnumFacing facing, boolean extending, boolean renderHead)
void breakBlock(World worldIn, BlockPos pos, IBlockState state)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
Item getItemDropped(IBlockState state, Random rand, int fortune)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
AxisAlignedBB getBoundingBox(World worldIn, BlockPos pos, IBlockState extendingBlock, float progress, EnumFacing direction)
Item getItem(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (2)

FACING
TYPE

Full Source

BlockPistonMoving.java313 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.PropertyDirection;
7
import net.minecraft.block.properties.PropertyEnum;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.entity.player.EntityPlayer;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.item.Item;
13
import net.minecraft.tileentity.TileEntity;
14
import net.minecraft.tileentity.TileEntityPiston;
15
import net.minecraft.util.AxisAlignedBB;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.util.MovingObjectPosition;
19
import net.minecraft.util.Vec3;
20
import net.minecraft.world.IBlockAccess;
21
import net.minecraft.world.World;
22
23
public class BlockPistonMoving extends BlockContainer
24
{
25
    public static final PropertyDirection FACING = BlockPistonExtension.FACING;
26
    public static final PropertyEnum<BlockPistonExtension.EnumPistonType> TYPE = BlockPistonExtension.TYPE;
27
28
    public BlockPistonMoving()
29
    {
30
        super(Material.piston);
31
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(TYPE, BlockPistonExtension.EnumPistonType.DEFAULT));
32
        this.setHardness(-1.0F);
33
    }
34
35
    /**
36
     * Returns a new instance of a block's tile entity class. Called on placing the block.
37
     */
38
    public TileEntity createNewTileEntity(World worldIn, int meta)
39
    {
40
        return null;
41
    }
42
43
    public static TileEntity newTileEntity(IBlockState state, EnumFacing facing, boolean extending, boolean renderHead)
44
    {
45
        return new TileEntityPiston(state, facing, extending, renderHead);
46
    }
47
48
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
49
    {
50
        TileEntity tileentity = worldIn.getTileEntity(pos);
51
52
        if (tileentity instanceof TileEntityPiston)
53
        {
54
            ((TileEntityPiston)tileentity).clearPistonTileEntity();
55
        }
56
        else
57
        {
58
            super.breakBlock(worldIn, pos, state);
59
        }
60
    }
61
62
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
63
    {
64
        return false;
65
    }
66
67
    /**
68
     * Check whether this Block can be placed on the given side
69
     */
70
    public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
71
    {
72
        return false;
73
    }
74
75
    /**
76
     * Called when a player destroys this Block
77
     */
78
    public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
79
    {
80
        BlockPos blockpos = pos.offset(((EnumFacing)state.getValue(FACING)).getOpposite());
81
        IBlockState iblockstate = worldIn.getBlockState(blockpos);
82
83
        if (iblockstate.getBlock() instanceof BlockPistonBase && ((Boolean)iblockstate.getValue(BlockPistonBase.EXTENDED)).booleanValue())
84
        {
85
            worldIn.setBlockToAir(blockpos);
86
        }
87
    }
88
89
    /**
90
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
91
     */
92
    public boolean isOpaqueCube()
93
    {
94
        return false;
95
    }
96
97
    public boolean isFullCube()
98
    {
99
        return false;
100
    }
101
102
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
103
    {
104
        if (!worldIn.isRemote && worldIn.getTileEntity(pos) == null)
105
        {
106
            worldIn.setBlockToAir(pos);
107
            return true;
108
        }
109
        else
110
        {
111
            return false;
112
        }
113
    }
114
115
    /**
116
     * Get the Item that this Block should drop when harvested.
117
     */
118
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
119
    {
120
        return null;
121
    }
122
123
    /**
124
     * Spawns this Block's drops into the World as EntityItems.
125
     */
126
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
127
    {
128
        if (!worldIn.isRemote)
129
        {
130
            TileEntityPiston tileentitypiston = this.getTileEntity(worldIn, pos);
131
132
            if (tileentitypiston != null)
133
            {
134
                IBlockState iblockstate = tileentitypiston.getPistonState();
135
                iblockstate.getBlock().dropBlockAsItem(worldIn, pos, iblockstate, 0);
136
            }
137
        }
138
    }
139
140
    /**
141
     * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit.
142
     */
143
    public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
144
    {
145
        return null;
146
    }
147
148
    /**
149
     * Called when a neighboring block changes.
150
     */
151
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
152
    {
153
        if (!worldIn.isRemote)
154
        {
155
            worldIn.getTileEntity(pos);
156
        }
157
    }
158
159
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
160
    {
161
        TileEntityPiston tileentitypiston = this.getTileEntity(worldIn, pos);
162
163
        if (tileentitypiston == null)
164
        {
165
            return null;
166
        }
167
        else
168
        {
169
            float f = tileentitypiston.getProgress(0.0F);
170
171
            if (tileentitypiston.isExtending())
172
            {
173
                f = 1.0F - f;
174
            }
175
176
            return this.getBoundingBox(worldIn, pos, tileentitypiston.getPistonState(), f, tileentitypiston.getFacing());
177
        }
178
    }
179
180
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
181
    {
182
        TileEntityPiston tileentitypiston = this.getTileEntity(worldIn, pos);
183
184
        if (tileentitypiston != null)
185
        {
186
            IBlockState iblockstate = tileentitypiston.getPistonState();
187
            Block block = iblockstate.getBlock();
188
189
            if (block == this || block.getMaterial() == Material.air)
190
            {
191
                return;
192
            }
193
194
            float f = tileentitypiston.getProgress(0.0F);
195
196
            if (tileentitypiston.isExtending())
197
            {
198
                f = 1.0F - f;
199
            }
200
201
            block.setBlockBoundsBasedOnState(worldIn, pos);
202
203
            if (block == Blocks.piston || block == Blocks.sticky_piston)
204
            {
205
                f = 0.0F;
206
            }
207
208
            EnumFacing enumfacing = tileentitypiston.getFacing();
209
            this.minX = block.getBlockBoundsMinX() - (double)((float)enumfacing.getFrontOffsetX() * f);
210
            this.minY = block.getBlockBoundsMinY() - (double)((float)enumfacing.getFrontOffsetY() * f);
211
            this.minZ = block.getBlockBoundsMinZ() - (double)((float)enumfacing.getFrontOffsetZ() * f);
212
            this.maxX = block.getBlockBoundsMaxX() - (double)((float)enumfacing.getFrontOffsetX() * f);
213
            this.maxY = block.getBlockBoundsMaxY() - (double)((float)enumfacing.getFrontOffsetY() * f);
214
            this.maxZ = block.getBlockBoundsMaxZ() - (double)((float)enumfacing.getFrontOffsetZ() * f);
215
        }
216
    }
217
218
    public AxisAlignedBB getBoundingBox(World worldIn, BlockPos pos, IBlockState extendingBlock, float progress, EnumFacing direction)
219
    {
220
        if (extendingBlock.getBlock() != this && extendingBlock.getBlock().getMaterial() != Material.air)
221
        {
222
            AxisAlignedBB axisalignedbb = extendingBlock.getBlock().getCollisionBoundingBox(worldIn, pos, extendingBlock);
223
224
            if (axisalignedbb == null)
225
            {
226
                return null;
227
            }
228
            else
229
            {
230
                double d0 = axisalignedbb.minX;
231
                double d1 = axisalignedbb.minY;
232
                double d2 = axisalignedbb.minZ;
233
                double d3 = axisalignedbb.maxX;
234
                double d4 = axisalignedbb.maxY;
235
                double d5 = axisalignedbb.maxZ;
236
237
                if (direction.getFrontOffsetX() < 0)
238
                {
239
                    d0 -= (double)((float)direction.getFrontOffsetX() * progress);
240
                }
241
                else
242
                {
243
                    d3 -= (double)((float)direction.getFrontOffsetX() * progress);
244
                }
245
246
                if (direction.getFrontOffsetY() < 0)
247
                {
248
                    d1 -= (double)((float)direction.getFrontOffsetY() * progress);
249
                }
250
                else
251
                {
252
                    d4 -= (double)((float)direction.getFrontOffsetY() * progress);
253
                }
254
255
                if (direction.getFrontOffsetZ() < 0)
256
                {
257
                    d2 -= (double)((float)direction.getFrontOffsetZ() * progress);
258
                }
259
                else
260
                {
261
                    d5 -= (double)((float)direction.getFrontOffsetZ() * progress);
262
                }
263
264
                return new AxisAlignedBB(d0, d1, d2, d3, d4, d5);
265
            }
266
        }
267
        else
268
        {
269
            return null;
270
        }
271
    }
272
273
    private TileEntityPiston getTileEntity(IBlockAccess worldIn, BlockPos pos)
274
    {
275
        TileEntity tileentity = worldIn.getTileEntity(pos);
276
        return tileentity instanceof TileEntityPiston ? (TileEntityPiston)tileentity : null;
277
    }
278
279
    public Item getItem(World worldIn, BlockPos pos)
280
    {
281
        return null;
282
    }
283
284
    /**
285
     * Convert the given metadata into a BlockState for this Block
286
     */
287
    public IBlockState getStateFromMeta(int meta)
288
    {
289
        return this.getDefaultState().withProperty(FACING, BlockPistonExtension.getFacing(meta)).withProperty(TYPE, (meta & 8) > 0 ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT);
290
    }
291
292
    /**
293
     * Convert the BlockState into the correct metadata value
294
     */
295
    public int getMetaFromState(IBlockState state)
296
    {
297
        int i = 0;
298
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
299
300
        if (state.getValue(TYPE) == BlockPistonExtension.EnumPistonType.STICKY)
301
        {
302
            i |= 8;
303
        }
304
305
        return i;
306
    }
307
308
    protected BlockState createBlockState()
309
    {
310
        return new BlockState(this, new IProperty[] {FACING, TYPE});
311
    }
312
}
313

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