Версия Minecraft
1.12.2
683
3
21
Блок падает при разрушении блока под ним что с этим делать?
Java:
package en.tiref.la.objects.Blocks;

import en.tiref.la.init.BlockInit;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
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.entity.EntityLivingBase;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class RemainsBlock extends BlockBase {
    
    public static AxisAlignedBB RemainsBlock_AABB = new AxisAlignedBB(0, 0, 0, 1, 0.5, 1);
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
    {
        this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
    }
    public RemainsBlock(String name) {
        super(name, Material.ROCK);
        
    }
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        EnumFacing facing = EnumFacing.getFront(meta);

        if(facing.getAxis()==EnumFacing.Axis.Y)
        {
            facing=EnumFacing.NORTH;
        }
        return getDefaultState().withProperty(FACING, facing);
    }
    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing) state.getValue(FACING)).getIndex();
    }   
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[]{FACING});
    }
    @Override
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos,EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
      return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }
    
    private boolean canBlockStay(World worldIn, BlockPos pos)
    {
        return worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos, EnumFacing.UP);
    }
    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
    }
    @Override
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
    {
        if(!this.canBlockStay(worldIn, pos))
        {
            worldIn.setBlockToAir(pos);
            InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(BlockInit.RemainsBlock));
        }
    }
    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }   
@Override
public boolean isOpaqueCube(IBlockState state) {
    return false;
   }

@Override
public boolean isFullCube(IBlockState state) {
       return false;
   }
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess acess, BlockPos pos) {
     return RemainsBlock_AABB;
  }

}
 
7,099
324
1,509
Как песок и гравий?

@Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
if(!this.canBlockStay(worldIn, pos)) {
worldIn.setBlockToAir(pos);
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(BlockInit.RemainsBlock));
}
}
Или в виде предмета?
 
3,005
192
592
3,005
192
592
Сверху