diff --git a/src/main/java/jayceecreates/earlygame/mixin/CopperMiningMixin.java b/src/main/java/jayceecreates/earlygame/mixin/CopperMiningMixin.java new file mode 100644 index 0000000..ae19d39 --- /dev/null +++ b/src/main/java/jayceecreates/earlygame/mixin/CopperMiningMixin.java @@ -0,0 +1,50 @@ +package jayceecreates.earlygame.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.*; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.item.Item; +import net.minecraft.util.registry.Registry; + +// Thanks to Snowdaw#3874 from the Fabric Discord server for the help! + +@Mixin(PlayerEntity.class) +public abstract class CopperMiningMixin extends LivingEntity { + + @Shadow @Final + private PlayerInventory inventory; + + @Inject( + method = "canHarvest(Lnet/minecraft/block/BlockState;)Z", + at = @At("HEAD"), + cancellable = true + ) + private void canHarvest(BlockState state, CallbackInfoReturnable < Boolean > cir) { + Item heldItem = this.inventory.getMainHandStack().getItem(); + + if (heldItem instanceof ToolItem) { + int miningLevel = ((ToolItem) heldItem).getMaterial().getMiningLevel(); + String blockName = Registry.BLOCK.getId(state.getBlock()).toString(); + + if (heldItem instanceof PickaxeItem) + if (miningLevel == 0 && blockName.equals("minecraft:copper_ore")) + cir.setReturnValue(true); + } + } + + protected CopperMiningMixin(EntityType entityType, World world) { + super(entityType, world); + } + +} \ No newline at end of file diff --git a/src/main/resources/earlygame.mixins.json b/src/main/resources/earlygame.mixins.json index 315f31b..8498e73 100644 --- a/src/main/resources/earlygame.mixins.json +++ b/src/main/resources/earlygame.mixins.json @@ -2,9 +2,10 @@ "required": true, "minVersion": "0.8", "package": "jayceecreates.earlygame.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_16", "mixins": [ "BlockMiningMixin", + "CopperMiningMixin", "IngredientMixin", "MatchingStackAccessor", "RecipeFieldAccessor"