BlockAnvil .java

net.minecraft.block.BlockAnvil (class): members: DAMAGE, Anvil, onStartFalling, onEndFalling, getStateForEntityRender, shouldSideBeRendered, FACING.

net.minecraft.blockclass191 linescommonextends BlockFalling6.1 KB

API Surface (19)

boolean isFullCube()
boolean isOpaqueCube()
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
int damageDropped(IBlockState state)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
void onStartFalling(EntityFallingBlock fallingEntity)
void onEndFalling(World worldIn, BlockPos pos)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
IBlockState getStateForEntityRender(IBlockState state)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
String getName()
boolean hasCustomName()
IChatComponent getDisplayName()
Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
String getGuiID()

Fields & Constants (2)

FACING
DAMAGE

String literals (5)

"facing"
"damage"
"anvil"
".name"
"minecraft:anvil"

Full Source

BlockAnvil.java191 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.List;
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.PropertyInteger;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.creativetab.CreativeTabs;
11
import net.minecraft.entity.EntityLivingBase;
12
import net.minecraft.entity.item.EntityFallingBlock;
13
import net.minecraft.entity.player.EntityPlayer;
14
import net.minecraft.entity.player.InventoryPlayer;
15
import net.minecraft.init.Blocks;
16
import net.minecraft.inventory.Container;
17
import net.minecraft.inventory.ContainerRepair;
18
import net.minecraft.item.Item;
19
import net.minecraft.item.ItemStack;
20
import net.minecraft.util.BlockPos;
21
import net.minecraft.util.ChatComponentTranslation;
22
import net.minecraft.util.EnumFacing;
23
import net.minecraft.util.IChatComponent;
24
import net.minecraft.world.IBlockAccess;
25
import net.minecraft.world.IInteractionObject;
26
import net.minecraft.world.World;
27
28
public class BlockAnvil extends BlockFalling
29
{
30
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
31
    public static final PropertyInteger DAMAGE = PropertyInteger.create("damage", 0, 2);
32
33
    protected BlockAnvil()
34
    {
35
        super(Material.anvil);
36
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(DAMAGE, Integer.valueOf(0)));
37
        this.setLightOpacity(0);
38
        this.setCreativeTab(CreativeTabs.tabDecorations);
39
    }
40
41
    public boolean isFullCube()
42
    {
43
        return false;
44
    }
45
46
    /**
47
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
48
     */
49
    public boolean isOpaqueCube()
50
    {
51
        return false;
52
    }
53
54
    /**
55
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
56
     * IBlockstate
57
     */
58
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
59
    {
60
        EnumFacing enumfacing = placer.getHorizontalFacing().rotateY();
61
        return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, enumfacing).withProperty(DAMAGE, Integer.valueOf(meta >> 2));
62
    }
63
64
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
65
    {
66
        if (!worldIn.isRemote)
67
        {
68
            playerIn.displayGui(new BlockAnvil.Anvil(worldIn, pos));
69
        }
70
71
        return true;
72
    }
73
74
    /**
75
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
76
     * returns the metadata of the dropped item based on the old metadata of the block.
77
     */
78
    public int damageDropped(IBlockState state)
79
    {
80
        return ((Integer)state.getValue(DAMAGE)).intValue();
81
    }
82
83
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
84
    {
85
        EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
86
87
        if (enumfacing.getAxis() == EnumFacing.Axis.X)
88
        {
89
            this.setBlockBounds(0.0F, 0.0F, 0.125F, 1.0F, 1.0F, 0.875F);
90
        }
91
        else
92
        {
93
            this.setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 1.0F);
94
        }
95
    }
96
97
    /**
98
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
99
     */
100
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
101
    {
102
        list.add(new ItemStack(itemIn, 1, 0));
103
        list.add(new ItemStack(itemIn, 1, 1));
104
        list.add(new ItemStack(itemIn, 1, 2));
105
    }
106
107
    protected void onStartFalling(EntityFallingBlock fallingEntity)
108
    {
109
        fallingEntity.setHurtEntities(true);
110
    }
111
112
    public void onEndFalling(World worldIn, BlockPos pos)
113
    {
114
        worldIn.playAuxSFX(1022, pos, 0);
115
    }
116
117
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
118
    {
119
        return true;
120
    }
121
122
    /**
123
     * Possibly modify the given BlockState before rendering it on an Entity (Minecarts, Endermen, ...)
124
     */
125
    public IBlockState getStateForEntityRender(IBlockState state)
126
    {
127
        return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH);
128
    }
129
130
    /**
131
     * Convert the given metadata into a BlockState for this Block
132
     */
133
    public IBlockState getStateFromMeta(int meta)
134
    {
135
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)).withProperty(DAMAGE, Integer.valueOf((meta & 15) >> 2));
136
    }
137
138
    /**
139
     * Convert the BlockState into the correct metadata value
140
     */
141
    public int getMetaFromState(IBlockState state)
142
    {
143
        int i = 0;
144
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
145
        i = i | ((Integer)state.getValue(DAMAGE)).intValue() << 2;
146
        return i;
147
    }
148
149
    protected BlockState createBlockState()
150
    {
151
        return new BlockState(this, new IProperty[] {FACING, DAMAGE});
152
    }
153
154
    public static class Anvil implements IInteractionObject
155
    {
156
        private final World world;
157
        private final BlockPos position;
158
159
        public Anvil(World worldIn, BlockPos pos)
160
        {
161
            this.world = worldIn;
162
            this.position = pos;
163
        }
164
165
        public String getName()
166
        {
167
            return "anvil";
168
        }
169
170
        public boolean hasCustomName()
171
        {
172
            return false;
173
        }
174
175
        public IChatComponent getDisplayName()
176
        {
177
            return new ChatComponentTranslation(Blocks.anvil.getUnlocalizedName() + ".name", new Object[0]);
178
        }
179
180
        public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
181
        {
182
            return new ContainerRepair(playerInventory, this.world, this.position, playerIn);
183
        }
184
185
        public String getGuiID()
186
        {
187
            return "minecraft:anvil";
188
        }
189
    }
190
}
191

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