ItemSign .java

net.minecraft.item.ItemSign (class): members: onItemUse. imports: BlockStandingSign, BlockWallSign, TileEntitySign, TileEntity, CreativeTabs, EnumFacing.

net.minecraft.itemclass77 linescommonextends Item2.4 KB

API Surface (1)

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

Full Source

ItemSign.java77 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.block.BlockStandingSign;
4
import net.minecraft.block.BlockWallSign;
5
import net.minecraft.creativetab.CreativeTabs;
6
import net.minecraft.entity.player.EntityPlayer;
7
import net.minecraft.init.Blocks;
8
import net.minecraft.tileentity.TileEntity;
9
import net.minecraft.tileentity.TileEntitySign;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.EnumFacing;
12
import net.minecraft.util.MathHelper;
13
import net.minecraft.world.World;
14
15
public class ItemSign extends Item
16
{
17
    public ItemSign()
18
    {
19
        this.maxStackSize = 16;
20
        this.setCreativeTab(CreativeTabs.tabDecorations);
21
    }
22
23
    /**
24
     * Called when a Block is right-clicked with this Item
25
     */
26
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
27
    {
28
        if (side == EnumFacing.DOWN)
29
        {
30
            return false;
31
        }
32
        else if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid())
33
        {
34
            return false;
35
        }
36
        else
37
        {
38
            pos = pos.offset(side);
39
40
            if (!playerIn.canPlayerEdit(pos, side, stack))
41
            {
42
                return false;
43
            }
44
            else if (!Blocks.standing_sign.canPlaceBlockAt(worldIn, pos))
45
            {
46
                return false;
47
            }
48
            else if (worldIn.isRemote)
49
            {
50
                return true;
51
            }
52
            else
53
            {
54
                if (side == EnumFacing.UP)
55
                {
56
                    int i = MathHelper.floor_double((double)((playerIn.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
57
                    worldIn.setBlockState(pos, Blocks.standing_sign.getDefaultState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3);
58
                }
59
                else
60
                {
61
                    worldIn.setBlockState(pos, Blocks.wall_sign.getDefaultState().withProperty(BlockWallSign.FACING, side), 3);
62
                }
63
64
                --stack.stackSize;
65
                TileEntity tileentity = worldIn.getTileEntity(pos);
66
67
                if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack))
68
                {
69
                    playerIn.openEditSign((TileEntitySign)tileentity);
70
                }
71
72
                return true;
73
            }
74
        }
75
    }
76
}
77

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