Skip to content

Commit

Permalink
use FAPI mining level API
Browse files Browse the repository at this point in the history
- point wood, gold, and netherite tags to fabric tags
- use it to check drop correctness
  • Loading branch information
TropheusJ committed Dec 8, 2023
1 parent 995524d commit b19e790
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import io.github.fabricators_of_create.porting_lib.PortingConstants;

import net.fabricmc.fabric.api.mininglevel.v1.MiningLevelManager;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -182,15 +184,10 @@ public static List<Tier> getTiersLowerThan(Tier tier) {
}

/**
* Fallback for when a tier isn't in the registry, copy of the logic in {@link DiggerItem#isCorrectToolForDrops}
* Fallback for when a tier isn't in the registry
*/
private static boolean isCorrectTierVanilla(Tier tier, BlockState state) {
int i = tier.getLevel();
if (i < 3 && state.is(BlockTags.NEEDS_DIAMOND_TOOL)) {
return false;
} else if (i < 2 && state.is(BlockTags.NEEDS_IRON_TOOL)) {
return false;
} else return i >= 1 || !state.is(BlockTags.NEEDS_STONE_TOOL);
return tier.getLevel() >= MiningLevelManager.getRequiredMiningLevel(state);
}

private static void processTier(Tier tier, ResourceLocation name, List<Object> afters, List<Object> befores) {
Expand Down
10 changes: 6 additions & 4 deletions tags/src/main/java/me/alphamode/forgetags/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.mininglevel.v1.MiningLevelManager;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
import net.minecraft.world.entity.EntityType;

import net.minecraft.world.item.Tiers;

import org.jetbrains.annotations.Nullable;

import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DyeColor;
Expand Down Expand Up @@ -171,9 +173,9 @@ private static void init() {
public static final TagKey<Block> STORAGE_BLOCKS_RAW_IRON = tag("raw_iron_blocks");
public static final TagKey<Block> STORAGE_BLOCKS_REDSTONE = tag("redstone_blocks");

public static final TagKey<Block> NEEDS_WOOD_TOOL = tag("needs_wood_tool");
public static final TagKey<Block> NEEDS_GOLD_TOOL = tag("needs_gold_tool");
public static final TagKey<Block> NEEDS_NETHERITE_TOOL = tag("needs_netherite_tool");
public static final TagKey<Block> NEEDS_WOOD_TOOL = MiningLevelManager.getBlockTag(Tiers.WOOD.getLevel());
public static final TagKey<Block> NEEDS_GOLD_TOOL = MiningLevelManager.getBlockTag(Tiers.GOLD.getLevel());
public static final TagKey<Block> NEEDS_NETHERITE_TOOL = MiningLevelManager.getBlockTag(Tiers.NETHERITE.getLevel());

private static TagKey<Block> tag(String name) {
return TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation("c", name));
Expand Down

0 comments on commit b19e790

Please sign in to comment.