BlockPumpkin .java

net.minecraft.block.BlockPumpkin (class): members: getSnowmanBasePattern, getGolemBasePattern, snowmanBasePattern, getSnowmanPattern, golemBasePattern.

net.minecraft.blockclass191 linescommonextends BlockDirectional8.1 KB

API Surface (12)

boolean apply(IBlockState p_apply_1_)
void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
boolean canDispenserPlace(World worldIn, BlockPos pos)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
BlockPattern getSnowmanBasePattern()
BlockPattern getSnowmanPattern()
BlockPattern getGolemBasePattern()
BlockPattern getGolemPattern()

Fields & Constants (5)

field_181085_Q
snowmanBasePattern
snowmanPattern
golemBasePattern
golemPattern

Full Source

BlockPumpkin.java191 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.base.Predicate;
4
import net.minecraft.block.material.MapColor;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.state.BlockState;
8
import net.minecraft.block.state.BlockWorldState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.block.state.pattern.BlockPattern;
11
import net.minecraft.block.state.pattern.BlockStateHelper;
12
import net.minecraft.block.state.pattern.FactoryBlockPattern;
13
import net.minecraft.creativetab.CreativeTabs;
14
import net.minecraft.entity.EntityLivingBase;
15
import net.minecraft.entity.monster.EntityIronGolem;
16
import net.minecraft.entity.monster.EntitySnowman;
17
import net.minecraft.init.Blocks;
18
import net.minecraft.util.BlockPos;
19
import net.minecraft.util.EnumFacing;
20
import net.minecraft.util.EnumParticleTypes;
21
import net.minecraft.world.World;
22
23
public class BlockPumpkin extends BlockDirectional
24
{
25
    private BlockPattern snowmanBasePattern;
26
    private BlockPattern snowmanPattern;
27
    private BlockPattern golemBasePattern;
28
    private BlockPattern golemPattern;
29
    private static final Predicate<IBlockState> field_181085_Q = new Predicate<IBlockState>()
30
    {
31
        public boolean apply(IBlockState p_apply_1_)
32
        {
33
            return p_apply_1_ != null && (p_apply_1_.getBlock() == Blocks.pumpkin || p_apply_1_.getBlock() == Blocks.lit_pumpkin);
34
        }
35
    };
36
37
    protected BlockPumpkin()
38
    {
39
        super(Material.gourd, MapColor.adobeColor);
40
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
41
        this.setTickRandomly(true);
42
        this.setCreativeTab(CreativeTabs.tabBlock);
43
    }
44
45
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
46
    {
47
        super.onBlockAdded(worldIn, pos, state);
48
        this.trySpawnGolem(worldIn, pos);
49
    }
50
51
    public boolean canDispenserPlace(World worldIn, BlockPos pos)
52
    {
53
        return this.getSnowmanBasePattern().match(worldIn, pos) != null || this.getGolemBasePattern().match(worldIn, pos) != null;
54
    }
55
56
    private void trySpawnGolem(World worldIn, BlockPos pos)
57
    {
58
        BlockPattern.PatternHelper blockpattern$patternhelper;
59
60
        if ((blockpattern$patternhelper = this.getSnowmanPattern().match(worldIn, pos)) != null)
61
        {
62
            for (int i = 0; i < this.getSnowmanPattern().getThumbLength(); ++i)
63
            {
64
                BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(0, i, 0);
65
                worldIn.setBlockState(blockworldstate.getPos(), Blocks.air.getDefaultState(), 2);
66
            }
67
68
            EntitySnowman entitysnowman = new EntitySnowman(worldIn);
69
            BlockPos blockpos1 = blockpattern$patternhelper.translateOffset(0, 2, 0).getPos();
70
            entitysnowman.setLocationAndAngles((double)blockpos1.getX() + 0.5D, (double)blockpos1.getY() + 0.05D, (double)blockpos1.getZ() + 0.5D, 0.0F, 0.0F);
71
            worldIn.spawnEntityInWorld(entitysnowman);
72
73
            for (int j = 0; j < 120; ++j)
74
            {
75
                worldIn.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, (double)blockpos1.getX() + worldIn.rand.nextDouble(), (double)blockpos1.getY() + worldIn.rand.nextDouble() * 2.5D, (double)blockpos1.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D, new int[0]);
76
            }
77
78
            for (int i1 = 0; i1 < this.getSnowmanPattern().getThumbLength(); ++i1)
79
            {
80
                BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(0, i1, 0);
81
                worldIn.notifyNeighborsRespectDebug(blockworldstate1.getPos(), Blocks.air);
82
            }
83
        }
84
        else if ((blockpattern$patternhelper = this.getGolemPattern().match(worldIn, pos)) != null)
85
        {
86
            for (int k = 0; k < this.getGolemPattern().getPalmLength(); ++k)
87
            {
88
                for (int l = 0; l < this.getGolemPattern().getThumbLength(); ++l)
89
                {
90
                    worldIn.setBlockState(blockpattern$patternhelper.translateOffset(k, l, 0).getPos(), Blocks.air.getDefaultState(), 2);
91
                }
92
            }
93
94
            BlockPos blockpos = blockpattern$patternhelper.translateOffset(1, 2, 0).getPos();
95
            EntityIronGolem entityirongolem = new EntityIronGolem(worldIn);
96
            entityirongolem.setPlayerCreated(true);
97
            entityirongolem.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.05D, (double)blockpos.getZ() + 0.5D, 0.0F, 0.0F);
98
            worldIn.spawnEntityInWorld(entityirongolem);
99
100
            for (int j1 = 0; j1 < 120; ++j1)
101
            {
102
                worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double)blockpos.getX() + worldIn.rand.nextDouble(), (double)blockpos.getY() + worldIn.rand.nextDouble() * 3.9D, (double)blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D, new int[0]);
