diff --git a/src/main/java/dev/dfonline/codeclient/config/Config.java b/src/main/java/dev/dfonline/codeclient/config/Config.java index 83d87a43..071803d9 100644 --- a/src/main/java/dev/dfonline/codeclient/config/Config.java +++ b/src/main/java/dev/dfonline/codeclient/config/Config.java @@ -96,6 +96,7 @@ public class Config { public int MiniMessageTagColor = 0x808080; public boolean StateSwitcher = true; public boolean SpeedSwitcher = true; + public boolean PickFunctionNames = true; public Config() { } @@ -185,6 +186,7 @@ public void save() { object.addProperty("HighlightExpressions", HighlightExpressions); object.addProperty("HighlightMiniMessage", HighlightMiniMessage); object.addProperty("MiniMessageTagColor", MiniMessageTagColor); + object.addProperty("PickFunctionNames", PickFunctionNames); FileManager.writeConfig(object.toString()); } catch (Exception e) { @@ -576,6 +578,18 @@ public YetAnotherConfigLib getLibConfig() { ) .controller(TickBoxControllerBuilder::create) .build()) + .option(Option.createBuilder(Boolean.class) + .name(Text.translatable("codeclient.config.pick_function_names")) + .description(OptionDescription.of( + Text.translatable("codeclient.config.pick_function_names.description1"), Text.translatable("codeclient.config.pick_function_names.description2") + )) + .binding( + true, + () -> PickFunctionNames, + opt -> PickFunctionNames = opt + ) + .controller(TickBoxControllerBuilder::create) + .build()) .option(Option.createBuilder(Boolean.class) .name(Text.translatable("codeclient.config.advanced_middle_click")) .description(OptionDescription.of(Text.translatable("codeclient.config.advanced_middle_click.description"), Text.translatable("codeclient.config.advanced_middle_click.description2"))) diff --git a/src/main/java/dev/dfonline/codeclient/mixin/world/block/MBlock.java b/src/main/java/dev/dfonline/codeclient/mixin/world/block/MBlock.java index e94c3617..5929bc1a 100644 --- a/src/main/java/dev/dfonline/codeclient/mixin/world/block/MBlock.java +++ b/src/main/java/dev/dfonline/codeclient/mixin/world/block/MBlock.java @@ -2,6 +2,7 @@ import dev.dfonline.codeclient.CodeClient; import dev.dfonline.codeclient.config.Config; +import dev.dfonline.codeclient.data.DFItem; import dev.dfonline.codeclient.dev.InteractionManager; import dev.dfonline.codeclient.hypercube.actiondump.ActionDump; import dev.dfonline.codeclient.location.Dev; @@ -13,17 +14,37 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldView; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.item.Items; +import net.minecraft.text.Style; +import net.minecraft.text.Text; import java.util.Arrays; +import java.util.Map; +import java.util.Set; @Mixin(Block.class) public class MBlock { @Inject(method = "getPickStack", at = @At("HEAD"), cancellable = true) private void getPickStack(WorldView world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { + + if (Config.getConfig().PickFunctionNames) { + if (CodeClient.location instanceof Dev) { + ItemStack copiedNameString = tryPickFunctionName(pos); + + // if that was a sign, function/process related one, and we copied its name successfully + if (copiedNameString != null) { + cir.setReturnValue(copiedNameString); + return; + } + } + } + if (!Config.getConfig().PickAction) return; + if (CodeClient.location instanceof Dev dev) { if (!dev.isInDev(pos)) return; var breakable = InteractionManager.isBlockBreakable(pos); @@ -42,4 +63,46 @@ private void getPickStack(WorldView world, BlockPos pos, BlockState state, Callb } } } + + @Unique + private static final Set CALLABLE_BLOCK_NAMES = Set.of( + "CALL FUNCTION", + "START PROCESS", + "FUNCTION", + "PROCESS" + ); + + /** + * Will have changed the return value to an appropriate string if it returns true + * @param pos Position of the block to try and copy function/process name from + * @return Null if a name can't be copied from that position, else the ItemStack of the appropriate DF string varitem + */ + @Unique + private ItemStack tryPickFunctionName(BlockPos pos) { + if (CodeClient.MC.world.getBlockEntity(pos) instanceof SignBlockEntity signBlock) { + try { + SignText text = signBlock.getFrontText(); + String firstLine = text.getMessage(0, false).getString(); + + if (!CALLABLE_BLOCK_NAMES.contains(firstLine)) + return null; + + DFItem string = new DFItem(new ItemStack(Items.STRING, 1)); + + String funcName = text.getMessage(1, false).getString(); + // stop item name from being italicized like anvil renaming + string.setName(Text.literal(funcName).setStyle(Style.EMPTY.withItalic(false))); + + String varItemJSON = CodeClient.gson.toJson(Map.of( + "id", "txt", + "data", Map.of("name", funcName) + )); + string.getItemData().setHypercubeStringValue("varitem", varItemJSON); + + return string.getItemStack(); + } catch (Exception ignored) { + } + } + return null; + } } \ No newline at end of file diff --git a/src/main/resources/assets/codeclient/lang/en_us.json b/src/main/resources/assets/codeclient/lang/en_us.json index 01831249..72c3ff08 100644 --- a/src/main/resources/assets/codeclient/lang/en_us.json +++ b/src/main/resources/assets/codeclient/lang/en_us.json @@ -110,6 +110,9 @@ "codeclient.config.pick_block_action.description1": "Replaces pick block with the action", "codeclient.config.pick_block_action.description2": "Requires actiondump.", "codeclient.config.pick_block_action.description3": "Click to open link.", + "codeclient.config.pick_function_names": "Pick Function/Process Name", + "codeclient.config.pick_function_names.description1": "Replaces the sign pick block item with the function or process name as a string.", + "codeclient.config.pick_function_names.description2": "Compatible with Pick Block Action.", "codeclient.config.recent_values": "Recent Values", "codeclient.config.recent_values.description": "Amount of recently used values to remember.", "codeclient.config.state_switcher": "Mode Switcher",