BlockSilverfish .java

net.minecraft.block.BlockSilverfish (class, 239 lines): members: canContainSilverfish, createStackedBlock, getDamageValue, EnumType, VARIANT, getSubBlocks.

net.minecraft.blockclass239 linescommonextends Block7.7 KB

API Surface (21)

int quantityDropped(Random random)
boolean canContainSilverfish(IBlockState blockState)
ItemStack createStackedBlock(IBlockState state)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
int getDamageValue(World worldIn, BlockPos pos)
void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
IBlockState getModelBlock()
IBlockState getModelBlock()
IBlockState getModelBlock()
IBlockState getModelBlock()
IBlockState getModelBlock()
IBlockState getModelBlock()
int getMetadata()
String toString()
BlockSilverfish.EnumType byMetadata(int meta)
String getName()
String getUnlocalizedName()
BlockSilverfish.EnumType forModelBlock(IBlockState model)

Fields & Constants (1)

VARIANT

String literals (13)

"variant"
"doTileDrops"
"stone"
"cobblestone"
"cobble"
"stone_brick"
"brick"
"mossy_brick"
"mossybrick"
"cracked_brick"
"crackedbrick"
"chiseled_brick"
"chiseledbrick"

Full Source

BlockSilverfish.java239 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.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyEnum;
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.monster.EntitySilverfish;
12
import net.minecraft.init.Blocks;
13
import net.minecraft.item.Item;
14
import net.minecraft.item.ItemStack;
15
import net.minecraft.util.BlockPos;
16
import net.minecraft.util.IStringSerializable;
17
import net.minecraft.world.World;
18
19
public class BlockSilverfish extends Block
20
{
21
    public static final PropertyEnum<BlockSilverfish.EnumType> VARIANT = PropertyEnum.<BlockSilverfish.EnumType>create("variant", BlockSilverfish.EnumType.class);
22
23
    public BlockSilverfish()
24
    {
25
        super(Material.clay);
26
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockSilverfish.EnumType.STONE));
27
        this.setHardness(0.0F);
28
        this.setCreativeTab(CreativeTabs.tabDecorations);
29
    }
30
31
    /**
32
     * Returns the quantity of items to drop on block destruction.
33
     */
34
    public int quantityDropped(Random random)
35
    {
36
        return 0;
37
    }
38
39
    public static boolean canContainSilverfish(IBlockState blockState)
40
    {
41
        Block block = blockState.getBlock();
42
        return blockState == Blocks.stone.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.STONE) || block == Blocks.cobblestone || block == Blocks.stonebrick;
43
    }
44
45
    protected ItemStack createStackedBlock(IBlockState state)
46
    {
47
        switch ((BlockSilverfish.EnumType)state.getValue(VARIANT))
48
        {
49
            case COBBLESTONE:
50
                return new ItemStack(Blocks.cobblestone);
51
52
            case STONEBRICK:
53
                return new ItemStack(Blocks.stonebrick);
54
55
            case MOSSY_STONEBRICK:
56
                return new ItemStack(Blocks.stonebrick, 1, BlockStoneBrick.EnumType.MOSSY.getMetadata());
57
58
            case CRACKED_STONEBRICK:
59
                return new ItemStack(Blocks.stonebrick, 1, BlockStoneBrick.EnumType.CRACKED.getMetadata());
60
61
            case CHISELED_STONEBRICK:
62
                return new ItemStack(Blocks.stonebrick, 1, BlockStoneBrick.EnumType.CHISELED.getMetadata());
63
64
            default:
65
                return new ItemStack(Blocks.stone);
66
        }
67
    }
68
69
    /**
70
     * Spawns this Block's drops into the World as EntityItems.
71
     */
