Skip to content

Instantly share code, notes, and snippets.

@ZornTaov
Last active March 3, 2016 22:51
Show Gist options
  • Save ZornTaov/ee6e86068e75c230f264 to your computer and use it in GitHub Desktop.
Save ZornTaov/ee6e86068e75c230f264 to your computer and use it in GitHub Desktop.
package zornco.bedcraftbeyond.blocks;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import zornco.bedcraftbeyond.BedCraftBeyond;
import zornco.bedcraftbeyond.blocks.BlockRug.EnumShape;
public class BlockRug extends Block {
public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public static final PropertyEnum<BlockRug.EnumShape> SHAPE = PropertyEnum.<BlockRug.EnumShape>create("shape", BlockRug.EnumShape.class);
public static final PropertyEnum<BlockRug.EnumShape> NSHAPE = PropertyEnum.<BlockRug.EnumShape>create("nshape", BlockRug.EnumShape.class);
public static final PropertyEnum<BlockRug.EnumShape> SSHAPE = PropertyEnum.<BlockRug.EnumShape>create("sshape", BlockRug.EnumShape.class);
public static final PropertyEnum<BlockRug.EnumShape> ESHAPE = PropertyEnum.<BlockRug.EnumShape>create("eshape", BlockRug.EnumShape.class);
public static final PropertyEnum<BlockRug.EnumShape> WSHAPE = PropertyEnum.<BlockRug.EnumShape>create("wshape", BlockRug.EnumShape.class);
public BlockRug() {
super(Material.cloth);
this.setCreativeTab(BedCraftBeyond.bedCraftBeyondTab);
}
@Override
public boolean isFullCube()
{
return false;
}
/**
* checks to see if you can place this block can be placed on that side of a
* block: BlockLever overrides
*/
@Override
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
return World.doesBlockHaveSolidTopSurface(worldIn, pos.down())
|| this.isBlockValid(worldIn.getBlockState(pos.down()).getBlock());
}
/**
* Checks to see if its valid to put this block at the specified
* coordinates. Args: world, pos
*/
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return World.doesBlockHaveSolidTopSurface(worldIn, pos.down())
|| this.isBlockValid(worldIn.getBlockState(pos.down()).getBlock());//(pos.down()));
}
private static boolean isBlockValid(Block block) {
return (block instanceof BlockStairs);// || (block instanceof BlockSlab);
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which
* neighbor changed (coordinates passed are their own) Args: pos,
* neighbor blockID
*/
@Override
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
int valid = 0;
if (worldIn.isSideSolid(pos.down(), EnumFacing.DOWN)|| this.isBlockValid(worldIn.getBlockState(pos.down()).getBlock())) {
valid++;
}
if (valid == 0) {
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
/**
* Returns a bounding box from the pool of bounding boxes (this means this
* box can change after the pool has been cleared to be reused)
*/
@Override
public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state) {
return null;
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos) {
float var9 = 0F;
float var10 = 1F;
float var11 = 0F;
float var12 = 0.0625F;
float var13 = 0F;
float var14 = 1F;
/*int ID = world.getBlockId(x, y-1, z);
if(ID == Block.stoneSingleSlab.blockID || ID == Block.woodSingleSlab.blockID && ((world.getBlockMetadata(x, y -1, z) & 0x8) == 0))
this.setBlockBounds(var9, var11-0.5F, var13, var10, var12-0.5F, var14);
else*/
this.setBlockBounds(var9, var11, var13, var10, var12, var14);
}
/**
* Return whether an adjacent block can connect to a wall.
*/
public static boolean canConnectRugTo(IBlockAccess par1IBlockAccess, BlockPos pos) {
Block var5 = par1IBlockAccess.getBlockState(pos).getBlock();
return (var5 == BedCraftBeyond.rugBlock)&& !par1IBlockAccess.isAirBlock(pos) ? true : false;
}
/**
* Determines the damage on the item the block drops. Used in cloth and
* wood.
*/
@Override
public int damageDropped(IBlockState state) {
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
/**
* Takes a dye damage value and returns the block damage value to match
*/
public static int getBlockFromDye(int par0) {
return ~par0 & 15;
}
/**
* Takes a block damage value and returns the dye damage value to match
*/
public static int getDyeFromBlock(int par0) {
return ~par0 & 15;
}
@SuppressWarnings("rawtypes")
@Override
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
}
/**
* If this block doesn't render as an ordinary block it will return False
* (examples: signs, buttons, stairs, etc)
*/
/*@Override
public boolean renderAsNormalBlock() {
return false;
}*/
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether
* or not to render the shared face of two adjacent blocks and also whether
* the player can attach torches, redstone wire, etc to this block.
*/
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
@SideOnly(Side.CLIENT)
/**
* Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
* coordinates. Args: blockAccess, pos, side
*/
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, BlockPos pos, EnumFacing side) {
return true;
}
@Override
public int getRenderType() {
return 3;
}
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
pos = pos.down();
IBlockState underState = worldIn.getBlockState(pos);
Block underBlock = underState.getBlock();
underState = underBlock.getActualState(underState, worldIn, pos);
if (underBlock instanceof BlockStairs && underState.getValue(BlockStairs.HALF) == BlockStairs.EnumHalf.BOTTOM) {
state = state.withProperty(SHAPE, BlockRug.EnumShape.getShape(underState.getValue(BlockStairs.SHAPE)));
}
else if (worldIn.getBlockState(pos).getBlock() instanceof BlockSlab && underState.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) {
state = state.withProperty(SHAPE, BlockRug.EnumShape.SLAB);
}
else
{
state = state.withProperty(SHAPE, BlockRug.EnumShape.BLOCK);
}
return state;
}
/**
* Check whether there is a stair block at the given position and it has the same properties as the given BlockState
*/
public static boolean isSameStair(IBlockAccess worldIn, BlockPos pos, IBlockState state)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
/**
* Checks if a block is stairs
*/
return isBlockValid(block) && iblockstate.getValue(BlockStairs.HALF) == state.getValue(BlockStairs.HALF) && iblockstate.getValue(BlockStairs.FACING) == state.getValue(BlockStairs.FACING);
}
@Override
protected BlockState createBlockState() {
return new BlockState(this, new IProperty[] {COLOR, FACING, SHAPE});//, NSHAPE, SSHAPE, ESHAPE, WSHAPE});
}
public static enum EnumShape implements IStringSerializable
{
NONE("none"),
BLOCK("block"),
SLAB("slab"),
STRAIGHT("straight"),
INNER_LEFT("inner_left"),
INNER_RIGHT("inner_right"),
OUTER_LEFT("outer_left"),
OUTER_RIGHT("outer_right");
private final String name;
private EnumShape(String name)
{
this.name = name;
}
public static BlockRug.EnumShape getShape(BlockStairs.EnumShape shape) {
switch (shape) {
case STRAIGHT:
return BlockRug.EnumShape.STRAIGHT;
case INNER_LEFT:
return BlockRug.EnumShape.INNER_LEFT;
case INNER_RIGHT:
return BlockRug.EnumShape.INNER_RIGHT;
case OUTER_LEFT:
return BlockRug.EnumShape.OUTER_LEFT;
case OUTER_RIGHT:
return BlockRug.EnumShape.OUTER_RIGHT;
default:
return BlockRug.EnumShape.STRAIGHT;
}
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment