119 lines
4.1 KiB
Java
119 lines
4.1 KiB
Java
package net.minecraft.block;
|
|
|
|
import java.util.Random;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.BlockFaceShape;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
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;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class BlockGrassPath extends Block
|
|
{
|
|
protected static final AxisAlignedBB GRASS_PATH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.9375D, 1.0D);
|
|
|
|
protected BlockGrassPath()
|
|
{
|
|
super(Material.GROUND);
|
|
this.setLightOpacity(255);
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
|
|
{
|
|
switch (side)
|
|
{
|
|
case UP:
|
|
return true;
|
|
case NORTH:
|
|
case SOUTH:
|
|
case WEST:
|
|
case EAST:
|
|
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
|
|
Block block = iblockstate.getBlock();
|
|
return !iblockstate.isOpaqueCube() && block != Blocks.FARMLAND && block != Blocks.GRASS_PATH;
|
|
default:
|
|
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Called after the block is set in the Chunk data, but before the Tile Entity is set
|
|
*/
|
|
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
|
|
{
|
|
super.onBlockAdded(worldIn, pos, state);
|
|
this.updateBlockState(worldIn, pos);
|
|
}
|
|
|
|
private void updateBlockState(World worldIn, BlockPos pos)
|
|
{
|
|
if (worldIn.getBlockState(pos.up()).getMaterial().isSolid())
|
|
{
|
|
BlockFarmland.turnToDirt(worldIn, pos);
|
|
}
|
|
}
|
|
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
|
|
{
|
|
return GRASS_PATH_AABB;
|
|
}
|
|
|
|
/**
|
|
* Used to determine ambient occlusion and culling when rebuilding chunks for render
|
|
*/
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public boolean isFullCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the Item that this Block should drop when harvested.
|
|
*/
|
|
public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
|
{
|
|
return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
|
|
}
|
|
|
|
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
|
|
{
|
|
return new ItemStack(this);
|
|
}
|
|
|
|
/**
|
|
* 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.updateBlockState(worldIn, pos);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
|
|
{
|
|
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
|
|
}
|
|
} |