BlockSnow .java

net.minecraft.block.BlockSnow (class, 177 lines): extends Block. members: getBoundsForLayers, LAYERS, isReplaceable, harvestBlock, isPassable, updateTick.

net.minecraft.blockclass177 linescommonextends Block5.7 KB

API Surface (18)

boolean isPassable(IBlockAccess worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
void setBlockBoundsForItemRender()
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void getBoundsForLayers(int p_150154_1_)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
Item getItemDropped(IBlockState state, Random rand, int fortune)
int quantityDropped(Random random)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
IBlockState getStateFromMeta(int meta)
boolean isReplaceable(World worldIn, BlockPos pos)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

LAYERS

String literals (1)

"layers"

Full Source

BlockSnow.java177 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.PropertyInteger;
7
import net.minecraft.block.state.BlockState;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.creativetab.CreativeTabs;
10
import net.minecraft.entity.player.EntityPlayer;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.init.Items;
13
import net.minecraft.item.Item;
14
import net.minecraft.item.ItemStack;
15
import net.minecraft.stats.StatList;
16
import net.minecraft.tileentity.TileEntity;
17
import net.minecraft.util.AxisAlignedBB;
18
import net.minecraft.util.BlockPos;
19
import net.minecraft.util.EnumFacing;
20
import net.minecraft.world.EnumSkyBlock;
21
import net.minecraft.world.IBlockAccess;
22
import net.minecraft.world.World;
23
24
public class BlockSnow extends Block
25
{
26
    public static final PropertyInteger LAYERS = PropertyInteger.create("layers", 1, 8);
27
28
    protected BlockSnow()
29
    {
30
        super(Material.snow);
31
        this.setDefaultState(this.blockState.getBaseState().withProperty(LAYERS, Integer.valueOf(1)));
32
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
33
        this.setTickRandomly(true);
34
        this.setCreativeTab(CreativeTabs.tabDecorations);
35
        this.setBlockBoundsForItemRender();
36
    }
37
38
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
39
    {
40
        return ((Integer)worldIn.getBlockState(pos).getValue(LAYERS)).intValue() < 5;
41
    }
42
43
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
44
    {
45
        int i = ((Integer)state.getValue(LAYERS)).intValue() - 1;
46
        float f = 0.125F;
47
        return new AxisAlignedBB((double)pos.getX() + this.minX, (double)pos.getY() + this.minY, (double)pos.getZ() + this.minZ, (double)pos.getX() + this.maxX, (double)((float)pos.getY() + (float)i * f), (double)pos.getZ() + this.maxZ);
48
    }
49
50
    /**
51
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
52
     */
53
    public boolean isOpaqueCube()
54
    {
55
        return false;
56
    }
57
58
    public boolean isFullCube()
59
    {
60
        return false;
61
    }
62
63
    /**
64
     * Sets the block's bounds for rendering it as an item
65
     */
66
    public void setBlockBoundsForItemRender()
67
    {
68
        this.getBoundsForLayers(0);
69
    }
70
71
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
72
    {
73
        IBlockState iblockstate = worldIn.getBlockState(pos);
74
        this.getBoundsForLayers(((Integer)iblockstate.getValue(LAYERS)).intValue());
75
    }
76
77
    protected void getBoundsForLayers(int p_150154_1_)
78
    {
79
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, (float)p_150154_1_ / 8.0F, 1.0F);
80
    }
81
82
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
83
    {
84
        IBlockState iblockstate = worldIn.getBlockState(pos.down());
85
        Block block = iblockstate.getBlock();
86
        return block != Blocks.ice && block != Blocks.packed_ice ? (block.getMaterial() == Material.leaves ? true : (block == this && ((Integer)iblockstate.getValue(LAYERS)).intValue() >= 7 ? true : block.isOpaqueCube() && block.blockMaterial.blocksMovement())) : false;
87
    }
88
89
    /**
90
     * Called when a neighboring block changes.
91
     */
92
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
93
    {
94
        this.checkAndDropBlock(worldIn, pos, state);
95
    }
96
97
    private boolean checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
98
    {
99
        if (!this.canPlaceBlockAt(worldIn, pos))
100
        {
101
            this.dropBlockAsItem(worldIn, pos, state, 0);
102
            worldIn.setBlockToAir(pos);
103
            return false;
104
        }
105
        else
106
        {
107
            return true;
108
        }
109
    }
110
111
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
112
    {
113
        spawnAsEntity(worldIn, pos, new ItemStack(Items.snowball, ((Integer)state.getValue(LAYERS)).intValue() + 1, 0));
114
        worldIn.setBlockToAir(pos);
115
        player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]);
116
    }
117
118
    /**
119
     * Get the Item that this Block should drop when harvested.
120
     */
121
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
122
    {
123
        return Items.snowball;
124
    }
125
126
    /**
127
     * Returns the quantity of items to drop on block destruction.
128
     */
129
    public int quantityDropped(Random random)
130
    {
131
        return 0;
132
    }
133
134
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
135
    {
136
        if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11)
137
        {
138
            this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
139
            worldIn.setBlockToAir(pos);
140
        }
141
    }
142
143
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
144
    {
145
        return side == EnumFacing.UP ? true : super.shouldSideBeRendered(worldIn, pos, side);
146
    }
147
148
    /**
149
     * Convert the given metadata into a BlockState for this Block
150
     */
151
    public IBlockState getStateFromMeta(int meta)
152
    {
153
        return this.getDefaultState().withProperty(LAYERS, Integer.valueOf((meta & 7) + 1));
154
    }
155
156
    /**
157
     * Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
158
     */
159
    public boolean isReplaceable(World worldIn, BlockPos pos)
160
    {
161
        return ((Integer)worldIn.getBlockState(pos).getValue(LAYERS)).intValue() == 1;
162
    }
163
164
    /**
165
     * Convert the BlockState into the correct metadata value
166
     */
167
    public int getMetaFromState(IBlockState state)
168
    {
169
        return ((Integer)state.getValue(LAYERS)).intValue() - 1;
170
    }
171
172
    protected BlockState createBlockState()
173
    {
174
        return new BlockState(this, new IProperty[] {LAYERS});
175
    }
176
}
177

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