use of com.lowdragmc.multiblocked.api.gui.dialogs.JsonBlockPatternWidget in project Multiblocked by Low-Drag-MC.
the class TemplateBuilderWidget method onBuildTemplate.
protected void onBuildTemplate(ClickData clickData) {
if (isRemote() && ItemBlueprint.isItemBlueprint(selected)) {
JsonBlockPattern pattern = null;
if (ItemBlueprint.isRaw(selected)) {
BlockPos[] poses = ItemBlueprint.getPos(selected);
World world = table.getLevel();
if (poses != null && world.hasChunksAt(poses[0], poses[1])) {
ControllerTileEntity controller = null;
for (int x = poses[0].getX(); x <= poses[1].getX(); x++) {
for (int y = poses[0].getY(); y <= poses[1].getY(); y++) {
for (int z = poses[0].getZ(); z <= poses[1].getZ(); z++) {
TileEntity te = world.getBlockEntity(new BlockPos(x, y, z));
if (te instanceof ControllerTileEntity) {
controller = (ControllerTileEntity) te;
}
}
}
}
if (controller != null) {
pattern = new JsonBlockPattern(table.getLevel(), controller.getLocation(), controller.getBlockPos(), controller.getFrontFacing(), poses[0].getX(), poses[0].getY(), poses[0].getZ(), poses[1].getX(), poses[1].getY(), poses[1].getZ());
} else {
// TODO tips dialog
}
} else {
// TODO tips dialog
}
} else if (selected.getTagElement("pattern") != null) {
String json = selected.getTagElement("pattern").getString("json");
pattern = Multiblocked.GSON.fromJson(json, JsonBlockPattern.class);
}
if (pattern != null) {
new JsonBlockPatternWidget(this, pattern, patternResult -> {
if (patternResult != null) {
if (ItemBlueprint.setPattern(selected) && patternResult.predicates.get("controller") instanceof PredicateComponent) {
patternResult.cleanUp();
String json = patternResult.toJson();
String controller = ((PredicateComponent) patternResult.predicates.get("controller")).location.toString();
selected.getOrCreateTagElement("pattern").putString("json", json);
selected.getOrCreateTagElement("pattern").putString("controller", controller);
writeClientAction(-1, buffer -> {
buffer.writeVarInt(selectedSlot);
buffer.writeUtf(json);
buffer.writeUtf(controller);
});
}
}
});
}
}
}
Aggregations