Search in sources :

Example 1 with RecipeMap

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();
        }
    }
}
Also used : JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) File(java.io.File) IOException(java.io.IOException) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Example 2 with RecipeMap

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);
}
Also used : RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) RecipeWidget(com.lowdragmc.multiblocked.api.gui.recipe.RecipeWidget) RecipeWrapper(com.lowdragmc.multiblocked.jei.recipeppage.RecipeWrapper) IJeiRuntime(mezz.jei.api.runtime.IJeiRuntime) MultiblockInfoCategory(com.lowdragmc.multiblocked.jei.multipage.MultiblockInfoCategory) IRecipeCategoryRegistration(mezz.jei.api.registration.IRecipeCategoryRegistration) Collectors(java.util.stream.Collectors) RecipeMapCategory(com.lowdragmc.multiblocked.jei.recipeppage.RecipeMapCategory) ArrayList(java.util.ArrayList) IModPlugin(mezz.jei.api.IModPlugin) IJeiHelpers(mezz.jei.api.helpers.IJeiHelpers) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) JeiPlugin(mezz.jei.api.JeiPlugin) IModIngredientRegistration(mezz.jei.api.registration.IModIngredientRegistration) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) ComponentDefinition(com.lowdragmc.multiblocked.api.definition.ComponentDefinition) ResourceLocation(net.minecraft.util.ResourceLocation) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) VanillaTypes(mezz.jei.api.constants.VanillaTypes) Nonnull(javax.annotation.Nonnull) ResourceLocation(net.minecraft.util.ResourceLocation) RecipeWidget(com.lowdragmc.multiblocked.api.gui.recipe.RecipeWidget) RecipeWrapper(com.lowdragmc.multiblocked.jei.recipeppage.RecipeWrapper) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Example 3 with RecipeMap

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));
    }
}
Also used : MultiblockInfoCategory(com.lowdragmc.multiblocked.jei.multipage.MultiblockInfoCategory) RecipeMapCategory(com.lowdragmc.multiblocked.jei.recipeppage.RecipeMapCategory) IJeiHelpers(mezz.jei.api.helpers.IJeiHelpers) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Example 4 with 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))));
        }
    }
}
Also used : SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap) Desktop(java.awt.Desktop) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) RecipeMapWidget(com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget) IOException(java.io.IOException) UUID(java.util.UUID) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) File(java.io.File) JsonElement(com.google.gson.JsonElement) Consumer(java.util.function.Consumer) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) Optional(java.util.Optional) FileUtility(com.lowdragmc.lowdraglib.utils.FileUtility) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) RecipeMapWidget(com.lowdragmc.multiblocked.api.gui.dialogs.RecipeMapWidget) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) JsonElement(com.google.gson.JsonElement) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) File(java.io.File) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Example 5 with RecipeMap

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;
}
Also used : ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) Recipe(com.lowdragmc.multiblocked.api.recipe.Recipe) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) RecipeMap(com.lowdragmc.multiblocked.api.recipe.RecipeMap)

Aggregations

RecipeMap (com.lowdragmc.multiblocked.api.recipe.RecipeMap)5 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)2 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)2 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)2 MultiblockInfoCategory (com.lowdragmc.multiblocked.jei.multipage.MultiblockInfoCategory)2 RecipeMapCategory (com.lowdragmc.multiblocked.jei.recipeppage.RecipeMapCategory)2 File (java.io.File)2 IOException (java.io.IOException)2 IJeiHelpers (mezz.jei.api.helpers.IJeiHelpers)2 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)1 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)1 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)1 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)1 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)1 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 SelectableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup)1 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)1 FileUtility (com.lowdragmc.lowdraglib.utils.FileUtility)1 ComponentDefinition (com.lowdragmc.multiblocked.api.definition.ComponentDefinition)1