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
bc3a544
commit 4165b6f
Showing
5 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
src/main/java/org/auioc/mcmod/arnicalib/common/event/impl/ItemInventoryTickEvent.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,49 @@ | ||
package org.auioc.mcmod.arnicalib.common.event.impl; | ||
|
||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.event.entity.player.PlayerEvent; | ||
import net.minecraftforge.eventbus.api.Cancelable; | ||
|
||
public class ItemInventoryTickEvent extends PlayerEvent { | ||
|
||
private final Level level; | ||
private final ItemStack itemStack; | ||
private final int index; | ||
private final boolean selected; | ||
|
||
public ItemInventoryTickEvent(Player player, Level level, ItemStack itemStack, int index, boolean selected) { | ||
super(player); | ||
this.level = level; | ||
this.itemStack = itemStack; | ||
this.index = index; | ||
this.selected = selected; | ||
} | ||
|
||
public Level getLevel() { | ||
return this.level; | ||
} | ||
|
||
public ItemStack getItemStack() { | ||
return this.itemStack; | ||
} | ||
|
||
public int getIndex() { | ||
return this.index; | ||
} | ||
|
||
public boolean isSelected() { | ||
return this.selected; | ||
} | ||
|
||
@Cancelable | ||
public static class Selected extends ItemInventoryTickEvent { | ||
|
||
public Selected(Player player, Level level, ItemStack itemStack, int index) { | ||
super(player, level, itemStack, index, true); | ||
} | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/auioc/mcmod/arnicalib/mixin/common/MixinItemStack.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 org.auioc.mcmod.arnicalib.mixin.common; | ||
|
||
import org.auioc.mcmod.arnicalib.common.event.CommonEventFactory; | ||
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 net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
|
||
@Mixin(value = ItemStack.class) | ||
public class MixinItemStack { | ||
|
||
// @org.spongepowered.asm.mixin.Debug(export = true, print = true) | ||
@Inject( | ||
method = "Lnet/minecraft/world/item/ItemStack;inventoryTick(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;IZ)V", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;", ordinal = 1), | ||
require = 1, | ||
allow = 1, | ||
cancellable = true | ||
) | ||
private void onInventoryTick(Level p_41667_, Entity p_41668_, int p_41669_, boolean p_41670_, CallbackInfo ci) { | ||
if (p_41670_ && p_41668_ instanceof Player player) { | ||
if (CommonEventFactory.onSelectedItemItemInventoryTick(player, p_41667_, ((ItemStack) (Object) this), p_41669_)) { | ||
ci.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
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