use of com.lowdragmc.multiblocked.api.recipe.RecipeMap in project Multiblocked by Low-Drag-MC.
the class ControllerScriptWidget method loadJson.
private void loadJson(ClickData clickData) {
if (selected != null && clickData.isRemote) {
JsonElement jsonElement = FileUtility.loadJson(selected);
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);
pattern.predicates.put("controller", new PredicateComponent(definition));
definition.basePattern = pattern.build();
for (File file : Optional.ofNullable(new File(Multiblocked.location, "recipe_map").listFiles((f, n) -> n.endsWith(".json"))).orElse(new File[0])) {
JsonObject config = (JsonObject) FileUtility.loadJson(file);
if (config != null && config.get("name").getAsString().equals(recipeMap)) {
definition.recipeMap = Multiblocked.GSON.fromJson(config, RecipeMap.class);
break;
}
}
controller.setDefinition(definition);
MbdComponents.TEST_DEFINITION_REGISTRY.put(definition.location, definition);
writeClientAction(-1, buffer -> buffer.writeUtf(definition.location.toString()));
} catch (Exception e) {
Multiblocked.LOGGER.error("tester: error while loading the controller json {}", selected.getName(), e);
}
textBox.setContent(Collections.singletonList(Multiblocked.GSON_PRETTY.toJson(jsonElement)));
tfGroup.computeMax();
}
}
}
use of com.lowdragmc.multiblocked.api.recipe.RecipeMap in project Multiblocked by Low-Drag-MC.
the class JEIPlugin method registerRecipes.
@Override
public void registerRecipes(@Nonnull IRecipeRegistration registration) {
Multiblocked.LOGGER.info("JEI register");
for (RecipeMap recipeMap : RecipeMap.RECIPE_MAP_REGISTRY.values()) {
if (recipeMap == RecipeMap.EMPTY)
continue;
registration.addRecipes(recipeMap.recipes.values().stream().map(recipe -> new RecipeWidget(recipe, recipeMap.progressTexture)).map(RecipeWrapper::new).collect(Collectors.toList()), new ResourceLocation(Multiblocked.MODID, recipeMap.name));
}
MultiblockInfoCategory.registerRecipes(registration);
}
use of com.lowdragmc.multiblocked.api.recipe.RecipeMap in project Multiblocked by Low-Drag-MC.
the class JEIPlugin method registerCategories.
@Override
public void registerCategories(@Nonnull IRecipeCategoryRegistration registry) {
Multiblocked.LOGGER.info("JEI register categories");
IJeiHelpers jeiHelpers = registry.getJeiHelpers();
registry.addRecipeCategories(new MultiblockInfoCategory(jeiHelpers));
for (RecipeMap recipeMap : RecipeMap.RECIPE_MAP_REGISTRY.values()) {
if (recipeMap == RecipeMap.EMPTY)
continue;
registry.addRecipeCategories(new RecipeMapCategory(jeiHelpers, recipeMap));
}
}
use of com.lowdragmc.multiblocked.api.recipe.RecipeMap in project Multiblocked by Low-Drag-MC.
the class RecipeMapBuilderWidget method updateRecipeMapList.
private void updateRecipeMapList() {
recipeMapList.clearAllWidgets();
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(RecipeMap.EMPTY);
}
selected = null;
File path = new File(Multiblocked.location, "recipe_map");
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles()).orElse(new File[0])) {
if (file.isFile() && file.getName().endsWith(".json")) {
recipeMapList.addWidget(new SelectableWidgetGroup(5, 1 + recipeMapList.widgets.size() * 22, getSize().width - 30, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
selected = file;
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class));
}
}).addWidget(new ImageWidget(0, 0, 120, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(104, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> new RecipeMapWidget(parent, Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class), recipeMap -> {
if (recipeMap != null) {
if (selected == file) {
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(recipeMap);
}
}
JsonElement element = Multiblocked.GSON.toJsonTree(recipeMap);
FileUtility.saveJson(file, element);
}
})).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(2, 0, 96, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(96).setType(TextTexture.TextType.ROLL))));
}
}
}
use of com.lowdragmc.multiblocked.api.recipe.RecipeMap in project Multiblocked by Low-Drag-MC.
the class RecipeMapTypeAdapter method deserialize.
@Override
public RecipeMap deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject json = (JsonObject) jsonElement;
RecipeMap recipeMap = new RecipeMap(json.get("name").getAsString());
recipeMap.progressTexture = new ResourceTexture(json.get("progressTexture").getAsString());
for (JsonElement recipe : json.get("recipes").getAsJsonArray()) {
recipeMap.addRecipe(Multiblocked.GSON.fromJson(recipe, Recipe.class));
}
return recipeMap;
}
Aggregations