Created
June 25, 2015 20:50
-
-
Save StillManic/1b6ef809aa778e9dff46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CustomModelBlock4 extends Block | |
{ | |
public static final PropertyDirection FACING = PropertyDirection.create("facing"); | |
public static final CustomModelBlock4 instance = new CustomModelBlock4(); | |
public static final String name = "CustomModelBlock4"; | |
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[] {FACING}, new IUnlistedProperty[0]); | |
private CustomModelBlock4() | |
{ | |
super(Material.iron); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(name); | |
// this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
// @Override | |
// protected BlockState createBlockState() | |
// { | |
// return new BlockState(this, new IProperty[] {FACING}); | |
// } | |
// @Override | |
// public int getMetaFromState(IBlockState state) | |
// { | |
// EnumFacing facing = (EnumFacing) state.getValue(FACING); | |
// return facing.ordinal(); | |
// } | |
// | |
// @Override | |
// public IBlockState getStateFromMeta(int meta) | |
// { | |
// return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta)); | |
// } | |
@Override | |
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) | |
{ | |
return this.state.getBaseState().withProperty(FACING, state.getValue(FACING)); | |
} | |
@Override | |
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) | |
{ | |
world.setBlockState(pos, this.state.getBaseState().withProperty(FACING, this.getFacingFromEntity(world, pos, placer))); | |
} | |
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn) | |
{ | |
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F) | |
{ | |
double d0 = entityIn.posY + (double)entityIn.getEyeHeight(); | |
if (d0 - (double)clickedBlock.getY() > 2.0D) | |
{ | |
return EnumFacing.UP; | |
} | |
if ((double)clickedBlock.getY() - d0 > 0.0D) | |
{ | |
return EnumFacing.DOWN; | |
} | |
} | |
return entityIn.getHorizontalFacing().getOpposite(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment