47 lines
1.8 KiB
Java
47 lines
1.8 KiB
Java
package ru.betterend.blocks;
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.world.level.material.Material;
|
|
import ru.bclib.blocks.BaseBlock;
|
|
import ru.bclib.blocks.BlockProperties;
|
|
import ru.betterend.registry.EndBlocks;
|
|
|
|
public class BlueVineLanternBlock extends BaseBlock {
|
|
public static final BooleanProperty NATURAL = BlockProperties.NATURAL;
|
|
|
|
public BlueVineLanternBlock() {
|
|
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WART_BLOCK));
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(NATURAL, false));
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
|
return !state.getValue(NATURAL) || world.getBlockState(pos.below()).getBlock() == EndBlocks.BLUE_VINE;
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
|
if (!canSurvive(state, world, pos)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
else {
|
|
return state;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
|
|
stateManager.add(NATURAL);
|
|
}
|
|
}
|