Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static final class Blocks {

public static final TagKey<Block> 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<Block> HEX_UNBREAKABLE = create("hex_unbreakable");

public static TagKey<Block> create(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <T : Enum<T>> Array<T>.getSafe(key: String, default: T = this[0]): T {
val lowercaseKey = key.lowercase(Locale.ROOT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ <T extends BlockEntity> BlockEntityType<T> createBlockEntityType(BiFunction<Bloc

// misc

boolean isCorrectTierForDrops(Tier tier, BlockState bs);

Ingredient getUnsealedIngredient(ItemStack stack);

IXplatTags tags();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,36 +330,6 @@ public Ingredient getUnsealedIngredient(ItemStack stack) {
return FabricUnsealedIngredient.of(stack);
}

// do a stupid hack from botania
private static List<ItemStack> stacks(Item... items) {
return Stream.of(items).map(ItemStack::new).toList();
}

private static final List<List<ItemStack>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading