Minor cleanup for tool breaking behavior
This commit is contained in:
parent
5154513cd4
commit
77eba4b33f
3 changed files with 36 additions and 12 deletions
|
@ -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.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
|
import net.minecraft.data.loot.BlockLoot;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
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.EnchantmentHelper;
|
||||||
import net.minecraft.world.item.enchantment.Enchantments;
|
import net.minecraft.world.item.enchantment.Enchantments;
|
||||||
import net.minecraft.world.level.block.Block;
|
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.material.MaterialColor;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
|
import ru.bclib.api.TagAPI;
|
||||||
import ru.bclib.client.render.BCLRenderLayer;
|
import ru.bclib.client.render.BCLRenderLayer;
|
||||||
import ru.bclib.interfaces.BlockModelProvider;
|
import ru.bclib.interfaces.BlockModelProvider;
|
||||||
import ru.bclib.interfaces.RenderLayerProvider;
|
import ru.bclib.interfaces.RenderLayerProvider;
|
||||||
|
@ -30,9 +33,9 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
|
||||||
private static FabricBlockSettings makeLeaves(MaterialColor color) {
|
private static FabricBlockSettings makeLeaves(MaterialColor color) {
|
||||||
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
|
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
|
||||||
.mapColor(color)
|
.mapColor(color)
|
||||||
.breakByTool(FabricToolTags.HOES)
|
.requiresTool()
|
||||||
.breakByTool(FabricToolTags.SHEARS)
|
.breakByTool(FabricToolTags.SHEARS)
|
||||||
.breakByHand(true)
|
.breakByTool(FabricToolTags.HOES)
|
||||||
.allowsSpawning((state, world, pos, type) -> false)
|
.allowsSpawning((state, world, pos, type) -> false)
|
||||||
.suffocates((state, world, pos) -> false)
|
.suffocates((state, world, pos) -> false)
|
||||||
.blockVision((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)));
|
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color)));
|
||||||
this.sapling = sapling;
|
this.sapling = sapling;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer<FabricBlockSettings> customizeProperties) {
|
public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer<FabricBlockSettings> customizeProperties) {
|
||||||
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
|
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
|
||||||
this.sapling = sapling;
|
this.sapling = sapling;
|
||||||
|
@ -68,7 +71,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
|
||||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||||
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
||||||
if (tool != null) {
|
if (tool != null) {
|
||||||
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
|
if (tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel(
|
||||||
Enchantments.SILK_TOUCH,
|
Enchantments.SILK_TOUCH,
|
||||||
tool
|
tool
|
||||||
) > 0) {
|
) > 0) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package ru.bclib.blocks;
|
package ru.bclib.blocks;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Mth;
|
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.material.MaterialColor;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
|
import ru.bclib.api.TagAPI;
|
||||||
import ru.bclib.interfaces.BlockModelProvider;
|
import ru.bclib.interfaces.BlockModelProvider;
|
||||||
import ru.bclib.util.MHelper;
|
import ru.bclib.util.MHelper;
|
||||||
|
|
||||||
|
@ -29,16 +32,30 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider {
|
||||||
private final int maxCount;
|
private final int maxCount;
|
||||||
|
|
||||||
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
|
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
|
||||||
this(drop, minCount, maxCount, experience, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
|
this(drop, minCount, maxCount, experience, 0);
|
||||||
.destroyTime(3F)
|
|
||||||
.explosionResistance(9F)
|
|
||||||
.requiresCorrectToolForDrops()
|
|
||||||
.sound(SoundType.STONE));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) {
|
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel) {
|
||||||
super(properties, UniformInt.of(experience>0?1:0, experience));
|
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.dropItem = drop;
|
||||||
this.minCount = minCount;
|
this.minCount = minCount;
|
||||||
this.maxCount = maxCount;
|
this.maxCount = maxCount;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.bclib.registry;
|
package ru.bclib.registry;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags;
|
||||||
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -10,6 +11,7 @@ import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import ru.bclib.api.TagAPI;
|
import ru.bclib.api.TagAPI;
|
||||||
import ru.bclib.blocks.BaseLeavesBlock;
|
import ru.bclib.blocks.BaseLeavesBlock;
|
||||||
|
import ru.bclib.blocks.BaseOreBlock;
|
||||||
import ru.bclib.blocks.FeatureSaplingBlock;
|
import ru.bclib.blocks.FeatureSaplingBlock;
|
||||||
import ru.bclib.config.PathConfig;
|
import ru.bclib.config.PathConfig;
|
||||||
import ru.bclib.interfaces.CustomItemProvider;
|
import ru.bclib.interfaces.CustomItemProvider;
|
||||||
|
@ -41,10 +43,12 @@ public class BlockRegistry extends BaseRegistry<Block> {
|
||||||
getModBlocks(id.getNamespace()).add(block);
|
getModBlocks(id.getNamespace()).add(block);
|
||||||
|
|
||||||
if (block instanceof BaseLeavesBlock){
|
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){
|
if (item != null){
|
||||||
TagAPI.addTags(item, TagAPI.ITEM_LEAVES);
|
TagAPI.addTags(item, TagAPI.ITEM_LEAVES);
|
||||||
}
|
}
|
||||||
|
} else if (block instanceof BaseOreBlock){
|
||||||
|
TagAPI.addTags(block, TagAPI.MINEABLE_PICKAXE);
|
||||||
} else if (block instanceof FeatureSaplingBlock){
|
} else if (block instanceof FeatureSaplingBlock){
|
||||||
TagAPI.addTags(block, TagAPI.BLOCK_SAPLINGS);
|
TagAPI.addTags(block, TagAPI.BLOCK_SAPLINGS);
|
||||||
if (item != null){
|
if (item != null){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue