From b0d8a4fcc033e52251fb75a504a67f28aba31652 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:57:39 -0800 Subject: [PATCH 1/8] add copyFromPlayer shorthand --- .../api/infocommand/InfoParserPackage.java | 22 +++++++++++++++++++ .../groovyscript/command/InfoInfoCommand.java | 15 +------------ .../groovyscript/keybinds/CopyKey.java | 14 +----------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java index 4ca760f4d..a7c43ad4f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java @@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.MinecraftForge; @@ -156,6 +157,27 @@ public void setTileEntity(@Nullable TileEntity tileEntity) { this.tileEntity = tileEntity; } + public void copyFromPlayer(@NotNull EntityPlayer player) { + // mainhand -> offhand -> entity being looked at -> block being looked at -> self + var stack = player.getHeldItem(EnumHand.MAIN_HAND); + if (stack.isEmpty()) stack = player.getHeldItem(EnumHand.OFF_HAND); + if (stack.isEmpty()) { + var entity = RayTracingHelper.getEntityLookingAt(player); + if (entity == null) { + var rayTrace = RayTracingHelper.getBlockLookingAt(player); + if (rayTrace == null) { + setEntity(player); + } else { + copyFromPos(rayTrace); + } + } else { + setEntity(entity); + } + } else { + setStack(stack); + } + } + public void copyFromPos(BlockPos pos) { if (pos == null) return; this.pos = pos; diff --git a/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java index 2f2d8b7ad..2241ae1c8 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java @@ -20,19 +20,6 @@ protected String targetDescription() { @Override void gatherInfo(InfoParserPackage info, EntityPlayer player) { - info.setStack(player.getHeldItem(EnumHand.MAIN_HAND)); - if (info.getStack().isEmpty()) info.setStack(player.getHeldItem(EnumHand.OFF_HAND)); - - // if there's nothing in the player's hands, get the entity being looked at and then the block position - // because entity should be preferred - if (info.getStack().isEmpty()) { - info.setEntity(RayTracingHelper.getEntityLookingAt(player)); - if (info.getEntity() == null) { - info.copyFromPos(RayTracingHelper.getBlockLookingAt(player)); - if (info.getPos() == null) { - info.setEntity(player); - } - } - } + info.copyFromPlayer(player); } } diff --git a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java index 93a7b4e44..1b92c1966 100644 --- a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java @@ -3,7 +3,6 @@ import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; import com.cleanroommc.groovyscript.compat.mods.ModSupport; import com.cleanroommc.groovyscript.compat.mods.jei.JeiPlugin; -import com.cleanroommc.groovyscript.helper.RayTracingHelper; import com.cleanroommc.groovyscript.helper.StyleConstant; import com.google.common.collect.ImmutableList; import mezz.jei.api.IRecipesGui; @@ -11,7 +10,6 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumHand; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraftforge.client.settings.KeyModifier; @@ -34,17 +32,7 @@ public static CopyKey createKeybind() { private static void gatherInfo(InfoParserPackage info, EntityPlayer player) { if (mc.inGameHasFocus) { - info.setStack(player.getHeldItem(EnumHand.MAIN_HAND)); - if (info.getStack().isEmpty()) info.setStack(player.getHeldItem(EnumHand.OFF_HAND)); - if (info.getStack().isEmpty()) { - info.setEntity(RayTracingHelper.getEntityLookingAt(player)); - if (info.getEntity() == null) { - info.copyFromPos(RayTracingHelper.getBlockLookingAt(player)); - if (info.getPos() == null) { - info.setEntity(player); - } - } - } + info.copyFromPlayer(player); } else { if (mc.currentScreen instanceof GuiContainer container && container.hoveredSlot != null) { info.setStack(container.hoveredSlot.getStack()); From 9304f5fb6ec40eb887271c2a2b9ce79a0d97f451 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:58:11 -0800 Subject: [PATCH 2/8] fix copyFromPos issue --- .../api/infocommand/InfoParserPackage.java | 14 ++++++++------ .../groovyscript/helper/RayTracingHelper.java | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java index a7c43ad4f..d56717c85 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java @@ -1,9 +1,9 @@ package com.cleanroommc.groovyscript.api.infocommand; import com.cleanroommc.groovyscript.event.GsHandEvent; +import com.cleanroommc.groovyscript.helper.RayTracingHelper; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; @@ -12,6 +12,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.MinecraftForge; import org.jetbrains.annotations.NotNull; @@ -178,15 +179,16 @@ public void copyFromPlayer(@NotNull EntityPlayer player) { } } - public void copyFromPos(BlockPos pos) { - if (pos == null) return; - this.pos = pos; + public void copyFromPos(RayTraceResult rayTrace) { + if (rayTrace == null) return; + this.pos = rayTrace.getBlockPos(); this.blockState = player.world.getBlockState(pos); this.block = blockState.getBlock(); this.tileEntity = player.world.getTileEntity(pos); - this.stack = block.getPickBlock(blockState, Minecraft.getMinecraft().objectMouseOver, player.world, pos, player); - if (this.stack.isEmpty()) this.stack = new ItemStack(block, 1, block.getMetaFromState(blockState)); + var stack = block.getPickBlock(blockState, rayTrace, player.world, pos, player); + if (stack.isEmpty()) stack = new ItemStack(block, 1, block.getMetaFromState(blockState)); + setStack(stack); } public void parse() { diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java index f6abdee96..56b291955 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java @@ -16,7 +16,7 @@ public class RayTracingHelper { /** * gets the block being looked at, stopping on fluid blocks */ - public static BlockPos getBlockLookingAt(EntityPlayer player) { + public static RayTraceResult getBlockLookingAt(EntityPlayer player) { double distance = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(); Vec3d eyes = player.getPositionEyes(0.0F); Vec3d look = player.getLook(0.0F); @@ -24,7 +24,7 @@ public static BlockPos getBlockLookingAt(EntityPlayer player) { RayTraceResult result = player.getEntityWorld().rayTraceBlocks(eyes, end, true); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { - return result.getBlockPos(); + return result; } return null; } From 3cf9b919454facb3e189984c8ac442e75051cf7f Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:58:29 -0800 Subject: [PATCH 3/8] fix attempting to copy jei incorrectly --- .../groovyscript/keybinds/CopyKey.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java index 1b92c1966..541066448 100644 --- a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java @@ -34,10 +34,19 @@ private static void gatherInfo(InfoParserPackage info, EntityPlayer player) { if (mc.inGameHasFocus) { info.copyFromPlayer(player); } else { - if (mc.currentScreen instanceof GuiContainer container && container.hoveredSlot != null) { - info.setStack(container.hoveredSlot.getStack()); + var jei = ModSupport.JEI.isLoaded(); + if (mc.currentScreen instanceof GuiContainer container) { + var slot = container.getSlotUnderMouse(); + if (slot != null) { + info.setStack(slot.getStack()); + } else if (jei && info.getStack().isEmpty()) { + // check sidebars of normal guis + info.setStack(getJeiStack()); + } + } else if (jei && getJeiRecipesObject() != null) { + // have to check this separately for if IRecipesGui is open, since its GuiScreen not GuiContainer + info.setStack(getJeiStack()); } - if (info.getStack().isEmpty() && ModSupport.JEI.isLoaded()) info.setStack(getJeiStack()); } } @@ -49,15 +58,20 @@ private static ItemStack getJeiStack() { } private static Object getJeiObject() { - if (mc.currentScreen instanceof IRecipesGui gui) { - var entry = gui.getIngredientUnderMouse(); - if (entry != null) return entry; - } - var entry = JeiPlugin.jeiRuntime.getBookmarkOverlay().getIngredientUnderMouse(); + var entry = getJeiRecipesObject(); + if (entry != null) return entry; + entry = JeiPlugin.jeiRuntime.getBookmarkOverlay().getIngredientUnderMouse(); if (entry != null) return entry; return JeiPlugin.jeiRuntime.getIngredientListOverlay().getIngredientUnderMouse(); } + private static Object getJeiRecipesObject() { + if (mc.currentScreen instanceof IRecipesGui gui) { + return gui.getIngredientUnderMouse(); + } + return null; + } + private static void print(EntityPlayer player, List messages) { if (messages.isEmpty()) { player.sendMessage(new TextComponentString("Couldn't find anything being focused!").setStyle(StyleConstant.getErrorStyle())); From 32b5f2faef03d9a337a062a7975fe4b204bf778c Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:58:54 -0800 Subject: [PATCH 4/8] check if screen is focused for valid --- .../java/com/cleanroommc/groovyscript/keybinds/CopyKey.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java index 541066448..f1560914c 100644 --- a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java @@ -82,9 +82,13 @@ private static void print(EntityPlayer player, List messages) { } } + public static boolean isCapturingKeyboard() { + return mc.currentScreen != null && mc.currentScreen.isFocused(); + } + @Override public boolean isValid() { - return mc.isIntegratedServerRunning(); + return mc.isIntegratedServerRunning() && mc.player != null && !isCapturingKeyboard(); } // only runs if isIntegratedServerRunning() is true, so getIntegratedServer() cannot be null From 8c229f34d7a515d3126dab7e29d3f8de28d96a46 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:59:11 -0800 Subject: [PATCH 5/8] extract immutable list --- .../java/com/cleanroommc/groovyscript/keybinds/CopyKey.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java index f1560914c..fff41c04b 100644 --- a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java @@ -21,6 +21,7 @@ public class CopyKey extends GroovyScriptKeybinds.Key { private static final Minecraft mc = Minecraft.getMinecraft(); + private static final List ARGS = ImmutableList.of("all"); public CopyKey() { super("copy", KeyModifier.CONTROL, Keyboard.KEY_C); @@ -97,7 +98,7 @@ public boolean isValid() { public void runOperation() { var player = mc.player; List messages = new ArrayList<>(); - InfoParserPackage info = new InfoParserPackage(mc.getIntegratedServer(), player, ImmutableList.of("all"), messages, false); + InfoParserPackage info = new InfoParserPackage(mc.getIntegratedServer(), player, ARGS, messages, false); gatherInfo(info, player); info.parse(true); print(player, messages); From f5c46178324a120db2ac052e98d62adb50b00872 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:59:34 -0800 Subject: [PATCH 6/8] the humble spotless apply --- .../com/cleanroommc/groovyscript/command/InfoInfoCommand.java | 2 -- .../com/cleanroommc/groovyscript/helper/RayTracingHelper.java | 1 - 2 files changed, 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java index 2241ae1c8..9eda6c01f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/InfoInfoCommand.java @@ -1,9 +1,7 @@ package com.cleanroommc.groovyscript.command; import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; -import com.cleanroommc.groovyscript.helper.RayTracingHelper; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.EnumHand; import org.jetbrains.annotations.NotNull; public class InfoInfoCommand extends BaseInfoCommand { diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java index 56b291955..75a95bd7c 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/RayTracingHelper.java @@ -5,7 +5,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EntitySelectors; import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; From 0cfc073a40b3133ac5a9eb2238e0028633366d4a Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:12:55 -0800 Subject: [PATCH 7/8] allow running on servers --- .../com/cleanroommc/groovyscript/keybinds/CopyKey.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java index fff41c04b..b1a4c7ff3 100644 --- a/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/keybinds/CopyKey.java @@ -89,16 +89,16 @@ public static boolean isCapturingKeyboard() { @Override public boolean isValid() { - return mc.isIntegratedServerRunning() && mc.player != null && !isCapturingKeyboard(); + return mc.player != null && !isCapturingKeyboard(); } - // only runs if isIntegratedServerRunning() is true, so getIntegratedServer() cannot be null - @SuppressWarnings("DataFlowIssue") @Override public void runOperation() { var player = mc.player; List messages = new ArrayList<>(); - InfoParserPackage info = new InfoParserPackage(mc.getIntegratedServer(), player, ARGS, messages, false); + var server = mc.isIntegratedServerRunning() ? mc.getIntegratedServer() : player.getServer(); + if (server == null) return; // unsure how this would happen, should be mutually exclusive + InfoParserPackage info = new InfoParserPackage(server, player, ARGS, messages, false); gatherInfo(info, player); info.parse(true); print(player, messages); From 19b73f7a19eb116970b4c7f592e9f3c4df41e10e Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:18:39 -0800 Subject: [PATCH 8/8] scratch that and set stack directly --- .../groovyscript/api/infocommand/InfoParserPackage.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java index d56717c85..94128006f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParserPackage.java @@ -186,9 +186,8 @@ public void copyFromPos(RayTraceResult rayTrace) { this.block = blockState.getBlock(); this.tileEntity = player.world.getTileEntity(pos); - var stack = block.getPickBlock(blockState, rayTrace, player.world, pos, player); + stack = block.getPickBlock(blockState, rayTrace, player.world, pos, player); if (stack.isEmpty()) stack = new ItemStack(block, 1, block.getMetaFromState(blockState)); - setStack(stack); } public void parse() {