Jump to content

Recommended Posts

Posted

Hello

My block renders well, but it doesn't display cracking animation when being mined. I tried to look to other block, that are not full cubes and have cracking animation, but I was unable to find what is my block missing. How can I enable the cracking animation?

My block class:

Spoiler

public class BlockBookshelfContainer extends Block
{
	
	public static final PropertyDirection FACING = BlockHorizontal.FACING;

	public BlockBookshelfContainer() 
	{
		super(Material.WOOD);
		this.setLightOpacity(0);
        this.setHardness(2.0F);
        this.setSoundType(SoundType.WOOD);
		this.setCreativeTab(CreativeTabs.DECORATIONS);
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	}
	
	public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }
	
	@Override
	public boolean isFullCube(IBlockState state)
	{
		return false;
	}
	
	@Override
	public boolean isOpaqueCube(IBlockState state)
	{
		return false;
	}
	
	public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
    {
		if (face.getAxis() == Axis.Y)
		{
			return BlockFaceShape.SOLID;
		}
        return face == (EnumFacing)state.getValue(FACING) ? BlockFaceShape.UNDEFINED : BlockFaceShape.SOLID;
    }
	
	protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, FACING);
    }
	
	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);
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
	public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }
	
	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)
    {
        super.onBlockPlacedBy(worldIn, pos, state, placer, stack);

        if (stack.hasDisplayName())
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityBookshelf)
            {
                ((TileEntityBookshelf)tileentity).setCustomName(stack.getDisplayName());
            }
        }
    }
	
	@Override
	public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
	{
		if (worldIn.getTileEntity(pos).getClass() == TileEntityBookshelf.class)
		{
			TileEntityBookshelf TE = (TileEntityBookshelf) worldIn.getTileEntity(pos);
			for (int i = 0; i < TE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getSlots(); i++)
			{
				ItemStack stack = TE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(i);
				worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack));
			}
		}
		super.breakBlock(worldIn, pos, state);
		worldIn.removeTileEntity(pos);
	}
	
	public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
    {
        if (te instanceof IWorldNameable && ((IWorldNameable)te).hasCustomName())
        {
            player.addStat(StatList.getBlockStats(this));
            player.addExhaustion(0.005F);

            if (worldIn.isRemote)
            {
                return;
            }

            int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
            Item item = this.getItemDropped(state, worldIn.rand, i);

            if (item == Items.AIR)
            {
                return;
            }

            ItemStack itemstack = new ItemStack(item, this.quantityDropped(worldIn.rand));
            itemstack.setStackDisplayName(((IWorldNameable)te).getName());
            spawnAsEntity(worldIn, pos, itemstack);
        }
        else
        {
            super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
        }
    }

	@Override
	public TileEntity createTileEntity(World world, IBlockState state) 
	{
		return new TileEntityBookshelf();
	}
	
	public boolean hasTileEntity(IBlockState state)
    {
        return true;
    }
	
	@Override
	public float getEnchantPowerBonus(World world, BlockPos pos)
	{
		if (world.getTileEntity(pos) instanceof TileEntityBookshelf)
		{
			TileEntityBookshelf bookshelf = (TileEntityBookshelf) world.getTileEntity(pos);
			return ((float) bookshelf.getBookCount()/3.0f);
		}
		return 0;
	}
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
	{
		if (!worldIn.isRemote)
		{
			playerIn.openGui(Main.instance, ModGUIHandler.ID_BOOKSHELF, worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
		return true;
	}
}

 

Thanks for any help

Posted
9 minutes ago, fcelon said:

I have already tried setting it to true. It has no effect.

You will also need to have a FastTESR that renders the appropriate break stage. Or you could not return BlockFaceShape.UNDEFINED in Block#getBlockFaceShape

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.