BlockSkull .java

net.minecraft.block.BlockSkull (class): members: getWitherBasePattern, IS_WITHER_SKELETON, witherBasePattern, checkWitherSpawn, getWitherPattern, NODROP.

net.minecraft.blockclass305 linescommonextends BlockContainer11.8 KB

API Surface (21)

boolean apply(BlockWorldState p_apply_1_)
String getLocalizedName()
boolean isOpaqueCube()
boolean isFullCube()
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
TileEntity createNewTileEntity(World worldIn, int meta)
Item getItem(World worldIn, BlockPos pos)
int getDamageValue(World worldIn, BlockPos pos)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
void breakBlock(World worldIn, BlockPos pos, IBlockState state)
Item getItemDropped(IBlockState state, Random rand, int fortune)
boolean canDispenserPlace(World worldIn, BlockPos pos, ItemStack stack)
void checkWitherSpawn(World worldIn, BlockPos pos, TileEntitySkull te)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
BlockPattern getWitherBasePattern()
BlockPattern getWitherPattern()

Fields & Constants (5)

FACING
NODROP
IS_WITHER_SKELETON
witherBasePattern
witherPattern

String literals (4)

"facing"
"nodrop"
"tile.skull.skeleton.name"
"SkullOwner"

Full Source

BlockSkull.java305 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.base.Predicate;
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.PropertyBool;
8
import net.minecraft.block.properties.PropertyDirection;
9
import net.minecraft.block.state.BlockState;
10
import net.minecraft.block.state.BlockWorldState;
11
import net.minecraft.block.state.IBlockState;
12
import net.minecraft.block.state.pattern.BlockPattern;
13
import net.minecraft.block.state.pattern.BlockStateHelper;
14
import net.minecraft.block.state.pattern.FactoryBlockPattern;
15
import net.minecraft.entity.EntityLivingBase;
16
import net.minecraft.entity.boss.EntityWither;
17
import net.minecraft.entity.player.EntityPlayer;
18
import net.minecraft.init.Blocks;
19
import net.minecraft.init.Items;
20
import net.minecraft.item.Item;
21
import net.minecraft.item.ItemStack;
22
import net.minecraft.nbt.NBTTagCompound;
23
import net.minecraft.nbt.NBTUtil;
24
import net.minecraft.stats.AchievementList;
25
import net.minecraft.tileentity.TileEntity;
26
import net.minecraft.tileentity.TileEntitySkull;
27
import net.minecraft.util.AxisAlignedBB;
28
import net.minecraft.util.BlockPos;
29
import net.minecraft.util.EnumFacing;
30
import net.minecraft.util.EnumParticleTypes;
31
import net.minecraft.util.StatCollector;
32
import net.minecraft.world.EnumDifficulty;
33
import net.minecraft.world.IBlockAccess;
34
import net.minecraft.world.World;
35
36
public class BlockSkull extends BlockContainer
37
{
38
    public static final PropertyDirection FACING = PropertyDirection.create("facing");
39
    public static final PropertyBool NODROP = PropertyBool.create("nodrop");
40
    private static final Predicate<BlockWorldState> IS_WITHER_SKELETON = new Predicate<BlockWorldState>()
41
    {
42
        public boolean apply(BlockWorldState p_apply_1_)
43
        {
44
            return p_apply_1_.getBlockState() != null && p_apply_1_.getBlockState().getBlock() == Blocks.skull && p_apply_1_.getTileEntity() instanceof TileEntitySkull && ((TileEntitySkull)p_apply_1_.getTileEntity()).getSkullType() == 1;
45
        }
46
    };
47
    private BlockPattern witherBasePattern;
48
    private BlockPattern witherPattern;
49
50
    protected BlockSkull()
51
    {
52
        super(Material.circuits);
53
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(NODROP, Boolean.valueOf(false)));
54
        this.setBlockBounds(0.25F, 0.0F, 0.25F, 0.75F, 0.5F, 0.75F);
55
    }
56
57
    /**
58
     * Gets the localized name of this block. Used for the statistics page.
59
     */
60
    public String getLocalizedName()
61
    {
62
        return StatCollector.translateToLocal("tile.skull.skeleton.name");
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
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
79
    {
80
        switch ((EnumFacing)worldIn.getBlockState(pos).getValue(FACING))
81
        {
82
            case UP:
83
            default:
84
                this.setBlockBounds(0.25F, 0.0F, 0.25F, 0.75F, 0.5F, 0.75F);
85
                break;
86
87
            case NORTH:
88
                this.setBlockBounds(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F);
89
                break;
90
91
            case SOUTH:
92
                this.setBlockBounds(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F);
93
                break;
94
95
            case WEST:
96
                this.setBlockBounds(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F);
97
                break;
98
99
            case EAST:
100
                this.setBlockBounds(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F);
101
        }
102
    }
103
104
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
105
    {
106
        this.setBlockBoundsBasedOnState(worldIn, pos);
107
        return super.getCollisionBoundingBox(worldIn, pos, state);
108
    }
109
110
    /**
111
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
112
     * IBlockstate
113
     */
114
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
115
    {
116
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()).withProperty(NODROP, Boolean.valueOf(false));
117
    }
118
119
    /**
120
     * Returns a new instance of a block's tile entity class. Called on placing the block.
121
     */
122
    public TileEntity createNewTileEntity(World worldIn, int meta)
123
    {
124
        return new TileEntitySkull();
125
    }
126
127
    public Item getItem(World worldIn, BlockPos pos)
128
    {
129
        return Items.skull;
130
    }
131
132
    /**
133
     * Gets the meta to use for the Pick Block ItemStack result
134
     */
135
    public int getDamageValue(World worldIn, BlockPos pos)
136
    {
137
        TileEntity tileentity = worldIn.getTileEntity(pos);
138
        return tileentity instanceof TileEntitySkull ? ((TileEntitySkull)tileentity).getSkullType() : super.getDamageValue(worldIn, pos);
139
    }
140
141
    /**
142
     * Spawns this Block's drops into the World as EntityItems.
143
     */
144
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
145
    {
146
    }
147
148
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
149
    {
150
        if (player.capabilities.isCreativeMode)
151
        {
152
            state = state.withProperty(NODROP, Boolean.valueOf(true));
153
            worldIn.setBlockState(pos, state, 4);
154
        }
155
156
        super.onBlockHarvested(worldIn, pos, state, player);
157
    }
158
159
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
160
    {
161
        if (!worldIn.isRemote)
162
        {
163
            if (!((Boolean)state.getValue(NODROP)).booleanValue())
164
            {
165
                TileEntity tileentity = worldIn.getTileEntity(pos);
166
167
                if (tileentity instanceof TileEntitySkull)
168
                {
169
                    TileEntitySkull tileentityskull = (TileEntitySkull)tileentity;
170
                    ItemStack itemstack = new ItemStack(Items.skull, 1, this.getDamageValue(worldIn, pos));
171
172
                    if (tileentityskull.getSkullType() == 3 && tileentityskull.getPlayerProfile() != null)
173
                    {
174
                        itemstack.setTagCompound(new NBTTagCompound());
175
                        NBTTagCompound nbttagcompound = new NBTTagCompound();
176
                        NBTUtil.writeGameProfile(nbttagcompound, tileentityskull.getPlayerProfile());
177
                        itemstack.getTagCompound().setTag("SkullOwner", nbttagcompound);
178
                    }
179
180
                    spawnAsEntity(worldIn, pos, itemstack);
181
                }
182
            }
183
184
            super.breakBlock(worldIn, pos, state);
185
        }
186
    }
187
188
    /**
189
     * Get the Item that this Block should drop when harvested.
190
     */
191
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
192
    {
193
        return Items.skull;
194
    }
195
196
    public boolean canDispenserPlace(World worldIn, BlockPos pos, ItemStack stack)
197
    {
198
        return stack.getMetadata() == 1 && pos.getY() >= 2 && worldIn.getDifficulty() != EnumDifficulty.PEACEFUL && !worldIn.isRemote ? this.getWitherBasePattern().match(worldIn, pos) != null : false;
199
    }
200
201
    public void checkWitherSpawn(World worldIn, BlockPos pos, TileEntitySkull te)
