|
7 | 7 | import com.circulation.random_complement.client.handler.RCJEIInputHandler; |
8 | 8 | import com.circulation.random_complement.common.CommonProxy; |
9 | 9 | import com.circulation.random_complement.common.util.Functions; |
| 10 | +import com.circulation.random_complement.mixin.jei.AccessorGhostIngredientDragManager; |
10 | 11 | import com.circulation.random_complement.mixin.jei.AccessorInputHandler; |
11 | 12 | import it.unimi.dsi.fastutil.objects.ReferenceArrayList; |
12 | 13 | import it.unimi.dsi.fastutil.objects.ReferenceList; |
13 | 14 | import lombok.val; |
14 | 15 | import mezz.jei.Internal; |
15 | 16 | import mezz.jei.bookmarks.BookmarkItem; |
16 | | -import mezz.jei.input.IClickedIngredient; |
17 | | -import mezz.jei.input.MouseHelper; |
| 17 | +import mezz.jei.gui.ghost.GhostIngredientDrag; |
18 | 18 | import net.minecraft.client.Minecraft; |
19 | 19 | import net.minecraft.item.ItemStack; |
20 | 20 | import net.minecraftforge.common.MinecraftForge; |
21 | 21 | import net.minecraftforge.fml.common.Loader; |
| 22 | +import net.minecraftforge.fml.common.Mod; |
22 | 23 | import net.minecraftforge.fml.common.Optional; |
| 24 | +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
| 25 | +import net.minecraftforge.fml.common.gameevent.TickEvent; |
| 26 | +import net.minecraftforge.fml.relauncher.Side; |
| 27 | +import org.jetbrains.annotations.NotNull; |
23 | 28 |
|
| 29 | +@Mod.EventBusSubscriber(Side.CLIENT) |
24 | 30 | public class ClientProxy extends CommonProxy { |
25 | 31 | public static final String categoryJEI = "RandomComplement(JEI)"; |
26 | 32 | public static final String categoryAE2 = "RandomComplement(AE2)"; |
| 33 | + @NotNull |
| 34 | + private static ItemStack mouseItemStack = ItemStack.EMPTY; |
27 | 35 |
|
28 | | - public static ItemStack getMouseItem() { |
| 36 | + @SubscribeEvent |
| 37 | + public static void onClientTick(TickEvent.ClientTickEvent event) { |
29 | 38 | val player = Minecraft.getMinecraft().player; |
30 | | - if (player == null) return ItemStack.EMPTY; |
31 | | - val i = player.inventory.getItemStack(); |
32 | | - if (!i.isEmpty()) return i; |
33 | | - |
34 | | - if (Loader.isModLoaded("jei")) return getJEIMouseItem(); |
| 39 | + if (player == null) { |
| 40 | + mouseItemStack = ItemStack.EMPTY; |
| 41 | + return; |
| 42 | + } |
| 43 | + var inv = player.inventory.getItemStack(); |
| 44 | + if (!inv.isEmpty()) { |
| 45 | + mouseItemStack = inv; |
| 46 | + return; |
| 47 | + } |
| 48 | + if (Loader.isModLoaded("jei")) mouseItemStack = getJEIMouseItem(); |
| 49 | + else mouseItemStack = ItemStack.EMPTY; |
| 50 | + } |
35 | 51 |
|
36 | | - return ItemStack.EMPTY; |
| 52 | + public static ItemStack getMouseItem() { |
| 53 | + return mouseItemStack; |
37 | 54 | } |
38 | 55 |
|
39 | 56 | @Optional.Method(modid = "jei") |
40 | 57 | public static ItemStack getJEIMouseItem() { |
41 | | - IClickedIngredient<?> ii = null; |
| 58 | + GhostIngredientDrag<?> ii = null; |
42 | 59 | if (Internal.getInputHandler() != null) { |
43 | | - ii = ((AccessorInputHandler) Internal.getInputHandler()).invokeGetIngredientUnderMouseForKey(MouseHelper.getX(), MouseHelper.getY()); |
| 60 | + ii = ((AccessorGhostIngredientDragManager) ((AccessorInputHandler) Internal.getInputHandler()).getGhostIngredientDragManager()).getGhostIngredientDrag(); |
44 | 61 | } |
45 | 62 | if (ii != null) { |
46 | | - if (ii.getValue() instanceof ItemStack stack) { |
| 63 | + if (ii.getIngredient() instanceof ItemStack stack) { |
47 | 64 | return stack; |
48 | 65 | } |
49 | | - if (ii.getValue() instanceof BookmarkItem<?> book && book.ingredient instanceof ItemStack stack) { |
| 66 | + if (ii.getIngredient() instanceof BookmarkItem<?> book && book.ingredient instanceof ItemStack stack) { |
50 | 67 | return stack; |
51 | 68 | } |
52 | 69 | } |
|
0 commit comments