Skip to content

Commit efe6eec

Browse files
committed
It misses args cuz my class doesn't have it, so 100% working now it seems
1 parent 712e2e8 commit efe6eec

3 files changed

Lines changed: 35 additions & 31 deletions

File tree

src/main/java/dev/dfonline/codeclient/Commands.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,31 @@ else if(!Files.isDirectory(currentPath)) {
218218
}
219219
}
220220

221+
try {
222+
if(Files.list(currentPath).findFirst().isPresent()) {
223+
Utility.sendMessage("Please use an empty directory to save into.",ChatType.FAIL);
224+
return -1;
225+
}
226+
}
227+
catch (Exception ignored) {
228+
Utility.sendMessage("An error occurred when reading the directory.",ChatType.FAIL);
229+
}
230+
221231
Utility.sendMessage("Scanning plot. Use /abort to abort.",ChatType.INFO);
222-
var scan = new ArrayList<Template>();
232+
var scan = new ArrayList<ItemStack>();
223233
Path finalCurrentPath = currentPath;
224234
CodeClient.currentAction = new ScanPlot(() -> {
225235
CodeClient.currentAction = new None();
226236
Utility.sendMessage("Done!", ChatType.SUCCESS);
227-
for (Template template : scan) {
237+
for (ItemStack item : scan) {
238+
String data = Utility.templateDataItem(item);
239+
var template = Template.parse64(data);
240+
if(template == null) continue;
228241
var first = template.blocks.get(0);
229242
String name = Objects.requireNonNullElse(first.action != null ? first.action : first.data,"unknown");
230243
var filePath = finalCurrentPath.resolve(name + ".dft");
231244
try {
232-
Files.write(filePath,template.compress());
245+
Files.write(filePath,Base64.getDecoder().decode(data));
233246
}
234247
catch (Exception ignored) {
235248
Utility.sendMessage("Couldn't save " + filePath + "...", ChatType.FAIL);

src/main/java/dev/dfonline/codeclient/action/impl/ScanPlot.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ public class ScanPlot extends Action {
2626
private List<BlockPos> blocks = null;
2727
private Action step = null;
2828
private static final Vec3d goToOffset = new Vec3d(0, 1.5, 0);
29-
private Integer progress = 0;
30-
private final ArrayList<Template> scanList;
29+
private final ArrayList<ItemStack> scanList;
3130

32-
public ScanPlot(Callback callback, ArrayList<Template> scanList) {
31+
public ScanPlot(Callback callback, ArrayList<ItemStack> scanList) {
3332
super(callback);
3433
this.scanList = scanList;
3534
if (!(CodeClient.location instanceof Dev)) {
@@ -61,23 +60,26 @@ public boolean onReceivePacket(Packet<?> packet) {
6160
// }
6261
}
6362

63+
private void next(int progress) {
64+
if(progress >= blocks.size()) {
65+
callback();
66+
return;
67+
}
68+
step = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {
69+
this.step = new pickUpBlock(blocks.get(progress),() -> {
70+
CodeClient.LOGGER.info("picked up block");
71+
next(progress + 1);
72+
});
73+
this.step.init();
74+
});
75+
step.init();
76+
}
77+
6478
@Override
6579
public void onTick() {
6680
if (step != null) step.onTick();
6781
else {
68-
if(progress >= blocks.size()) {
69-
callback();
70-
return;
71-
}
72-
step = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {
73-
this.step = new pickUpBlock(blocks.get(progress),() -> {
74-
CodeClient.LOGGER.info("picked up block");
75-
step = null;
76-
progress+=1;
77-
});
78-
this.step.init();
79-
});
80-
step.init();
82+
next(0);
8183
}
8284
}
8385

@@ -109,7 +111,7 @@ public boolean onReceivePacket(Packet<?> packet) {
109111
var data = Utility.templateDataItem(slot.getStack());
110112
var template = Template.parse64(data);
111113
if (template == null) return false;
112-
scanList.add(Template.parse64(data));
114+
scanList.add(slot.getStack());
113115
net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
114116
this.callback();
115117
return true;

src/main/java/dev/dfonline/codeclient/hypercube/template/Template.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ public int getLength() {
1919
return length;
2020
}
2121

22-
public byte[] compress() throws IOException {
23-
return compress(CodeClient.gson.toJson(this));
24-
}
25-
2622
/**
2723
* Parse base64+gzip data
2824
*/
@@ -62,11 +58,4 @@ private static byte[] decompress(byte[] compressedData) throws IOException {
6258
return bos.toByteArray();
6359
}
6460
}
65-
private static byte[] compress(String uncompressedString) throws IOException {
66-
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
67-
try (GZIPOutputStream gzipStream = new GZIPOutputStream(byteStream)) {
68-
gzipStream.write(uncompressedString.getBytes());
69-
}
70-
return byteStream.toByteArray();
71-
}
7261
}

0 commit comments

Comments
 (0)