Skip to content

Commit f7bd80a

Browse files
committed
make placer use free space
1 parent 8a4f6d5 commit f7bd80a

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.2+build.4
88
loader_version=0.14.24
99

1010
# Mod Properties
11-
mod_version=1.5.7
11+
mod_version=1.5.8
1212
maven_group=dev.dfonline
1313
archives_base_name=CodeClient
1414

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,14 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
204204
// return -1;
205205
// }));
206206
dispatcher.register(literal("placetemplates").executes(context -> {
207-
if(CodeClient.location instanceof Dev dev) {
208-
var map = new HashMap<BlockPos, ItemStack>();
209-
BlockPos pos = dev.findFreePlacePos();
210-
for (var template: Utility.templatesInInventory()) {
211-
map.put(pos, template);
212-
pos = dev.findFreePlacePos(pos.west(2));
213-
}
214-
CodeClient.currentAction = new PlaceTemplates(map, () -> {
207+
if(CodeClient.location instanceof Dev) {
208+
var action = Utility.createPlacer(Utility.templatesInInventory(), () -> {
215209
CodeClient.currentAction = new None();
216210
Utility.sendMessage("Done!", ChatType.SUCCESS);
217211
});
212+
if(action == null) return -1;
213+
CodeClient.currentAction = action;
214+
CodeClient.currentAction.init();
218215
return 0;
219216
}
220217
Utility.sendMessage("You must be in dev mode!",ChatType.FAIL);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.JsonObject;
44
import com.google.gson.JsonParser;
55
import dev.dfonline.codeclient.action.Action;
6+
import dev.dfonline.codeclient.action.None;
67
import dev.dfonline.codeclient.action.impl.PlaceTemplates;
78
import dev.dfonline.codeclient.hypercube.template.Template;
89
import dev.dfonline.codeclient.hypercube.template.TemplateBlock;
@@ -149,6 +150,23 @@ public static PlaceTemplates createSwapper(List<ItemStack> templates, Action.Cal
149150
return null;
150151
}
151152

153+
/**
154+
* A regular placer will always start from where code starts.
155+
* This will use any free spaces instead.
156+
*/
157+
public static PlaceTemplates createPlacer(List<ItemStack> templates, Action.Callback callback) {
158+
if(CodeClient.location instanceof Dev dev) {
159+
var map = new HashMap<BlockPos, ItemStack>();
160+
BlockPos pos = dev.findFreePlacePos();
161+
for (var template: templates) {
162+
map.put(pos, template);
163+
pos = dev.findFreePlacePos(pos.west(2));
164+
}
165+
CodeClient.currentAction = new PlaceTemplates(map, callback);
166+
}
167+
return null;
168+
}
169+
152170
public static void sendHandItem(ItemStack item) {
153171
CodeClient.MC.getNetworkHandler().sendPacket(new CreativeInventoryActionC2SPacket(36 + CodeClient.MC.player.getInventory().selectedSlot, item));
154172
}

src/main/java/dev/dfonline/codeclient/websocket/SocketHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ private static class Place extends SocketHandler.Action {
216216
@Override
217217
public void start(WebSocket responder) {
218218
if(!ready) return;
219-
CodeClient.currentAction = new PlaceTemplates(templates, () -> {
219+
var placer = Utility.createPlacer(templates, () -> {
220220
CodeClient.currentAction = new None();
221221
if(responder.isOpen()) responder.send("place done");
222-
next();
223-
});
222+
next();});
223+
if(placer == null) return;
224+
CodeClient.currentAction = placer;
224225
CodeClient.currentAction.init();
225226
}
226227

0 commit comments

Comments
 (0)