ItemSnow .java

net.minecraft.item.ItemSnow (class, 78 lines): extends ItemBlock. members: getMetadata, onItemUse. imports: BlockSnow, AxisAlignedBB, Block, EnumFacing.

net.minecraft.itemclass78 linescommonextends ItemBlock2.7 KB

API Surface (2)

boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
int getMetadata(int damage)

Full Source

ItemSnow.java78 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.BlockSnow;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.entity.player.EntityPlayer;
7
import net.minecraft.util.AxisAlignedBB;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.EnumFacing;
10
import net.minecraft.world.World;
11
12
public class ItemSnow extends ItemBlock
13
{
14
    public ItemSnow(Block block)
15
    {
16
        super(block);
17
        this.setMaxDamage(0);
18
        this.setHasSubtypes(true);
19
    }
20
21
    /**
22
     * Called when a Block is right-clicked with this Item
23
     */
24
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
25
    {
26
        if (stack.stackSize == 0)
27
        {
28
            return false;
29
        }
30
        else if (!playerIn.canPlayerEdit(pos, side, stack))
31
        {
32
            return false;
33
        }
34
        else
35
        {
36
            IBlockState iblockstate = worldIn.getBlockState(pos);
37
            Block block = iblockstate.getBlock();
38
            BlockPos blockpos = pos;
39
40
            if ((side != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
41
            {
42
                blockpos = pos.offset(side);
43
                iblockstate = worldIn.getBlockState(blockpos);
44
                block = iblockstate.getBlock();
45
            }
46
47
            if (block == this.block)
48
            {
49
                int i = ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue();
50
51
                if (i <= 7)
52
                {
53
                    IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, Integer.valueOf(i + 1));
54
                    AxisAlignedBB axisalignedbb = this.block.getCollisionBoundingBox(worldIn, blockpos, iblockstate1);
55
56
                    if (axisalignedbb != null && worldIn.checkNoEntityCollision(axisalignedbb) && worldIn.setBlockState(blockpos, iblockstate1, 2))
57
                    {
58
                        worldIn.playSoundEffect((double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
59
                        --stack.stackSize;
60
                        return true;
61
                    }
62
                }
63
            }
64
65
            return super.onItemUse(stack, playerIn, worldIn, blockpos, side, hitX, hitY, hitZ);
66
        }
67
    }
68
69
    /**
70
     * Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
71
     * placed as a Block (mostly used with ItemBlocks).
72
     */
73
    public int getMetadata(int damage)
74
    {
75
        return damage;
76
    }
77
}
78

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