Skip to content

Commit

Permalink
make some wip scan stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Feb 11, 2024
1 parent 96406ed commit 37e13d5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.logging.Log;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.dfonline.codeclient.dev.BuildClip;
import dev.dfonline.codeclient.dev.LastPos;
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
import dev.dfonline.codeclient.hypercube.template.Template;
import dev.dfonline.codeclient.location.*;
import dev.dfonline.codeclient.websocket.SocketHandler;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
Expand Down Expand Up @@ -176,6 +177,23 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
// return 0;
// }));

dispatcher.register(literal("scanplot").executes(context -> {
if(CodeClient.location instanceof Dev) {
var scan = new ArrayList<Template>();
CodeClient.currentAction = new ScanPlot(() -> {
CodeClient.currentAction = new None();
Utility.sendMessage("Done!", ChatType.SUCCESS);
Utility.sendMessage("Results:", ChatType.INFO);
for (Template template : scan) {
Utility.sendMessage(String.valueOf(template.blocks.size()));
}

},scan);
CodeClient.currentAction.init();
return 0;
}
else return 1;
}));
dispatcher.register(literal("scanfor").then(argument("name", StringArgumentType.greedyString()).executes(context -> {
if(CodeClient.location instanceof Dev dev) {
Pattern pattern = Pattern.compile(context.getArgument("name", String.class), Pattern.CASE_INSENSITIVE);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/dfonline/codeclient/action/impl/GoTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class GoTo extends Action {
private int lastTickPackets = 1;
private int thisTickPackets = 0;
boolean doNotSuppress = false;
boolean complete = false;

public GoTo(Vec3d target, Callback callback) {
super(callback);
Expand Down Expand Up @@ -79,6 +80,7 @@ public void onTick() {
CodeClient.MC.player.setVelocity(0,0,0);
if(CodeClient.MC.player.getPos().equals(target)) {
active = false;
complete = true;
callback();
return;
}
Expand Down
95 changes: 95 additions & 0 deletions src/main/java/dev/dfonline/codeclient/action/impl/ScanPlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package dev.dfonline.codeclient.action.impl;

import dev.dfonline.codeclient.Callback;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.hypercube.template.Template;
import dev.dfonline.codeclient.hypercube.template.TemplateBlock;
import dev.dfonline.codeclient.location.Dev;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class ScanPlot extends Action {
private List<BlockPos> blocks = null;
private GoTo goTo = null;
private int progress = 0;
private static final Vec3d goToOffset = new Vec3d(0,1.5,0);
private boolean waitForResponse = false;
private final ArrayList<Template> scanList;

public ScanPlot(Callback callback, ArrayList<Template> scanList) {
super(callback);
this.scanList = scanList;
if (!(CodeClient.location instanceof Dev)) {
throw new IllegalStateException("Player must be in dev mode.");
}
}

@Override
public void init() {
if(CodeClient.location instanceof Dev plot) {
blocks = plot.scanForSigns(Pattern.compile("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS"),Pattern.compile(".*")).keySet().stream().toList();
}
}

@Override
public boolean onReceivePacket(Packet<?> packet) {
var net = CodeClient.MC.getNetworkHandler();
if(waitForResponse && net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot) {
var data = Utility.templateDataItem(slot.getStack());
var template = Template.parse64(data);
if(template == null) return false;
scanList.add(Template.parse64(data));
waitForResponse = false;
net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
return true;
}
return false;
}

@Override
public void onTick() {
var net = CodeClient.MC.getNetworkHandler();
var player = CodeClient.MC.player;
var inter = CodeClient.MC.interactionManager;
if(CodeClient.location instanceof Dev && this.blocks != null && net != null && player != null && inter != null) {
if(goTo == null || goTo.complete) {
if(goTo != null && !waitForResponse) {
var current = blocks.get(progress);
boolean sneaky = !player.isSneaking();
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
inter.interactBlock(player, Hand.MAIN_HAND, new BlockHitResult(current.toCenterPos(), Direction.UP, current,false));
if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
waitForResponse = true;
progress += 1;
goTo = null;
}
if(progress == blocks.size()) {
if(!waitForResponse) {
callback();
}
return;
}
goTo = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {});
goTo.init();
}
goTo.onTick();
}
}
}

0 comments on commit 37e13d5

Please sign in to comment.