Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package shane.mod.objects;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.BlockRenderLayer;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.Mirror;
- import net.minecraft.util.Rotation;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import shane.mod.objects.blocks.blocksbase.BlockBase;
- public class yourblock extends BlockBase
- {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- public yourblock(String name, Material material, float hardness, float resistance, String tool, int level,
- CreativeTabs tab, SoundType sound, float value) {
- super(name, material, hardness, resistance, tool, level, tab, sound, value);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
- }
- @Override
- public BlockRenderLayer getBlockLayer()
- {
- return BlockRenderLayer.CUTOUT_MIPPED;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state)
- {
- return false;
- }
- @Override
- public boolean isFullBlock(IBlockState state)
- {
- return false;
- }
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
- {
- this.setDefaultFacing(worldIn, pos, state);
- }
- private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
- {
- if (!worldIn.isRemote)
- {
- IBlockState iblockstate = worldIn.getBlockState(pos.north());
- IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
- IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
- IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
- EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
- if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
- {
- enumfacing = EnumFacing.SOUTH;
- }
- else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
- {
- enumfacing = EnumFacing.NORTH;
- }
- else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
- {
- enumfacing = EnumFacing.EAST;
- }
- else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
- {
- enumfacing = EnumFacing.WEST;
- }
- worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
- }
- }
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
- }
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
- {
- worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- }
- public IBlockState getStateFromMeta(int meta)
- {
- EnumFacing enumfacing = EnumFacing.getFront(meta);
- if (enumfacing.getAxis() == EnumFacing.Axis.Y)
- {
- enumfacing = EnumFacing.NORTH;
- }
- return this.getDefaultState().withProperty(FACING, enumfacing);
- }
- public int getMetaFromState(IBlockState state)
- {
- return ((EnumFacing)state.getValue(FACING)).getIndex();
- }
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {FACING});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement