47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
package ru.betterend.blocks;
|
|
|
|
import java.util.List;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
import net.minecraft.enchantment.Enchantments;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.damage.DamageSource;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.Items;
|
|
import net.minecraft.loot.context.LootContext;
|
|
import net.minecraft.loot.context.LootContextParameters;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
import ru.betterend.blocks.basis.EndPlantBlock;
|
|
import ru.betterend.registry.EndBlocks;
|
|
import ru.betterend.util.MHelper;
|
|
|
|
public class NeedlegrassBlock extends EndPlantBlock {
|
|
@Override
|
|
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
|
if (entity instanceof LivingEntity) {
|
|
entity.damage(DamageSource.CACTUS, 0.1F);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
|
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
|
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) || EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
|
return Lists.newArrayList(new ItemStack(this));
|
|
}
|
|
else {
|
|
return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM)));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected boolean isTerrain(BlockState state) {
|
|
return state.isOf(EndBlocks.SHADOW_GRASS);
|
|
}
|
|
}
|