- 103
- 2
- 2
Делаю ломатель блоков, ломает нормально, но ломает пока-что только над собой, как мне учитывать направление взгляда? EnumFacing на 1.15.2 отсутствует.
blockbreaker block:
public blockbreaker(){
super(Properties.create(Material.IRON)
.hardnessAndResistance(2.0f)
.harvestLevel(2)
.harvestTool(ToolType.PICKAXE)
.sound(SoundType.METAL)
);
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH));
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite().getOpposite());
}
blockbreaker tileentity:
@Override
public void tick(){
if (!this.world.isRemote) {
ItemStack itemstack = this.inventory.getStackInSlot(0);//Get ITEMSTACK from slot
BlockPos blockp= pos.offset(Direction.UP,1);//Get XYZ block which need to break
Block block=world.getBlockState(blockp).getBlock();//Get block which need to break
System.out.print(block);
ItemStack itemstack2 = new ItemStack(Item.getItemFromBlock(block));//Get ITEMSTACK from BLOCK which we break
if (world.isAirBlock(blockp)==false && itemstack.getCount()<=63){//If block is not air and item stack dont equal 64
if (itemstack.isEmpty()){//If slot don't have any item, then set itemstack from block
this.inventory.setStackInSlot(0, itemstack2.copy());//Set itemstack
}else if (itemstack.getItem()==itemstack2.getItem()){//If slot have any item and block which we break equivalent block which contained in slot, then increase itemstack
itemstack.setCount(itemstack.getCount()+1);
}
world.destroyBlock(blockp,false);//just break the block
}
}
}