-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled copper ore mining using wooden tools
- Loading branch information
1 parent
bf0a042
commit 4e8160e
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/jayceecreates/earlygame/mixin/CopperMiningMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters