BlockSponge .java

net.minecraft.block.BlockSponge (class): members: tryAbsorb, WET, getLocalizedName, randomDisplayTick, onBlockAdded, damageDropped, getSubBlocks.

net.minecraft.blockclass204 linescommonextends Block6.4 KB

API Surface (10)

String getLocalizedName()
int damageDropped(IBlockState state)
void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void tryAbsorb(World worldIn, BlockPos pos, IBlockState state)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)

Fields & Constants (1)

WET

String literals (1)

".dry.name"

Full Source

BlockSponge.java204 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.collect.Lists;
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.Queue;
7
import java.util.Random;
8
import net.minecraft.block.material.Material;
9
import net.minecraft.block.properties.IProperty;
10
import net.minecraft.block.properties.PropertyBool;
11
import net.minecraft.block.state.BlockState;
12
import net.minecraft.block.state.IBlockState;
13
import net.minecraft.creativetab.CreativeTabs;
14
import net.minecraft.init.Blocks;
15
import net.minecraft.item.Item;
16
import net.minecraft.item.ItemStack;
17
import net.minecraft.util.BlockPos;
18
import net.minecraft.util.EnumFacing;
19
import net.minecraft.util.EnumParticleTypes;
20
import net.minecraft.util.StatCollector;
21
import net.minecraft.util.Tuple;
22
import net.minecraft.world.World;
23
24
public class BlockSponge extends Block
25
{
26
    public static final PropertyBool WET = PropertyBool.create("wet");
27
28
    protected BlockSponge()
29
    {
30
        super(Material.sponge);
31
        this.setDefaultState(this.blockState.getBaseState().withProperty(WET, Boolean.valueOf(false)));
32
        this.setCreativeTab(CreativeTabs.tabBlock);
33
    }
34
35
    /**
36
     * Gets the localized name of this block. Used for the statistics page.
37
     */
38
    public String getLocalizedName()
39
    {
40
        return StatCollector.translateToLocal(this.getUnlocalizedName() + ".dry.name");
41
    }
42
43
    /**
44
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
45
     * returns the metadata of the dropped item based on the old metadata of the block.
46
     */
47
    public int damageDropped(IBlockState state)
48
    {
49
        return ((Boolean)state.getValue(WET)).booleanValue() ? 1 : 0;
50
    }
51
52
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
53
    {
54
        this.tryAbsorb(worldIn, pos, state);
55
    }
56
57
    /**
58
     * Called when a neighboring block changes.
59
     */
60
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
61
    {
62
        this.tryAbsorb(worldIn, pos, state);
63
        super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
64
    }
65
66
    protected void tryAbsorb(World worldIn, BlockPos pos, IBlockState state)
67
    {
68
        if (!((Boolean)state.getValue(WET)).booleanValue() && this.absorb(worldIn, pos))
69
        {
70
            worldIn.setBlockState(pos, state.withProperty(WET, Boolean.valueOf(true)), 2);
71
            worldIn.playAuxSFX(2001, pos, Block.getIdFromBlock(Blocks.water));
72
        }
73
    }
74
75
    private boolean absorb(World worldIn, BlockPos pos)
76
    {
77
        Queue<Tuple<BlockPos, Integer>> queue = Lists.<Tuple<BlockPos, Integer>>newLinkedList();
78
        ArrayList<BlockPos> arraylist = Lists.<BlockPos>newArrayList();
79
        queue.add(new Tuple(pos, Integer.valueOf(0)));
80
        int i = 0;
81
82
        while (!((Queue)queue).isEmpty())
83
        {
84
            Tuple<BlockPos, Integer> tuple = (Tuple)queue.poll();
85
            BlockPos blockpos = (BlockPos)tuple.getFirst();
86
            int j = ((Integer)tuple.getSecond()).intValue();
87
88
            for (EnumFacing enumfacing : EnumFacing.values())
89
            {
90
                BlockPos blockpos1 = blockpos.offset(enumfacing);
91
92
                if (worldIn.getBlockState(blockpos1).getBlock().getMaterial() == Material.water)
93
                {
94
                    worldIn.setBlockState(blockpos1, Blocks.air.getDefaultState(), 2);
95
                    arraylist.add(blockpos1);
96
                    ++i;
97
98
                    if (j < 6)
99
                    {
100
                        queue.add(new Tuple(blockpos1, Integer.valueOf(j + 1)));
101
                    }
102
                }
103
            }
104
105
            if (i > 64)
106
            {
107
                break;
108
            }
109
        }
110
111
        for (BlockPos blockpos2 : arraylist)
112
        {
113
            worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.air);
114
        }
115
116
        return i > 0;
117
    }
118
119
    /**
120
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
121
     */
122
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
123
    {
124
        list.add(new ItemStack(itemIn, 1, 0));
125
        list.add(new ItemStack(itemIn, 1, 1));
126
    }
127
128
    /**
129
     * Convert the given metadata into a BlockState for this Block
130
     */
131
    public IBlockState getStateFromMeta(int meta)
132
    {
133
        return this.getDefaultState().withProperty(WET, Boolean.valueOf((meta & 1) == 1));
134
    }
135
136
    /**
137
     * Convert the BlockState into the correct metadata value
138
     */
139
    public int getMetaFromState(IBlockState state)
140
    {
141
        return ((Boolean)state.getValue(WET)).booleanValue() ? 1 : 0;
142
    }
143
144
    protected BlockState createBlockState()
145
    {
146
        return new BlockState(this, new IProperty[] {WET});
147
    }
148
149
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
150
    {
151
        if (((Boolean)state.getValue(WET)).booleanValue())
152
        {
153
            EnumFacing enumfacing = EnumFacing.random(rand);
154
155
            if (enumfacing != EnumFacing.UP && !World.doesBlockHaveSolidTopSurface(worldIn, pos.offset(enumfacing)))
156
            {
157
                double d0 = (double)pos.getX();
158
                double d1 = (double)pos.getY();
159
                double d2 = (double)pos.getZ();
160
161
                if (enumfacing == EnumFacing.DOWN)
162
                {
163
                    d1 = d1 - 0.05D;
164
                    d0 += rand.nextDouble();
165
                    d2 += rand.nextDouble();
166
                }
167
                else
168
                {
169
                    d1 = d1 + rand.nextDouble() * 0.8D;
170
171
                    if (enumfacing.getAxis() == EnumFacing.Axis.X)
172
                    {
173
                        d2 += rand.nextDouble();
174
175
                        if (enumfacing == EnumFacing.EAST)
176
                        {
177
                            ++d0;
178
                        }
179
                        else
180
                        {
181
                            d0 += 0.05D;
182
                        }
183
                    }
184
                    else
185
                    {
186
                        d0 += rand.nextDouble();
187
188
                        if (enumfacing == EnumFacing.SOUTH)
189
                        {
190
                            ++d2;
191
                        }
192
                        else
193
                        {
194
                            d2 += 0.05D;
195
                        }
196
                    }
197
                }
198
199
                worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
200
            }
201
        }
202
    }
203
}
204

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