Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/dev/dfonline/codeclient/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ItemStack> 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);
Expand All @@ -42,4 +63,46 @@ private void getPickStack(WorldView world, BlockPos pos, BlockState state, Callb
}
}
}

@Unique
private static final Set<String> 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;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/codeclient/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down