72
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
73
    {
74
        if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
75
        {
76
            EntitySilverfish entitysilverfish = new EntitySilverfish(worldIn);
77
            entitysilverfish.setLocationAndAngles((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, 0.0F, 0.0F);
78
            worldIn.spawnEntityInWorld(entitysilverfish);
79
            entitysilverfish.spawnExplosionParticle();
80
        }
81
    }
82
83
    /**
84
     * Gets the meta to use for the Pick Block ItemStack result
85
     */
86
    public int getDamageValue(World worldIn, BlockPos pos)
87
    {
88
        IBlockState iblockstate = worldIn.getBlockState(pos);
89
        return iblockstate.getBlock().getMetaFromState(iblockstate);
90
    }
91
92
    /**
93
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
94
     */
95
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
96
    {
97
        for (BlockSilverfish.EnumType blocksilverfish$enumtype : BlockSilverfish.EnumType.values())
98
        {
99
            list.add(new ItemStack(itemIn, 1, blocksilverfish$enumtype.getMetadata()));
100
        }
101
    }
102
103
    /**
104
     * Convert the given metadata into a BlockState for this Block
105
     */
106
    public IBlockState getStateFromMeta(int meta)
107
    {
108
        return this.getDefaultState().withProperty(VARIANT, BlockSilverfish.EnumType.byMetadata(meta));
109
    }
110
111
    /**
112
     * Convert the BlockState into the correct metadata value
113
     */
114
    public int getMetaFromState(IBlockState state)
115
    {
116
        return ((BlockSilverfish.EnumType)state.getValue(VARIANT)).getMetadata();
117
    }
118
119
    protected BlockState createBlockState()
120
    {
121
        return new BlockState(this, new IProperty[] {VARIANT});
122
    }
123
124
    public static enum EnumType implements IStringSerializable
125
    {
126
        STONE(0, "stone")
127
        {
128
            public IBlockState getModelBlock()
129
            {
130
                return Blocks.stone.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.STONE);
131
            }
132
        },
133
        COBBLESTONE(1, "cobblestone", "cobble")
134
        {
135
            public IBlockState getModelBlock()
136
            {
137
                return Blocks.cobblestone.getDefaultState();
138
            }
139
        },
140
        STONEBRICK(2, "stone_brick", "brick")
141
        {
142
            public IBlockState getModelBlock()
143
            {
144
                return Blocks.stonebrick.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.DEFAULT);
145
            }
146
        },
147
        MOSSY_STONEBRICK(3, "mossy_brick", "mossybrick")
148
        {
149
            public IBlockState getModelBlock()
150
            {
151
                return Blocks.stonebrick.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY);
152
            }
153
        },
154
        CRACKED_STONEBRICK(4, "cracked_brick", "crackedbrick")
155
        {
156
            public IBlockState getModelBlock()
157
            {
158
                return Blocks.stonebrick.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.CRACKED);
159
            }
160
        },
161
        CHISELED_STONEBRICK(5, "chiseled_brick", "chiseledbrick")
162
        {
163
            public IBlockState getModelBlock()
164
            {
165
                return Blocks.stonebrick.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.CHISELED);
166
            }
167
        };
168
169
        private static final BlockSilverfish.EnumType[] META_LOOKUP = new BlockSilverfish.EnumType[values().length];
170
        private final int meta;
171
        private final String name;
172
        private final String unlocalizedName;
173
174
        private EnumType(int meta, String name)
175
        {
176
            this(meta, name, name);
177
        }
178
179
        private EnumType(int meta, String name, String unlocalizedName)
180
        {
181
            this.meta = meta;
182
            this.name = name;
183
            this.unlocalizedName = unlocalizedName;
184
        }
185
186
        public int getMetadata()
187
        {
188
            return this.meta;
189
        }
190
191
        public String toString()
192
        {
193
            return this.name;
194
        }
195
196
        public static BlockSilverfish.EnumType byMetadata(int meta)
197
        {
198
            if (meta < 0 || meta >= META_LOOKUP.length)
199
            {
200
                meta = 0;
201
            }
202
203
            return META_LOOKUP[meta];
204
        }
205
206
        public String getName()
207
        {
208
            return this.name;
209
        }
210
211
        public String getUnlocalizedName()
212
        {
213
            return this.unlocalizedName;
214
        }
215
216
        public abstract IBlockState getModelBlock();
217
218
        public static BlockSilverfish.EnumType forModelBlock(IBlockState model)
219
        {
220
            for (BlockSilverfish.EnumType blocksilverfish$enumtype : values())
221
            {
222
                if (model == blocksilverfish$enumtype.getModelBlock())
223
                {
224
                    return blocksilverfish$enumtype;
225
                }
226
            }
227
228
            return STONE;
229
        }
230
231
        static {
232
            for (BlockSilverfish.EnumType blocksilverfish$enumtype : values())
233
            {
234
                META_LOOKUP[blocksilverfish$enumtype.getMetadata()] = blocksilverfish$enumtype;
235
            }
236
        }
237
    }
238
}
239

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