BlockFarmland .java

net.minecraft.block.BlockFarmland (class): members: MOISTURE, onFallenUpon, shouldSideBeRendered, getItem, getCollisionBoundingBox, updateTick, isFullCube.

net.minecraft.blockclass178 linescommonextends Block5.5 KB

API Surface (12)

AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

MOISTURE

String literals (2)

"moisture"
"mobGriefing"

Full Source

BlockFarmland.java178 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.properties.IProperty;
6
import net.minecraft.block.properties.PropertyInteger;
7
import net.minecraft.block.state.BlockState;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.entity.Entity;
10
import net.minecraft.entity.EntityLivingBase;
11
import net.minecraft.entity.player.EntityPlayer;
12
import net.minecraft.init.Blocks;
13
import net.minecraft.item.Item;
14
import net.minecraft.util.AxisAlignedBB;
15
import net.minecraft.util.BlockPos;
16
import net.minecraft.util.EnumFacing;
17
import net.minecraft.world.IBlockAccess;
18
import net.minecraft.world.World;
19
20
public class BlockFarmland extends Block
21
{
22
    public static final PropertyInteger MOISTURE = PropertyInteger.create("moisture", 0, 7);
23
24
    protected BlockFarmland()
25
    {
26
        super(Material.ground);
27
        this.setDefaultState(this.blockState.getBaseState().withProperty(MOISTURE, Integer.valueOf(0)));
28
        this.setTickRandomly(true);
29
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
30
        this.setLightOpacity(255);
31
    }
32
33
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
34
    {
35
        return new AxisAlignedBB((double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), (double)(pos.getX() + 1), (double)(pos.getY() + 1), (double)(pos.getZ() + 1));
36
    }
37
38
    /**
39
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
40
     */
41
    public boolean isOpaqueCube()
42
    {
43
        return false;
44
    }
45
46
    public boolean isFullCube()
47
    {
48
        return false;
49
    }
50
51
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
52
    {
53
        int i = ((Integer)state.getValue(MOISTURE)).intValue();
54
55
        if (!this.hasWater(worldIn, pos) && !worldIn.isRainingAt(pos.up()))
56
        {
57
            if (i > 0)
58
            {
59
                worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(i - 1)), 2);
60
            }
61
            else if (!this.hasCrops(worldIn, pos))
62
            {
63
                worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
64
            }
65
        }
66
        else if (i < 7)
67
        {
68
            worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(7)), 2);
69
        }
70
    }
71
72
    /**
73
     * Block's chance to react to a living entity falling on it.
74
     */
75
    public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
76
    {
77
        if (entityIn instanceof EntityLivingBase)
78
        {
79
            if (!worldIn.isRemote && worldIn.rand.nextFloat() < fallDistance - 0.5F)
80
            {
81
                if (!(entityIn instanceof EntityPlayer) && !worldIn.getGameRules().getBoolean("mobGriefing"))
82
                {
83
                    return;
84
                }
85
86
                worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
87
            }
88
89
            super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
90
        }
91
    }
92
93
    private boolean hasCrops(World worldIn, BlockPos pos)
94
    {
95
        Block block = worldIn.getBlockState(pos.up()).getBlock();
96
        return block instanceof BlockCrops || block instanceof BlockStem;
97
    }
98
99
    private boolean hasWater(World worldIn, BlockPos pos)
100
    {
101
        for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4)))
102
        {
103
            if (worldIn.getBlockState(blockpos$mutableblockpos).getBlock().getMaterial() == Material.water)
104
            {
105
                return true;
106
            }
107
        }
108
109
        return false;
110
    }
111
112
    /**
113
     * Called when a neighboring block changes.
114
     */
115
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
116
    {
117
        super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
118
119
        if (worldIn.getBlockState(pos.up()).getBlock().getMaterial().isSolid())
120
        {
121
            worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
122
        }
123
    }
124
125
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
126
    {
127
        switch (side)
128
        {
129
            case UP:
130
                return true;
131
132
            case NORTH:
133
            case SOUTH:
134
            case WEST:
135
            case EAST:
136
                Block block = worldIn.getBlockState(pos).getBlock();
137
                return !block.isOpaqueCube() && block != Blocks.farmland;
138
139
            default:
140
                return super.shouldSideBeRendered(worldIn, pos, side);
141
        }
142
    }
143
144
    /**
145
     * Get the Item that this Block should drop when harvested.
146
     */
147
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
148
    {
149
        return Blocks.dirt.getItemDropped(Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
150
    }
151
152
    public Item getItem(World worldIn, BlockPos pos)
153
    {
154
        return Item.getItemFromBlock(Blocks.dirt);
155
    }
156
157
    /**
158
     * Convert the given metadata into a BlockState for this Block
159
     */
160
    public IBlockState getStateFromMeta(int meta)
161
    {
162
        return this.getDefaultState().withProperty(MOISTURE, Integer.valueOf(meta & 7));
163
    }
164
165
    /**
166
     * Convert the BlockState into the correct metadata value
167
     */
168
    public int getMetaFromState(IBlockState state)
169
    {
170
        return ((Integer)state.getValue(MOISTURE)).intValue();
171
    }
172
173
    protected BlockState createBlockState()
174
    {
175
        return new BlockState(this, new IProperty[] {MOISTURE});
176
    }
177
}
178

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