Skip to content

Commit

Permalink
Make PlayerInteractEvent Mixins compile on 1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 25, 2024
1 parent ef6a39e commit 7c47aa8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions versions/mappings/forge-1.12.2-1.8.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ net.minecraft.util.text.TextFormatting net.minecraft.util.EnumChatFormatting

net.minecraft.client.renderer.entity.RenderLiving net.minecraft.client.renderer.entity.RendererLivingEntity

net.minecraft.util.math.RayTraceResult net.minecraft.util.MovingObjectPosition

org.objectweb.asm.commons.ClassRemapper org.objectweb.asm.commons.RemappingClassAdapter
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,27 @@ public class Mixin_PlayerInteractEvent_LeftAction {
@Shadow public MovingObjectPosition objectMouseOver;
@Shadow public EntityPlayerSP thePlayer;

@Shadow private int leftClickCounter;
@Unique private PlayerInteractEvent lastAttackEvent;

@Inject(method = "clickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;swingItem()V", shift = At.Shift.BEFORE), cancellable = true)
@Inject(
method = "clickMouse",
at = @At(
//#if MC >= 1.12.2
//$$ value = "HEAD"
//#else
value = "INVOKE",
target = "Lnet/minecraft/client/entity/EntityPlayerSP;swingItem()V",
shift = At.Shift.BEFORE
//#endif
),
cancellable = true
)
private void onPlayerAttackCallback(CallbackInfo ci) {
if (this.leftClickCounter > 0) {
return;
}

MovingObjectPosition rayCastedObject = this.objectMouseOver;
PlayerInteractEvent.Type type = PlayerInteractEvent.Type.AIR;
if (rayCastedObject != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ public class Mixin_PlayerInteractEvent_RightAction {
@Shadow public MovingObjectPosition objectMouseOver;
@Shadow public EntityPlayerSP thePlayer;

@Inject(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/InventoryPlayer;getCurrentItem()Lnet/minecraft/item/ItemStack;"), cancellable = true)
@Inject(
method = "rightClickMouse",
at = @At(
value = "INVOKE",
//#if MC >= 1.12.2
//$$ target = "Lnet/minecraft/client/entity/EntityPlayerSP;getHeldItem(Lnet/minecraft/util/EnumHand;)Lnet/minecraft/item/ItemStack;"
//#else
target = "Lnet/minecraft/entity/player/InventoryPlayer;getCurrentItem()Lnet/minecraft/item/ItemStack;"
//#endif
),
cancellable = true
)
private void onPlayerInteractCallback(CallbackInfo ci) {
MovingObjectPosition rayCastedObject = this.objectMouseOver;
PlayerInteractEvent.Type type = PlayerInteractEvent.Type.AIR;
Expand Down

0 comments on commit 7c47aa8

Please sign in to comment.