-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Electric Chainsaws Voiding Items
- Loading branch information
1 parent
0e2931a
commit 86f3c84
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/com/nomiceu/nomilabs/mixin/gregtech/ToolEventHandlersMixin.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,35 @@ | ||
package com.nomiceu.nomilabs.mixin.gregtech; | ||
|
||
import net.minecraft.util.EnumHand; | ||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import gregtech.common.ToolEventHandlers; | ||
|
||
/** | ||
* Fix chainsaw breaking replacing currently held item with power unit, regardless of whether it is the chainsaw. | ||
*/ | ||
@Mixin(value = ToolEventHandlers.class, remap = false) | ||
public class ToolEventHandlersMixin { | ||
|
||
@Redirect(method = "onPlayerDestroyItem", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraftforge/event/entity/player/PlayerDestroyItemEvent;getHand()Lnet/minecraft/util/EnumHand;", | ||
ordinal = 0), | ||
require = 1) | ||
private static EnumHand checkForSameStack(PlayerDestroyItemEvent instance) { | ||
var hand = instance.getHand(); | ||
if (hand == null) return null; | ||
|
||
// For the tree felling routine, the player may no longer be holding the chainsaw | ||
// Check for exact instance equality, and if not, return null | ||
// Returning null leads to the item being added to inventory instead of replacing item in hand | ||
if (instance.getEntityPlayer().getHeldItem(hand) != instance.getOriginal()) | ||
return null; | ||
|
||
return hand; | ||
} | ||
} |
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