Skip to content

Commit

Permalink
use MiningLevelManager
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jan 10, 2024
1 parent 7f25590 commit 3796468
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

import io.github.fabricators_of_create.porting_lib.loot.LootModifierManager;
import io.github.fabricators_of_create.porting_lib.loot.LootTableIdCondition;
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemStackHandler;
import io.github.fabricators_of_create.porting_lib.util.CanToolPerformAction;
import io.github.fabricators_of_create.porting_lib.util.UsernameCache;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.core.Registry;

import net.minecraft.world.item.ItemStack;

import net.minecraft.world.item.Items;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,8 +22,6 @@
import net.fabricmc.api.ModInitializer;
import net.minecraft.resources.ResourceLocation;

import java.util.Arrays;

public class PortingLib implements ModInitializer {
public static final String ID = "porting_lib";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.fabricators_of_create.porting_lib.mixin.common.hack;

import me.alphamode.forgetags.Tags;

import net.fabricmc.fabric.api.mininglevel.v1.MiningLevelManager;
import net.minecraft.tags.TagKey;

import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.block.Block;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* ForgeTags is not being updated as it has been merged into newer Porting Lib versions.
* Gross fix for #70
*/
@Mixin(value = Tags.Blocks.class, remap = false)
public class Tags$BlocksMixin {
@Inject(method = "tag", at = @At("HEAD"), cancellable = true)
private static void useFapiTags(String name, CallbackInfoReturnable<TagKey<Block>> cir) {
if ("needs_netherite_tool".equals(name)) {
TagKey<Block> fapiTag = MiningLevelManager.getBlockTag(Tiers.NETHERITE.getLevel());
cir.setReturnValue(fapiTag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import io.github.fabricators_of_create.porting_lib.PortingLib;

import net.fabricmc.fabric.api.mininglevel.v1.MiningLevelManager;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;

Expand Down Expand Up @@ -190,15 +191,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
3 changes: 2 additions & 1 deletion src/main/resources/porting_lib.mixins.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@
"accessor.SlotAccessor",
"accessor.StairBlockAccessor",
"accessor.StructureTemplateAccessor",
"accessor.TagValueAccessor"
"accessor.TagValueAccessor",
"hack.Tags$BlocksMixin"
],
"injectors": {
"defaultRequire": 1,
Expand Down

0 comments on commit 3796468

Please sign in to comment.