BlockCauldron .java

net.minecraft.block.BlockCauldron (class): members: setWaterLevel, fillWithRain, LEVEL, getComparatorInputOverride, hasComparatorInputOverride, getItem.

net.minecraft.blockclass284 linescommonextends Block10.2 KB

API Surface (15)

void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
void setBlockBoundsForItemRender()
boolean isOpaqueCube()
boolean isFullCube()
void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level)
void fillWithRain(World worldIn, BlockPos pos)
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
boolean hasComparatorInputOverride()
int getComparatorInputOverride(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

LEVEL

String literals (1)

"level"

Full Source

BlockCauldron.java284 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.List;
4
import java.util.Random;
5
import net.minecraft.block.material.MapColor;
6
import net.minecraft.block.material.Material;
7
import net.minecraft.block.properties.IProperty;
8
import net.minecraft.block.properties.PropertyInteger;
9
import net.minecraft.block.state.BlockState;
10
import net.minecraft.block.state.IBlockState;
11
import net.minecraft.entity.Entity;
12
import net.minecraft.entity.item.EntityItem;
13
import net.minecraft.entity.player.EntityPlayer;
14
import net.minecraft.entity.player.EntityPlayerMP;
15
import net.minecraft.init.Items;
16
import net.minecraft.item.Item;
17
import net.minecraft.item.ItemArmor;
18
import net.minecraft.item.ItemBanner;
19
import net.minecraft.item.ItemStack;
20
import net.minecraft.stats.StatList;
21
import net.minecraft.tileentity.TileEntityBanner;
22
import net.minecraft.util.AxisAlignedBB;
23
import net.minecraft.util.BlockPos;
24
import net.minecraft.util.EnumFacing;
25
import net.minecraft.util.MathHelper;
26
import net.minecraft.world.World;
27
28
public class BlockCauldron extends Block
29
{
30
    public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 3);
31
32
    public BlockCauldron()
33
    {
34
        super(Material.iron, MapColor.stoneColor);
35
        this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
36
    }
37
38
    /**
39
     * Add all collision boxes of this Block to the list that intersect with the given mask.
40
     */
41
    public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
42
    {
43
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
44
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
45
        float f = 0.125F;
46
        this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
47
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
48
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
49
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
50
        this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
51
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
52
        this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
53
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
54
        this.setBlockBoundsForItemRender();
55
    }
56
57
    /**
58
     * Sets the block's bounds for rendering it as an item
59
     */
60
    public void setBlockBoundsForItemRender()
61
    {
62
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
63
    }
64
65
    /**
66
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
67
     */
68
    public boolean isOpaqueCube()
69
    {
70
        return false;
71
    }
72
73
    public boolean isFullCube()
74
    {
75
        return false;
76
    }
77
78
    /**
79
     * Called When an Entity Collided with the Block
80
     */
81
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
82
    {
83
        int i = ((Integer)state.getValue(LEVEL)).intValue();
84
        float f = (float)pos.getY() + (6.0F + (float)(3 * i)) / 16.0F;
85
86
        if (!worldIn.isRemote && entityIn.isBurning() && i > 0 && entityIn.getEntityBoundingBox().minY <= (double)f)
87
        {
88
            entityIn.extinguish();
89
            this.setWaterLevel(worldIn, pos, state, i - 1);
90
        }
91
    }
92
93
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
94
    {
95
        if (worldIn.isRemote)
96
        {
97
            return true;
98
        }
99
        else
100
        {
101
            ItemStack itemstack = playerIn.inventory.getCurrentItem();
102
103
            if (itemstack == null)
104
            {
105
                return true;
106
            }
107
            else
108
            {
109
                int i = ((Integer)state.getValue(LEVEL)).intValue();
110
                Item item = itemstack.getItem();
111
112
                if (item == Items.water_bucket)
113
                {
114
                    if (i < 3)
115
                    {
116
                        if (!playerIn.capabilities.isCreativeMode)
117
                        {
118
                            playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bucket));
119
                        }
120
121
                        playerIn.triggerAchievement(StatList.field_181725_I);
122
                        this.setWaterLevel(worldIn, pos, state, 3);
123
                    }
124
125
                    return true;
126
                }
127
                else if (item == Items.glass_bottle)
128
                {
129
                    if (i > 0)
130
                    {
131
                        if (!playerIn.capabilities.isCreativeMode)
132
                        {
133
                            ItemStack itemstack2 = new ItemStack(Items.potionitem, 1, 0);
134
135
                            if (!playerIn.inventory.addItemStackToInventory(itemstack2))
136
                            {
137
                                worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.5D, (double)pos.getZ() + 0.5D, itemstack2));
138
                            }
139
                            else if (playerIn instanceof EntityPlayerMP)
140
                            {
141
                                ((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
142
                            }
143
144
                            playerIn.triggerAchievement(StatList.field_181726_J);
145
                            --itemstack.stackSize;
146
147
                            if (itemstack.stackSize <= 0)
148
                            {
149
                                playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack)null);
150
                            }
151
                        }
152
153
                        this.setWaterLevel(worldIn, pos, state, i - 1);
154
                    }
155
156
                    return true;
157
                }
