ItemBucket .java

net.minecraft.item.ItemBucket (class): members: tryPlaceContainedLiquid, isFull, onItemRightClick. strings: "random.fizz". imports: BlockLiquid, StatList.

net.minecraft.itemclass167 linescommonextends Item5.9 KB

API Surface (2)

ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)

Fields & Constants (1)

isFull

String literals (1)

"random.fizz"

Full Source

ItemBucket.java167 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.BlockLiquid;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.state.IBlockState;
7
import net.minecraft.creativetab.CreativeTabs;
8
import net.minecraft.entity.player.EntityPlayer;
9
import net.minecraft.init.Blocks;
10
import net.minecraft.init.Items;
11
import net.minecraft.stats.StatList;
12
import net.minecraft.util.BlockPos;
13
import net.minecraft.util.EnumParticleTypes;
14
import net.minecraft.util.MovingObjectPosition;
15
import net.minecraft.world.World;
16
17
public class ItemBucket extends Item
18
{
19
    /** field for checking if the bucket has been filled. */
20
    private Block isFull;
21
22
    public ItemBucket(Block containedBlock)
23
    {
24
        this.maxStackSize = 1;
25
        this.isFull = containedBlock;
26
        this.setCreativeTab(CreativeTabs.tabMisc);
27
    }
28
29
    /**
30
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
31
     */
32
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
33
    {
34
        boolean flag = this.isFull == Blocks.air;
35
        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);
36
37
        if (movingobjectposition == null)
38
        {
39
            return itemStackIn;
40
        }
41
        else
42
        {
43
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
44
            {
45
                BlockPos blockpos = movingobjectposition.getBlockPos();
46
47
                if (!worldIn.isBlockModifiable(playerIn, blockpos))
48
                {
49
                    return itemStackIn;
50
                }
51
52
                if (flag)
53
                {
54
                    if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
55
                    {
56
                        return itemStackIn;
57
                    }
58
59
                    IBlockState iblockstate = worldIn.getBlockState(blockpos);
60
                    Material material = iblockstate.getBlock().getMaterial();
61
62
                    if (material == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
63
                    {
64
                        worldIn.setBlockToAir(blockpos);
65
                        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
66
                        return this.fillBucket(itemStackIn, playerIn, Items.water_bucket);
67
                    }
68
69
                    if (material == Material.lava && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
70
                    {
71
                        worldIn.setBlockToAir(blockpos);
72
                        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
73
                        return this.fillBucket(itemStackIn, playerIn, Items.lava_bucket);
74
                    }
75
                }
76
                else
77
                {
78
                    if (this.isFull == Blocks.air)
79
                    {
80
                        return new ItemStack(Items.bucket);
81
                    }
82
83
                    BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
84
85
                    if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn))
86
                    {
87
                        return itemStackIn;
88
                    }
89
90
                    if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode)
91
                    {
92
                        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
93
                        return new ItemStack(Items.bucket);
94
                    }
95
                }
96
            }
97
98
            return itemStackIn;
99
        }
100
    }
101
102
    private ItemStack fillBucket(ItemStack emptyBuckets, EntityPlayer player, Item fullBucket)
103
    {
104
        if (player.capabilities.isCreativeMode)
105
        {
106
            return emptyBuckets;
107
        }
108
        else if (--emptyBuckets.stackSize <= 0)
109
        {
110
            return new ItemStack(fullBucket);
111
        }
112
        else
113
        {
114
            if (!player.inventory.addItemStackToInventory(new ItemStack(fullBucket)))
115
            {
116
                player.dropPlayerItemWithRandomChoice(new ItemStack(fullBucket, 1, 0), false);
117
            }
118
119
            return emptyBuckets;
120
        }
121
    }
122
123
    public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
124
    {
125
        if (this.isFull == Blocks.air)
126
        {
127
            return false;
128
        }
129
        else
130
        {
131
            Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
132
            boolean flag = !material.isSolid();
133
134
            if (!worldIn.isAirBlock(pos) && !flag)
135
            {
136
                return false;
137
            }
138
            else
139
            {
140
                if (worldIn.provider.doesWaterVaporize() && this.isFull == Blocks.flowing_water)
141
                {
142
                    int i = pos.getX();
143
                    int j = pos.getY();
144
                    int k = pos.getZ();
145
                    worldIn.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
146
147
                    for (int l = 0; l < 8; ++l)
148
                    {
149
                        worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
150
                    }
151
                }
152
                else
153
                {
154
                    if (!worldIn.isRemote && flag && !material.isLiquid())
155
                    {
156
                        worldIn.destroyBlock(pos, true);
157
                    }
158
159
                    worldIn.setBlockState(pos, this.isFull.getDefaultState(), 3);
160
                }
161
162
                return true;
163
            }
164
        }
165
    }
166
}
167

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