Search in sources :

Example 1 with ItemStackTexture

use of com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture 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);
    }
}
Also used : Arrays(java.util.Arrays) PredicateComponent(com.lowdragmc.multiblocked.api.pattern.predicates.PredicateComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) Direction(net.minecraft.util.Direction) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint) BlueprintTableTileEntity(com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) ClickData(com.lowdragmc.lowdraglib.gui.util.ClickData) MBDBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.MBDBlockStateRenderer) I18n(net.minecraft.client.resources.I18n) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) Desktop(java.awt.Desktop) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ControllerWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget) File(java.io.File) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ResourceLocation(net.minecraft.util.ResourceLocation) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) Optional(java.util.Optional) FileUtility(com.lowdragmc.lowdraglib.utils.FileUtility) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) PacketBuffer(net.minecraft.network.PacketBuffer) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ControllerWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.ControllerWidget) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) JsonBlockPattern(com.lowdragmc.multiblocked.api.pattern.JsonBlockPattern) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) JsonElement(com.google.gson.JsonElement) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) File(java.io.File)

Example 2 with ItemStackTexture

use of com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture in project Multiblocked by Low-Drag-MC.

the class PartBuilderWidget method updateList.

protected void updateList() {
    setNewRenderer(null, "");
    files.forEach(containers::waitToRemoved);
    files.clear();
    File path = new File(Multiblocked.location, "definition/part");
    walkFile("Common", new ItemStackTexture(BlueprintTableTileEntity.partDefinition.getStackForm()), path, (jsonElement, file) -> {
        PartDefinition definition = Multiblocked.GSON.fromJson(jsonElement, PartDefinition.class);
        new PartWidget(this, definition, jsonObject -> {
            if (jsonObject != null) {
                FileUtility.saveJson(file, jsonObject);
            }
        });
    });
    if (Multiblocked.isCreateLoaded()) {
        path = new File(path, "create");
        walkFile("Create", new ItemStackTexture(AllBlocks.FLYWHEEL.asStack()), path, ((jsonElement, file) -> {
            CreatePartDefinition definition = Multiblocked.GSON.fromJson(jsonElement, CreatePartDefinition.class);
            new CreatePartWidget(this, definition, jsonObject -> {
                if (jsonObject != null) {
                    FileUtility.saveJson(file, jsonObject);
                }
            });
        }));
    }
}
Also used : OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) CreatePartDefinition(com.lowdragmc.multiblocked.common.definition.CreatePartDefinition) CreatePartWidget(com.lowdragmc.multiblocked.common.gui.component.CreatePartWidget) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) BlueprintTableTileEntity(com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) BiConsumer(java.util.function.BiConsumer) AllBlocks(com.simibubi.create.AllBlocks) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) IMultiblockedRenderer(com.lowdragmc.multiblocked.client.renderer.IMultiblockedRenderer) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) Desktop(java.awt.Desktop) MbdComponents(com.lowdragmc.multiblocked.api.registry.MbdComponents) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) ColorBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ColorBorderTexture) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) GuiTextureGroup(com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup) BlockPos(net.minecraft.util.math.BlockPos) IGuiTexture(com.lowdragmc.lowdraglib.gui.texture.IGuiTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) File(java.io.File) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) FileUtility(com.lowdragmc.lowdraglib.utils.FileUtility) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) PartWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.PartWidget) Collections(java.util.Collections) ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) CreatePartWidget(com.lowdragmc.multiblocked.common.gui.component.CreatePartWidget) PartWidget(com.lowdragmc.multiblocked.api.gui.blueprint_table.components.PartWidget) CreatePartDefinition(com.lowdragmc.multiblocked.common.definition.CreatePartDefinition) CreatePartDefinition(com.lowdragmc.multiblocked.common.definition.CreatePartDefinition) PartDefinition(com.lowdragmc.multiblocked.api.definition.PartDefinition) CreatePartWidget(com.lowdragmc.multiblocked.common.gui.component.CreatePartWidget) File(java.io.File)

Example 3 with ItemStackTexture

use of com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture in project Multiblocked by Low-Drag-MC.

the class TemplateBuilderWidget method readInitialData.

@Override
public void readInitialData(PacketBuffer buffer) {
    super.readInitialData(buffer);
    this.addWidget(containers = new DraggableScrollableWidgetGroup(200, 120, 150, 98));
    containers.setClientSideWidget();
    for (int i = buffer.readVarInt(); i > 0; i--) {
        ItemStack itemStack = buffer.readItem();
        int slotIndex = buffer.readVarInt();
        containers.addWidget(new SelectableWidgetGroup(0, containers.widgets.size() * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(w -> onSelected(itemStack, slotIndex)).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(itemStack.getDisplayName().getString()).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(itemStack))));
    }
}
Also used : ItemStackTexture(com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SelectableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) ItemStack(net.minecraft.item.ItemStack) ItemBlueprint(com.lowdragmc.multiblocked.api.item.ItemBlueprint)

Aggregations

ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)3 ItemStackTexture (com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture)3 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)3 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)3 SelectableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup)3 JsonElement (com.google.gson.JsonElement)2 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)2 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)2 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)2 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)2 FileUtility (com.lowdragmc.lowdraglib.utils.FileUtility)2 TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)2 Multiblocked (com.lowdragmc.multiblocked.Multiblocked)2 ItemBlueprint (com.lowdragmc.multiblocked.api.item.ItemBlueprint)2 MbdComponents (com.lowdragmc.multiblocked.api.registry.MbdComponents)2 BlueprintTableTileEntity (com.lowdragmc.multiblocked.api.tile.BlueprintTableTileEntity)2 DummyComponentTileEntity (com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)2 Desktop (java.awt.Desktop)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2