-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78d430e
commit 3589206
Showing
7 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Common/src/main/java/dev/upcraft/sparkweave/api/event/ItemMenuInteractionEvent.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,32 @@ | ||
package dev.upcraft.sparkweave.api.event; | ||
|
||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.ClickAction; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
|
||
public interface ItemMenuInteractionEvent { | ||
Event<ItemMenuInteractionEvent> EVENT = Event.create(ItemMenuInteractionEvent.class, listeners -> (menu, player, level, clickAction, slot, slotStack, cursorStack) -> { | ||
for(ItemMenuInteractionEvent listener : listeners) { | ||
boolean cancel = listener.interactWithItemInMenu(menu, player, level, clickAction, slot, slotStack, cursorStack); | ||
|
||
if(cancel) | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
/** | ||
* @param menu The menu the player is in | ||
* @param player The player doing the interaction | ||
* @param clickAction The mouse button being clicked | ||
* @param slot The slot the item being interacted with is in | ||
* @param slotStack The {@link ItemStack} in the menu that's being interacted with | ||
* @param cursorStack The {@link ItemStack} currently being held by the user's cursor | ||
* @return Whether to cancel the normal interaction that would happen | ||
*/ | ||
boolean interactWithItemInMenu(AbstractContainerMenu menu, Player player, Level level, ClickAction clickAction, Slot slot, ItemStack slotStack, ItemStack cursorStack); | ||
} |
8 changes: 8 additions & 0 deletions
8
Common/src/main/java/dev/upcraft/sparkweave/mixin/AbstractContainerMenuMixin.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,8 @@ | ||
package dev.upcraft.sparkweave.mixin; | ||
|
||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@Mixin(AbstractContainerMenu.class) | ||
public class AbstractContainerMenuMixin { | ||
} |
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
27 changes: 27 additions & 0 deletions
27
Fabric/src/main/java/dev/upcraft/sparkweave/fabric/mixin/AbstractContainerMenuMixin.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,27 @@ | ||
package dev.upcraft.sparkweave.fabric.mixin; | ||
|
||
import dev.upcraft.sparkweave.api.event.ItemMenuInteractionEvent; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.ClickAction; | ||
import net.minecraft.world.inventory.ClickType; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@Mixin(AbstractContainerMenu.class) | ||
public class AbstractContainerMenuMixin { | ||
@Inject( | ||
method = "doClick", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;updateTutorialInventoryAction(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/inventory/ClickAction;)V"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true | ||
) | ||
private void handleItemClickEvent(int slotId, int button, ClickType clickType, Player player, CallbackInfo info, ClickAction clickAction, Slot slot, ItemStack slotStack, ItemStack cursorStack) { | ||
if(ItemMenuInteractionEvent.EVENT.invoker().interactWithItemInMenu((AbstractContainerMenu) (Object) this, player, player.level(), clickAction, slot, slotStack, cursorStack)) | ||
info.cancel(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/mixin/AbstractContainerMenuMixin.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,29 @@ | ||
package dev.upcraft.sparkweave.neoforge.mixin; | ||
|
||
import dev.upcraft.sparkweave.api.event.ItemMenuInteractionEvent; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.ClickAction; | ||
import net.minecraft.world.inventory.ClickType; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@SuppressWarnings("InvalidInjectorMethodSignature") | ||
@Mixin(AbstractContainerMenu.class) | ||
public class AbstractContainerMenuMixin { | ||
@Inject( | ||
method = "doClick", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;updateTutorialInventoryAction(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/inventory/ClickAction;)V"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true | ||
) | ||
private void handleItemClickEvent(int slotId, int button, ClickType clickType, Player player, CallbackInfo info, Inventory inventory, ClickAction clickAction, Slot slot, ItemStack slotStack, ItemStack cursorStack) { | ||
if(ItemMenuInteractionEvent.EVENT.invoker().interactWithItemInMenu((AbstractContainerMenu) (Object) this, player, player.level(), clickAction, slot, slotStack, cursorStack)) | ||
info.cancel(); | ||
} | ||
} |
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