Minor cleanup for tool breaking behavior

This commit is contained in:
Frank 2021-12-03 14:44:14 +01:00
parent 5154513cd4
commit 77eba4b33f
3 changed files with 36 additions and 12 deletions

View file

@ -4,8 +4,10 @@ import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.data.loot.BlockLoot;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Block;
@ -15,6 +17,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.api.TagAPI;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
@ -30,9 +33,9 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
private static FabricBlockSettings makeLeaves(MaterialColor color) {
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.mapColor(color)
.breakByTool(FabricToolTags.HOES)
.requiresTool()
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.breakByTool(FabricToolTags.HOES)
.allowsSpawning((state, world, pos, type) -> false)
.suffocates((state, world, pos) -> false)
.blockVision((state, world, pos) -> false);
@ -42,7 +45,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color)));
this.sapling = sapling;
}
public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer<FabricBlockSettings> customizeProperties) {
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
this.sapling = sapling;
@ -68,7 +71,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
if (tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {

View file

@ -1,6 +1,8 @@
package ru.bclib.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
@ -17,6 +19,7 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.api.TagAPI;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.util.MHelper;
@ -29,16 +32,30 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider {
private final int maxCount;
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
this(drop, minCount, maxCount, experience, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.destroyTime(3F)
.explosionResistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE));
this(drop, minCount, maxCount, experience, 0);
}
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) {
super(properties, UniformInt.of(experience>0?1:0, experience));
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel) {
this(drop, minCount, maxCount, experience, miningLevel, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.requiresTool()
.destroyTime(3F)
.explosionResistance(9F)
.sound(SoundType.STONE));
}
private static Properties makeProps(Properties properties, int level){
FabricBlockInternals.computeExtraData(properties).addMiningLevel(FabricToolTags.PICKAXES, level);
return properties;
}
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) {
this(drop, minCount, maxCount, experience, 0, properties);
}
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel, Properties properties) {
super(makeProps(properties, miningLevel), UniformInt.of(experience>0?1:0, experience));
this.dropItem = drop;
this.minCount = minCount;
this.maxCount = maxCount;

View file

@ -1,5 +1,6 @@
package ru.bclib.registry;
import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
@ -10,6 +11,7 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import ru.bclib.api.TagAPI;
import ru.bclib.blocks.BaseLeavesBlock;
import ru.bclib.blocks.BaseOreBlock;
import ru.bclib.blocks.FeatureSaplingBlock;
import ru.bclib.config.PathConfig;
import ru.bclib.interfaces.CustomItemProvider;
@ -41,10 +43,12 @@ public class BlockRegistry extends BaseRegistry<Block> {
getModBlocks(id.getNamespace()).add(block);
if (block instanceof BaseLeavesBlock){
TagAPI.addTags(block, TagAPI.BLOCK_LEAVES);
TagAPI.addTags(block, TagAPI.BLOCK_LEAVES, TagAPI.MINEABLE_HOE, FabricMineableTags.SHEARS_MINEABLE);
if (item != null){
TagAPI.addTags(item, TagAPI.ITEM_LEAVES);
}
} else if (block instanceof BaseOreBlock){
TagAPI.addTags(block, TagAPI.MINEABLE_PICKAXE);
} else if (block instanceof FeatureSaplingBlock){
TagAPI.addTags(block, TagAPI.BLOCK_SAPLINGS);
if (item != null){