158
                else
159
                {
160
                    if (i > 0 && item instanceof ItemArmor)
161
                    {
162
                        ItemArmor itemarmor = (ItemArmor)item;
163
164
                        if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER && itemarmor.hasColor(itemstack))
165
                        {
166
                            itemarmor.removeColor(itemstack);
167
                            this.setWaterLevel(worldIn, pos, state, i - 1);
168
                            playerIn.triggerAchievement(StatList.field_181727_K);
169
                            return true;
170
                        }
171
                    }
172
173
                    if (i > 0 && item instanceof ItemBanner && TileEntityBanner.getPatterns(itemstack) > 0)
174
                    {
175
                        ItemStack itemstack1 = itemstack.copy();
176
                        itemstack1.stackSize = 1;
177
                        TileEntityBanner.removeBannerData(itemstack1);
178
179
                        if (itemstack.stackSize <= 1 && !playerIn.capabilities.isCreativeMode)
180
                        {
181
                            playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, itemstack1);
182
                        }
183
                        else
184
                        {
185
                            if (!playerIn.inventory.addItemStackToInventory(itemstack1))
186
                            {
187
                                worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.5D, (double)pos.getZ() + 0.5D, itemstack1));
188
                            }
189
                            else if (playerIn instanceof EntityPlayerMP)
190
                            {
191
                                ((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
192
                            }
193
194
                            playerIn.triggerAchievement(StatList.field_181728_L);
195
196
                            if (!playerIn.capabilities.isCreativeMode)
197
                            {
198
                                --itemstack.stackSize;
199
                            }
200
                        }
201
202
                        if (!playerIn.capabilities.isCreativeMode)
203
                        {
204
                            this.setWaterLevel(worldIn, pos, state, i - 1);
205
                        }
206
207
                        return true;
208
                    }
209
                    else
210
                    {
211
                        return false;
212
                    }
213
                }
214
            }
215
        }
216
    }
217
218
    public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level)
219
    {
220
        worldIn.setBlockState(pos, state.withProperty(LEVEL, Integer.valueOf(MathHelper.clamp_int(level, 0, 3))), 2);
221
        worldIn.updateComparatorOutputLevel(pos, this);
222
    }
223
224
    /**
225
     * Called similar to random ticks, but only when it is raining.
226
     */
227
    public void fillWithRain(World worldIn, BlockPos pos)
228
    {
229
        if (worldIn.rand.nextInt(20) == 1)
230
        {
231
            IBlockState iblockstate = worldIn.getBlockState(pos);
232
233
            if (((Integer)iblockstate.getValue(LEVEL)).intValue() < 3)
234
            {
235
                worldIn.setBlockState(pos, iblockstate.cycleProperty(LEVEL), 2);
236
            }
237
        }
238
    }
239
240
    /**
241
     * Get the Item that this Block should drop when harvested.
242
     */
243
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
244
    {
245
        return Items.cauldron;
246
    }
247
248
    public Item getItem(World worldIn, BlockPos pos)
249
    {
250
        return Items.cauldron;
251
    }
252
253
    public boolean hasComparatorInputOverride()
254
    {
255
        return true;
256
    }
257
258
    public int getComparatorInputOverride(World worldIn, BlockPos pos)
259
    {
260
        return ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue();
261
    }
262
263
    /**
264
     * Convert the given metadata into a BlockState for this Block
265
     */
266
    public IBlockState getStateFromMeta(int meta)
267
    {
268
        return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta));
269
    }
270
271
    /**
272
     * Convert the BlockState into the correct metadata value
273
     */
274
    public int getMetaFromState(IBlockState state)
275
    {
276
        return ((Integer)state.getValue(LEVEL)).intValue();
277
    }
278
279
    protected BlockState createBlockState()
280
    {
281
        return new BlockState(this, new IProperty[] {LEVEL});
282
    }
283
}
284

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