use of com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget in project Multiblocked by Low-Drag-MC.
the class ControllerBuilderWidget method onBuildTemplate.
@Override
protected void onBuildTemplate(ClickData clickData) {
if (clickData.isRemote) {
if (pos != null && facing != null && selected != null && facing.getAxis() != Direction.Axis.Y) {
BlockPos[] poses = ItemBlueprint.getPos(selected);
if (poses != null) {
World world = table.getLevel();
ResourceLocation location = new ResourceLocation("mod_id:component_id");
ControllerDefinition controllerDefinition = new ControllerDefinition(location);
controllerDefinition.baseRenderer = new MBDBlockStateRenderer(world.getBlockState(pos));
new ControllerWidget(this, controllerDefinition, new JsonBlockPattern(world, location, pos, facing, poses[0].getX(), poses[0].getY(), poses[0].getZ(), poses[1].getX(), poses[1].getY(), poses[1].getZ()), "empty", jsonObject -> {
if (jsonObject != null) {
FileUtility.saveJson(new File(Multiblocked.location, "definition/controller/" + jsonObject.get("location").getAsString().replace(":", "_") + ".json"), jsonObject);
updateList();
}
});
}
} else {
// TODO
}
}
}
use of com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget 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);
}
}
Aggregations