Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 onBlockPlaced(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);
- }
- @Override
- public EnumBlockRenderType getRenderType(IBlockState state)
- {
- return EnumBlockRenderType.MODEL;
- }
- 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)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement