BetterEnd/src/main/java/ru/betterend/blocks/basis/BlockLogStripable.java
2020-09-26 15:40:09 +03:00

41 lines
1.6 KiB
Java

package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.PillarBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockLogStripable extends BlockPillar {
private final Block striped;
public BlockLogStripable(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).materialColor(color));
this.striped = striped;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getMainHandStack().getItem().isIn(FabricToolTags.AXES)) {
world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isClient) {
world.setBlockState(pos, striped.getDefaultState().with(PillarBlock.AXIS, state.get(PillarBlock.AXIS)), 11);
if (player != null && !player.isCreative()) {
player.getMainHandStack().damage(1, world.random, (ServerPlayerEntity) player);
}
}
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
}
}