Skip to content

Commit

Permalink
It misses args cuz my class doesn't have it, so 100% working now it s…
Browse files Browse the repository at this point in the history
…eems
  • Loading branch information
GeorgeRNG committed Mar 31, 2024
1 parent 712e2e8 commit efe6eec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
19 changes: 16 additions & 3 deletions src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,31 @@ else if(!Files.isDirectory(currentPath)) {
}
}

try {
if(Files.list(currentPath).findFirst().isPresent()) {
Utility.sendMessage("Please use an empty directory to save into.",ChatType.FAIL);
return -1;
}
}
catch (Exception ignored) {
Utility.sendMessage("An error occurred when reading the directory.",ChatType.FAIL);
}

Utility.sendMessage("Scanning plot. Use /abort to abort.",ChatType.INFO);
var scan = new ArrayList<Template>();
var scan = new ArrayList<ItemStack>();
Path finalCurrentPath = currentPath;
CodeClient.currentAction = new ScanPlot(() -> {
CodeClient.currentAction = new None();
Utility.sendMessage("Done!", ChatType.SUCCESS);
for (Template template : scan) {
for (ItemStack item : scan) {
String data = Utility.templateDataItem(item);
var template = Template.parse64(data);
if(template == null) continue;
var first = template.blocks.get(0);
String name = Objects.requireNonNullElse(first.action != null ? first.action : first.data,"unknown");
var filePath = finalCurrentPath.resolve(name + ".dft");
try {
Files.write(filePath,template.compress());
Files.write(filePath,Base64.getDecoder().decode(data));
}
catch (Exception ignored) {
Utility.sendMessage("Couldn't save " + filePath + "...", ChatType.FAIL);
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/dev/dfonline/codeclient/action/impl/ScanPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public class ScanPlot extends Action {
private List<BlockPos> blocks = null;
private Action step = null;
private static final Vec3d goToOffset = new Vec3d(0, 1.5, 0);
private Integer progress = 0;
private final ArrayList<Template> scanList;
private final ArrayList<ItemStack> scanList;

public ScanPlot(Callback callback, ArrayList<Template> scanList) {
public ScanPlot(Callback callback, ArrayList<ItemStack> scanList) {
super(callback);
this.scanList = scanList;
if (!(CodeClient.location instanceof Dev)) {
Expand Down Expand Up @@ -61,23 +60,26 @@ public boolean onReceivePacket(Packet<?> packet) {
// }
}

private void next(int progress) {
if(progress >= blocks.size()) {
callback();
return;
}
step = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {
this.step = new pickUpBlock(blocks.get(progress),() -> {
CodeClient.LOGGER.info("picked up block");
next(progress + 1);
});
this.step.init();
});
step.init();
}

@Override
public void onTick() {
if (step != null) step.onTick();
else {
if(progress >= blocks.size()) {
callback();
return;
}
step = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {
this.step = new pickUpBlock(blocks.get(progress),() -> {
CodeClient.LOGGER.info("picked up block");
step = null;
progress+=1;
});
this.step.init();
});
step.init();
next(0);
}
}

Expand Down Expand Up @@ -109,7 +111,7 @@ public boolean onReceivePacket(Packet<?> packet) {
var data = Utility.templateDataItem(slot.getStack());
var template = Template.parse64(data);
if (template == null) return false;
scanList.add(Template.parse64(data));
scanList.add(slot.getStack());
net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
this.callback();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public int getLength() {
return length;
}

public byte[] compress() throws IOException {
return compress(CodeClient.gson.toJson(this));
}

/**
* Parse base64+gzip data
*/
Expand Down Expand Up @@ -62,11 +58,4 @@ private static byte[] decompress(byte[] compressedData) throws IOException {
return bos.toByteArray();
}
}
private static byte[] compress(String uncompressedString) throws IOException {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzipStream = new GZIPOutputStream(byteStream)) {
gzipStream.write(uncompressedString.getBytes());
}
return byteStream.toByteArray();
}
}

0 comments on commit efe6eec

Please sign in to comment.