147 lines
5.1 KiB
Java
147 lines
5.1 KiB
Java
package net.minecraft.block;
|
|
|
|
import java.util.Random;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.block.material.MapColor;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.BlockFaceShape;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BlockBush extends Block
|
|
{
|
|
protected static final AxisAlignedBB BUSH_AABB = new AxisAlignedBB(0.30000001192092896D, 0.0D, 0.30000001192092896D, 0.699999988079071D, 0.6000000238418579D, 0.699999988079071D);
|
|
|
|
protected BlockBush()
|
|
{
|
|
this(Material.PLANTS);
|
|
}
|
|
|
|
protected BlockBush(Material materialIn)
|
|
{
|
|
this(materialIn, materialIn.getMaterialMapColor());
|
|
}
|
|
|
|
protected BlockBush(Material materialIn, MapColor mapColorIn)
|
|
{
|
|
super(materialIn, mapColorIn);
|
|
this.setTickRandomly(true);
|
|
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
|
}
|
|
|
|
/**
|
|
* Checks if this block can be placed exactly at the given position.
|
|
*/
|
|
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
|
{
|
|
return super.canPlaceBlockAt(worldIn, pos) && this.canSustainBush(worldIn.getBlockState(pos.down()));
|
|
}
|
|
|
|
/**
|
|
* Return true if the block can sustain a Bush
|
|
*/
|
|
protected boolean canSustainBush(IBlockState state)
|
|
{
|
|
return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.FARMLAND;
|
|
}
|
|
|
|
/**
|
|
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
|
|
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
|
|
* block, etc.
|
|
*/
|
|
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
|
|
{
|
|
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
|
|
this.checkAndDropBlock(worldIn, pos, state);
|
|
}
|
|
|
|
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
|
{
|
|
this.checkAndDropBlock(worldIn, pos, state);
|
|
}
|
|
|
|
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
|
|
{
|
|
if (!this.canBlockStay(worldIn, pos, state))
|
|
{
|
|
this.dropBlockAsItem(worldIn, pos, state, 0);
|
|
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
|
|
}
|
|
}
|
|
|
|
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
|
|
{
|
|
return this.canSustainBush(worldIn.getBlockState(pos.down()));
|
|
}
|
|
|
|
/**
|
|
* @deprecated call via {@link IBlockState#getBoundingBox(IBlockAccess,BlockPos)} whenever possible.
|
|
* Implementing/overriding is fine.
|
|
*/
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
|
|
{
|
|
return BUSH_AABB;
|
|
}
|
|
|
|
@Nullable
|
|
|
|
/**
|
|
* @deprecated call via {@link IBlockState#getCollisionBoundingBox(IBlockAccess,BlockPos)} whenever possible.
|
|
* Implementing/overriding is fine.
|
|
*/
|
|
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
|
|
{
|
|
return NULL_AABB;
|
|
}
|
|
|
|
/**
|
|
* Used to determine ambient occlusion and culling when rebuilding chunks for render
|
|
* @deprecated call via {@link IBlockState#isOpaqueCube()} whenever possible. Implementing/overriding is fine.
|
|
*/
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @deprecated call via {@link IBlockState#isFullCube()} whenever possible. Implementing/overriding is fine.
|
|
*/
|
|
public boolean isFullCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Gets the render layer this block will render on. SOLID for solid blocks, CUTOUT or CUTOUT_MIPPED for on-off
|
|
* transparency (glass, reeds), TRANSLUCENT for fully blended transparency (stained glass)
|
|
*/
|
|
public BlockRenderLayer getBlockLayer()
|
|
{
|
|
return BlockRenderLayer.CUTOUT;
|
|
}
|
|
|
|
/**
|
|
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
|
|
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
|
|
* <p>
|
|
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
|
|
* does not fit the other descriptions and will generally cause other things not to connect to the face.
|
|
|
|
* @return an approximation of the form of the given face
|
|
* @deprecated call via {@link IBlockState#getBlockFaceShape(IBlockAccess,BlockPos,EnumFacing)} whenever possible.
|
|
* Implementing/overriding is fine.
|
|
*/
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
|
|
{
|
|
return BlockFaceShape.UNDEFINED;
|
|
}
|
|
}
|