BCLib/src/main/java/org/betterx/bclib/blocks/BaseStripableLogBlock.java
2022-05-18 23:56:23 +02:00

54 lines
2.2 KiB
Java

package org.betterx.bclib.blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.BlockHitResult;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import org.betterx.bclib.api.tag.NamedMineableTags;
import org.betterx.bclib.api.tag.TagAPI;
public class BaseStripableLogBlock extends BaseRotatedPillarBlock {
private final Block striped;
public BaseStripableLogBlock(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).color(color));
this.striped = striped;
}
@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state,
Level world,
BlockPos pos,
Player player,
InteractionHand hand,
BlockHitResult hit) {
if (TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.AXE)) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos,
striped.defaultBlockState()
.setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)),
11
);
if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}
}
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}
}