From 77eba4b33ffa0f19cce1695be68ad0ebc35b7d3d Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 14:44:14 +0100 Subject: [PATCH] Minor cleanup for tool breaking behavior --- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 11 ++++--- .../java/ru/bclib/blocks/BaseOreBlock.java | 31 ++++++++++++++----- .../java/ru/bclib/registry/BlockRegistry.java | 6 +++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 3dd32197..784667b3 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -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 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 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) { diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index 31963438..fa009b6f 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -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; diff --git a/src/main/java/ru/bclib/registry/BlockRegistry.java b/src/main/java/ru/bclib/registry/BlockRegistry.java index 608e9ca7..bf067f1e 100644 --- a/src/main/java/ru/bclib/registry/BlockRegistry.java +++ b/src/main/java/ru/bclib/registry/BlockRegistry.java @@ -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 { 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){