diff --git a/CHANGELOG.md b/CHANGELOG.md index d401546f73..d5289464a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added - Updated to Minecraft 1.21.1 ([#985](https://github.com/FallingColors/HexMod/pull/985)) @SuperKnux @slava110 +- Added the `hex_unbreakable` tag for blocks that should be immune to Break Block regardless of the configured mining tier ([#1186](https://github.com/FallingColors/HexMod/pull/1186)) @Robotgiggle @slava110 ### Fixed diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java index 47b9dab60b..8230034ac1 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java @@ -54,7 +54,7 @@ public static final class Blocks { public static final TagKey CHEAP_TO_BREAK_BLOCK = create("cheap_to_break_block"); - //blocks unbreakable by Break Block + //blocks unbreakable by Break Block, regardless of tier public static final TagKey HEX_UNBREAKABLE = create("hex_unbreakable"); public static TagKey create(String name) { diff --git a/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt b/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt index aa4999873b..061ae27931 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/utils/HexUtils.kt @@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.casting.iota.ListIota import at.petrak.hexcasting.api.casting.iota.NullIota import at.petrak.hexcasting.api.casting.math.HexCoord import at.petrak.hexcasting.api.casting.validateSubIotas +import at.petrak.hexcasting.api.mod.HexTags import net.minecraft.ChatFormatting import net.minecraft.core.HolderLookup import net.minecraft.core.Registry @@ -21,6 +22,8 @@ import net.minecraft.server.level.ServerLevel import net.minecraft.tags.TagKey import net.minecraft.world.InteractionHand import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.Tier +import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.phys.Vec2 import net.minecraft.world.phys.Vec3 import java.lang.ref.WeakReference @@ -108,6 +111,12 @@ fun pxToCoord(px: Vec2, size: Float, offset: Vec2): HexCoord { HexCoord(q, r + (rf + 0.5 * qf).roundToInt()) } +fun isCorrectTierForDrops(tier: Tier, bs: BlockState): Boolean { + val tierTooLow = bs.`is`(tier.incorrectBlocksForDrops) + val blacklisted = bs.`is`(HexTags.Blocks.HEX_UNBREAKABLE) + return !(tierTooLow || blacklisted) +} + @JvmOverloads fun > Array.getSafe(key: String, default: T = this[0]): T { val lowercaseKey = key.lowercase(Locale.ROOT) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBreakBlock.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBreakBlock.kt index 796e82ccd0..f478e55ce6 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBreakBlock.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBreakBlock.kt @@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.mod.HexTags +import at.petrak.hexcasting.api.utils.isCorrectTierForDrops import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos import net.minecraft.server.level.ServerPlayer @@ -43,7 +44,7 @@ object OpBreakBlock : SpellAction { if ( !blockstate.isAir && blockstate.getDestroySpeed(env.world, pos) >= 0f // fix being able to break bedrock &c - && IXplatAbstractions.INSTANCE.isCorrectTierForDrops(tier, blockstate) + && isCorrectTierForDrops(tier, blockstate) && IXplatAbstractions.INSTANCE.isBreakingAllowed( env.world, pos, diff --git a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java index dd38a214b0..125479390d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java +++ b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java @@ -155,8 +155,6 @@ BlockEntityType createBlockEntityType(BiFunction stacks(Item... items) { - return Stream.of(items).map(ItemStack::new).toList(); - } - - private static final List> HARVEST_TOOLS_BY_LEVEL = List.of( - stacks(Items.WOODEN_PICKAXE, Items.WOODEN_AXE, Items.WOODEN_HOE, Items.WOODEN_SHOVEL), - stacks(Items.STONE_PICKAXE, Items.STONE_AXE, Items.STONE_HOE, Items.STONE_SHOVEL), - stacks(Items.IRON_PICKAXE, Items.IRON_AXE, Items.IRON_HOE, Items.IRON_SHOVEL), - stacks(Items.DIAMOND_PICKAXE, Items.DIAMOND_AXE, Items.DIAMOND_HOE, Items.DIAMOND_SHOVEL), - stacks(Items.NETHERITE_PICKAXE, Items.NETHERITE_AXE, Items.NETHERITE_HOE, Items.NETHERITE_SHOVEL) - ); - - @Override - public boolean isCorrectTierForDrops(Tier tier, BlockState bs) { - if (!bs.requiresCorrectToolForDrops()) { - return true; - } - - int level = HexConfig.server() - .opBreakHarvestLevelBecauseForgeThoughtItWasAGoodIdeaToImplementHarvestTiersUsingAnHonestToGodTopoSort(); - for (var tool : HARVEST_TOOLS_BY_LEVEL.get(level)) { - if (tool.isCorrectToolForDrops(bs)) { - return true; - } - } - - return false; - } - @Override public Item.Properties addEquipSlotFabric(EquipmentSlot slot) { return new Item.Properties().equipmentSlot((e, s) -> slot); diff --git a/Neoforge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java b/Neoforge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java index 5acbe02d87..65d77b6329 100644 --- a/Neoforge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java +++ b/Neoforge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java @@ -396,12 +396,6 @@ public Ingredient getUnsealedIngredient(ItemStack stack) { return ForgeUnsealedIngredient.of(stack).toVanilla(); } - @Override - public boolean isCorrectTierForDrops(Tier tier, BlockState bs) { - // TODO port: check tag - return !bs.is(HexTags.Blocks.HEX_UNBREAKABLE); - } - @Override public Item.Properties addEquipSlotFabric(EquipmentSlot slot) { return new Item.Properties();