use of com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern in project Multiblocked by Low-Drag-MC.
the class ControllerBuilderWidget method updateList.
protected void updateList() {
int size = files.size();
files.forEach(containers::waitToRemoved);
files.clear();
File path = new File(Multiblocked.location, "definition/controller");
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles((s, name) -> name.endsWith(".json"))).orElse(new File[0])) {
SelectableWidgetGroup widgetGroup = (SelectableWidgetGroup) new SelectableWidgetGroup(0, (containers.widgets.size() - size) * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
templateButton.setVisible(false);
selected = null;
onJsonSelected(file);
}).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(134, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> {
JsonElement jsonElement = FileUtility.loadJson(file);
if (jsonElement != null) {
try {
String recipeMap = jsonElement.getAsJsonObject().get("recipeMap").getAsString();
JsonBlockPattern pattern = Multiblocked.GSON.fromJson(jsonElement.getAsJsonObject().get("basePattern"), JsonBlockPattern.class);
ControllerDefinition definition = Multiblocked.GSON.fromJson(jsonElement, ControllerDefinition.class);
new ControllerWidget(this, definition, pattern, recipeMap, jsonObject -> {
if (jsonObject != null) {
FileUtility.saveJson(file, jsonObject);
}
});
} catch (Exception ignored) {
}
}
}).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(Items.PAPER)));
files.add(widgetGroup);
containers.addWidget(widgetGroup);
}
}
use of com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern 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