BlockCake .java

net.minecraft.block.BlockCake (class, 183 lines): members: BITES, onBlockClicked, getSelectedBoundingBox, getComparatorInputOverride, canPlaceBlockAt.

net.minecraft.blockclass183 linescommonextends Block5.3 KB

API Surface (19)

void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void setBlockBoundsForItemRender()
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
boolean isFullCube()
boolean isOpaqueCube()
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
int quantityDropped(Random random)
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
EnumWorldBlockLayer getBlockLayer()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
int getComparatorInputOverride(World worldIn, BlockPos pos)
boolean hasComparatorInputOverride()

Fields & Constants (1)

BITES

String literals (1)

"bites"

Full Source

BlockCake.java183 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.entity.player.EntityPlayer;
10
import net.minecraft.init.Items;
11
import net.minecraft.item.Item;
12
import net.minecraft.stats.StatList;
13
import net.minecraft.util.AxisAlignedBB;
14
import net.minecraft.util.BlockPos;
15
import net.minecraft.util.EnumFacing;
16
import net.minecraft.util.EnumWorldBlockLayer;
17
import net.minecraft.world.IBlockAccess;
18
import net.minecraft.world.World;
19
20
public class BlockCake extends Block
21
{
22
    public static final PropertyInteger BITES = PropertyInteger.create("bites", 0, 6);
23
24
    protected BlockCake()
25
    {
26
        super(Material.cake);
27
        this.setDefaultState(this.blockState.getBaseState().withProperty(BITES, Integer.valueOf(0)));
28
        this.setTickRandomly(true);
29
    }
30
31
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
32
    {
33
        float f = 0.0625F;
34
        float f1 = (float)(1 + ((Integer)worldIn.getBlockState(pos).getValue(BITES)).intValue() * 2) / 16.0F;
35
        float f2 = 0.5F;
36
        this.setBlockBounds(f1, 0.0F, f, 1.0F - f, f2, 1.0F - f);
37
    }
38
39
    /**
40
     * Sets the block's bounds for rendering it as an item
41
     */
42
    public void setBlockBoundsForItemRender()
43
    {
44
        float f = 0.0625F;
45
        float f1 = 0.5F;
46
        this.setBlockBounds(f, 0.0F, f, 1.0F - f, f1, 1.0F - f);
47
    }
48
49
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
50
    {
51
        float f = 0.0625F;
52
        float f1 = (float)(1 + ((Integer)state.getValue(BITES)).intValue() * 2) / 16.0F;
53
        float f2 = 0.5F;
54
        return new AxisAlignedBB((double)((float)pos.getX() + f1), (double)pos.getY(), (double)((float)pos.getZ() + f), (double)((float)(pos.getX() + 1) - f), (double)((float)pos.getY() + f2), (double)((float)(pos.getZ() + 1) - f));
55
    }
56
57
    public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
58
    {
59
        return this.getCollisionBoundingBox(worldIn, pos, worldIn.getBlockState(pos));
60
    }
61
62
    public boolean isFullCube()
63
    {
64
        return false;
65
    }
66
67
    /**
68
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
69
     */
70
    public boolean isOpaqueCube()
71
    {
72
        return false;
73
    }
74
75
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
76
    {
77
        this.eatCake(worldIn, pos, state, playerIn);
78
        return true;
79
    }
80
81
    public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
82
    {
83
        this.eatCake(worldIn, pos, worldIn.getBlockState(pos), playerIn);
84
    }
85
86
    private void eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
87
    {
88
        if (player.canEat(false))
89
        {
90
            player.triggerAchievement(StatList.field_181724_H);
91
            player.getFoodStats().addStats(2, 0.1F);
92
            int i = ((Integer)state.getValue(BITES)).intValue();
93
94
            if (i < 6)
95
            {
96
                worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
97
            }
98
            else
99
            {
100
                worldIn.setBlockToAir(pos);
101
            }
102
        }
103
    }
104
105
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
106
    {
107
        return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
108
    }
109
110
    /**
111
     * Called when a neighboring block changes.
112
     */
113
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
114
    {
115
        if (!this.canBlockStay(worldIn, pos))
116
        {
117
            worldIn.setBlockToAir(pos);
118
        }
119
    }
120
121
    private boolean canBlockStay(World worldIn, BlockPos pos)
122
    {
123
        return worldIn.getBlockState(pos.down()).getBlock().getMaterial().isSolid();
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
    /**
135
     * Get the Item that this Block should drop when harvested.
136
     */
137
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
138
    {
139
        return null;
140
    }
141
142
    public Item getItem(World worldIn, BlockPos pos)
143
    {
144
        return Items.cake;
145
    }
146
147
    public EnumWorldBlockLayer getBlockLayer()
148
    {
149
        return EnumWorldBlockLayer.CUTOUT;
150
    }
151
152
    /**
153
     * Convert the given metadata into a BlockState for this Block
154
     */
155
    public IBlockState getStateFromMeta(int meta)
156
    {
157
        return this.getDefaultState().withProperty(BITES, Integer.valueOf(meta));
158
    }
159
160
    /**
161
     * Convert the BlockState into the correct metadata value
162
     */
163
    public int getMetaFromState(IBlockState state)
164
    {
165
        return ((Integer)state.getValue(BITES)).intValue();
166
    }
167
168
    protected BlockState createBlockState()
169
    {
170
        return new BlockState(this, new IProperty[] {BITES});
171
    }
172
173
    public int getComparatorInputOverride(World worldIn, BlockPos pos)
174
    {
175
        return (7 - ((Integer)worldIn.getBlockState(pos).getValue(BITES)).intValue()) * 2;
176
    }
177
178
    public boolean hasComparatorInputOverride()
179
    {
180
        return true;
181
    }
182
}
183

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