Skip to content

Commit

Permalink
Enabled copper ore mining using wooden tools
Browse files Browse the repository at this point in the history
  • Loading branch information
JayCeeCreates committed Jun 23, 2021
1 parent bf0a042 commit 4e8160e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
50 changes: 50 additions & 0 deletions src/main/java/jayceecreates/earlygame/mixin/CopperMiningMixin.java
Original file line number Diff line number Diff line change
@@ -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<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}

}
3 changes: 2 additions & 1 deletion src/main/resources/earlygame.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4e8160e

Please sign in to comment.