61 lines
2.4 KiB
Java
61 lines
2.4 KiB
Java
package ru.betterend.blocks;
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
|
import net.minecraft.world.item.enchantment.Enchantments;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.SnowLayerBlock;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.lighting.LayerLightEngine;
|
|
import net.minecraft.world.level.storage.loot.LootContext;
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|
import ru.bclib.blocks.BaseRotatedPillarBlock;
|
|
import ru.betterend.registry.EndBlocks;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
@SuppressWarnings("deprecation")
|
|
public class MossyDragonBoneBlock extends BaseRotatedPillarBlock {
|
|
public MossyDragonBoneBlock() {
|
|
super(FabricBlockSettings.copyOf(Blocks.BONE_BLOCK).hardness(0.5F).randomTicks());
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
|
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
|
if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
|
return Collections.singletonList(new ItemStack(this));
|
|
}
|
|
return Collections.singletonList(new ItemStack(EndBlocks.DRAGON_BONE_BLOCK));
|
|
}
|
|
|
|
@Override
|
|
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
|
|
if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) {
|
|
world.setBlockAndUpdate(pos, Blocks.BONE_BLOCK.defaultBlockState().setValue(AXIS, state.getValue(AXIS)));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) {
|
|
BlockPos blockPos = pos.above();
|
|
BlockState blockState = worldView.getBlockState(blockPos);
|
|
if (blockState.is(Blocks.SNOW) && blockState.getValue(SnowLayerBlock.LAYERS) == 1) {
|
|
return true;
|
|
}
|
|
else if (blockState.getFluidState().getAmount() == 8) {
|
|
return false;
|
|
}
|
|
else {
|
|
int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
|
|
return i < 5;
|
|
}
|
|
}
|
|
}
|