Skip to content

Commit

Permalink
Merge branch 'sylviameows-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed May 15, 2024
2 parents 69141e0 + cc4f790 commit 7a641dd
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.action.None;
import dev.dfonline.codeclient.action.impl.*;
Expand All @@ -13,6 +14,7 @@
import dev.dfonline.codeclient.location.Plot;
import dev.dfonline.codeclient.websocket.SocketHandler;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.block.entity.SignText;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.text.ClickEvent;
Expand All @@ -22,6 +24,7 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -286,7 +289,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
return -1;
})));

dispatcher.register(literal("jump")
LiteralCommandNode<FabricClientCommandSource> jumpCommand = dispatcher.register(literal("jump")
.then(literal("player").then(argument("name", greedyString()).suggests((context, builder) -> suggestJump(JumpType.PLAYER_EVENT, context, builder)).executes(context -> {
var name = context.getArgument("name", String.class);
jump(JumpType.PLAYER_EVENT,name);
Expand All @@ -308,6 +311,9 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
return 0;
})))
);

dispatcher.register(literal("goto").redirect(jumpCommand));

// dispatcher.register(literal("swapininv").executes(context -> {
// if(CodeClient.location instanceof Dev) {
// PlaceTemplates action = Utility.createSwapper(Utility.templatesInInventory(), () -> {
Expand Down Expand Up @@ -551,10 +557,25 @@ private static CompletableFuture<Suggestions> suggestJump(JumpType type, Command
}
private static void jump(JumpType type, String name) {
if(CodeClient.location instanceof Dev dev && CodeClient.currentAction instanceof None) {
var results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$"));
@Nullable HashMap<BlockPos, SignText> results = null;
// functions/processes in diamondfire are case-sensitive, and you can have two functions with the same name if they have different cases.
if (type == JumpType.FUNCTION || type == JumpType.PROCESS) {
results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$"));
} else {
// however, events do not have this problem and the case of what you type shouldn't matter.
results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$", Pattern.CASE_INSENSITIVE));
}

if(results == null) return;
var first = results.keySet().stream().findFirst();
if(first.isEmpty()) return;

// no exact match exists in the plot, so we can run a less restrictive search.
if(first.isEmpty()) {
results = dev.scanForSigns(type.pattern,Pattern.compile("^.*"+Pattern.quote(name)+".*$", Pattern.CASE_INSENSITIVE));
if(results == null) return;
first = results.keySet().stream().findFirst();
if(first.isEmpty()) return; // there is no partial match, so the player doesn't get sent
}
CodeClient.currentAction = new GoTo(first.get().toCenterPos(), () -> CodeClient.currentAction = new None());
CodeClient.currentAction.init();
}
Expand Down

0 comments on commit 7a641dd

Please sign in to comment.