103
            }
104
105
            for (int k1 = 0; k1 < this.getGolemPattern().getPalmLength(); ++k1)
106
            {
107
                for (int l1 = 0; l1 < this.getGolemPattern().getThumbLength(); ++l1)
108
                {
109
                    BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(k1, l1, 0);
110
                    worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.air);
111
                }
112
            }
113
        }
114
    }
115
116
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
117
    {
118
        return worldIn.getBlockState(pos).getBlock().blockMaterial.isReplaceable() && World.doesBlockHaveSolidTopSurface(worldIn, pos.down());
119
    }
120
121
    /**
122
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
123
     * IBlockstate
124
     */
125
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
126
    {
127
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
128
    }
129
130
    /**
131
     * Convert the given metadata into a BlockState for this Block
132
     */
133
    public IBlockState getStateFromMeta(int meta)
134
    {
135
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
136
    }
137
138
    /**
139
     * Convert the BlockState into the correct metadata value
140
     */
141
    public int getMetaFromState(IBlockState state)
142
    {
143
        return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
144
    }
145
146
    protected BlockState createBlockState()
147
    {
148
        return new BlockState(this, new IProperty[] {FACING});
149
    }
150
151
    protected BlockPattern getSnowmanBasePattern()
152
    {
153
        if (this.snowmanBasePattern == null)
154
        {
155
            this.snowmanBasePattern = FactoryBlockPattern.start().aisle(new String[] {" ", "#", "#"}).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.snow))).build();
156
        }
157
158
        return this.snowmanBasePattern;
159
    }
160
161
    protected BlockPattern getSnowmanPattern()
162
    {
163
        if (this.snowmanPattern == null)
164
        {
165
            this.snowmanPattern = FactoryBlockPattern.start().aisle(new String[] {"^", "#", "#"}).where('^', BlockWorldState.hasState(field_181085_Q)).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.snow))).build();
166
        }
167
168
        return this.snowmanPattern;
169
    }
170
171
    protected BlockPattern getGolemBasePattern()
172
    {
173
        if (this.golemBasePattern == null)
174
        {
175
            this.golemBasePattern = FactoryBlockPattern.start().aisle(new String[] {"~ ~", "###", "~#~"}).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.iron_block))).where('~', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.air))).build();
176
        }
177
178
        return this.golemBasePattern;
179
    }
180
181
    protected BlockPattern getGolemPattern()
182
    {
183
        if (this.golemPattern == null)
184
        {
185
            this.golemPattern = FactoryBlockPattern.start().aisle(new String[] {"~^~", "###", "~#~"}).where('^', BlockWorldState.hasState(field_181085_Q)).where('#', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.iron_block))).where('~', BlockWorldState.hasState(BlockStateHelper.forBlock(Blocks.air))).build();
186
        }
187
188
        return this.golemPattern;
189
    }
190
}
191

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