202
    {
203
        if (te.getSkullType() == 1 && pos.getY() >= 2 && worldIn.getDifficulty() != EnumDifficulty.PEACEFUL && !worldIn.isRemote)
204
        {
205
            BlockPattern blockpattern = this.getWitherPattern();
206
            BlockPattern.PatternHelper blockpattern$patternhelper = blockpattern.match(worldIn, pos);
207
208
            if (blockpattern$patternhelper != null)
209
            {
210
                for (int i = 0; i < 3; ++i)
211
                {
212
                    BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, 0, 0);
213
                    worldIn.setBlockState(blockworldstate.getPos(), blockworldstate.getBlockState().withProperty(NODROP, Boolean.valueOf(true)), 2);
214
                }
215
216
                for (int j = 0; j < blockpattern.getPalmLength(); ++j)
217
                {
218
                    for (int k = 0; k < blockpattern.getThumbLength(); ++k)
219
                    {
220
                        BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(j, k, 0);
221
                        worldIn.setBlockState(blockworldstate1.getPos(), Blocks.air.getDefaultState(), 2);
222
                    }
223
                }
224
225
                BlockPos blockpos = blockpattern$patternhelper.translateOffset(1, 0, 0).getPos();
226
                EntityWither entitywither = new EntityWither(worldIn);
227
                BlockPos blockpos1 = blockpattern$patternhelper.translateOffset(1, 2, 0).getPos();
228
                entitywither.setLocationAndAngles((double)blockpos1.getX() + 0.5D, (double)blockpos1.getY() + 0.55D, (double)blockpos1.getZ() + 0.5D, blockpattern$patternhelper.getFinger().getAxis() == EnumFacing.Axis.X ? 0.0F : 90.0F, 0.0F);
229
                entitywither.renderYawOffset = blockpattern$patternhelper.getFinger().getAxis() == EnumFacing.Axis.X ? 0.0F : 90.0F;
230
                entitywither.func_82206_m();
231
232
                for (EntityPlayer entityplayer : worldIn.getEntitiesWithinAABB(EntityPlayer.class, entitywither.getEntityBoundingBox().expand(50.0D, 50.0D, 50.0D)))
233
                {
234
                    entityplayer.triggerAchievement(AchievementList.spawnWither);
235
                }
236
237
                worldIn.spawnEntityInWorld(entitywither);
238
239
                for (int l = 0; l < 120; ++l)
240
                {
241
                    worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double)blockpos.getX() + worldIn.rand.nextDouble(), (double)(blockpos.getY() - 2) + worldIn.rand.nextDouble() * 3.9D, (double)blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D, new int[0]);
242
                }
243
244
                for (int i1 = 0; i1 < blockpattern.getPalmLength(); ++i1)
245
                {
246
                    for (int j1 = 0; j1 < blockpattern.getThumbLength(); ++j1)
247
                    {
248
                        BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(i1, j1, 0);
249
                        worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.air);
250
                    }
251
                }
252
            }
253
        }
254
    }
255
256
    /**
257
     * Convert the given metadata into a BlockState for this Block
258
     */
259
    public IBlockState getStateFromMeta(int meta)
260
    {
261
        return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7)).withProperty(NODROP, Boolean.valueOf((meta & 8) > 0));
262
    }
263
264
    /**
265
     * Convert the BlockState into the correct metadata value
266
     */
267
    public int getMetaFromState(IBlockState state)
268
    {
269
        int i = 0;
270
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
271
272
        if (((Boolean)state.getValue(NODROP)).booleanValue())
273
        {
274
            i |= 8;
275
        }
276
277
        return i;
278
    }
279
280
    protected BlockState createBlockState()
281
    {
282
        return new BlockState(this, new IProperty[] {FACING, NODROP});
283
    }
284
285
    protected BlockPattern getWitherBasePattern()
286
    {
287
        if (this.witherBasePattern == null)
288
        {
289
            this.witherBasePattern = FactoryBlockPattern.start().aisle(new String[] {"   ", "###", "~#~"}).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.soul_sand))).where('~', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.air))).build();
290
        }
291
292
        return this.witherBasePattern;
293
    }
294
295
    protected BlockPattern getWitherPattern()
296
    {
297
        if (this.witherPattern == null)
298
        {
299
            this.witherPattern = FactoryBlockPattern.start().aisle(new String[] {"^^^", "###", "~#~"}).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.soul_sand))).where('^', IS_WITHER_SKELETON).where('~', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.air))).build();
300
        }
301
302
        return this.witherPattern;
303
    }
304
}
305

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