Search in sources :

Example 1 with SlotWidget

use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.

the class PatternWidget method onPosSelected.

private void onPosSelected(BlockPos pos, Direction facing) {
    if (index >= patterns.length || index < 0)
        return;
    TraceabilityPredicate predicate = patterns[index].predicateMap.get(pos);
    if (predicate != null) {
        predicates.clear();
        predicates.addAll(predicate.common);
        predicates.addAll(predicate.limited);
        // why it happens?
        predicates.removeIf(p -> p == null || p.candidates == null);
        if (candidates != null) {
            for (SlotWidget candidate : candidates) {
                removeWidget(candidate);
            }
        }
        List<List<ItemStack>> candidateStacks = new ArrayList<>();
        List<List<String>> predicateTips = new ArrayList<>();
        for (SimplePredicate simplePredicate : predicates) {
            List<ItemStack> itemStacks = simplePredicate.getCandidates();
            if (!itemStacks.isEmpty()) {
                candidateStacks.add(itemStacks);
                predicateTips.add(simplePredicate.getToolTips(predicate));
            }
        }
        candidates = new SlotWidget[candidateStacks.size()];
        CycleItemStackHandler itemHandler = new CycleItemStackHandler(candidateStacks);
        for (int i = 0; i < candidateStacks.size(); i++) {
            int finalI = i;
            candidates[i] = new SlotWidget(itemHandler, i, 9 + (i / 6) * 18, 33 + (i % 6) * 18, false, false).setItemHook(this::itemHook).setBackgroundTexture(new ColorRectTexture(0x4fffffff)).setOnAddedTooltips((slot, list) -> predicateTips.get(finalI).forEach(tip -> list.add(new StringTextComponent(tip))));
            addWidget(candidates[i]);
        }
        updateClientSlots();
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) BlockComponent(com.lowdragmc.multiblocked.api.block.BlockComponent) ItemStackKey(com.lowdragmc.lowdraglib.utils.ItemStackKey) Direction(net.minecraft.util.Direction) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) Dist(net.minecraftforge.api.distmarker.Dist) Block(net.minecraft.block.Block) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) Map(java.util.Map) StringTextComponent(net.minecraft.util.text.StringTextComponent) NonNullList(net.minecraft.util.NonNullList) BlockState(net.minecraft.block.BlockState) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) LongSet(it.unimi.dsi.fastutil.longs.LongSet) CycleBlockStateRenderer(com.lowdragmc.multiblocked.client.renderer.impl.CycleBlockStateRenderer) Collection(java.util.Collection) MultiblockState(com.lowdragmc.multiblocked.api.pattern.MultiblockState) LongSets(it.unimi.dsi.fastutil.longs.LongSets) Set(java.util.Set) Collectors(java.util.stream.Collectors) SceneWidget(com.lowdragmc.lowdraglib.gui.widget.SceneWidget) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Objects(java.util.Objects) Vector3d(net.minecraft.util.math.vector.Vector3d) List(java.util.List) BlockItem(net.minecraft.item.BlockItem) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) BlockPattern(com.lowdragmc.multiblocked.api.pattern.BlockPattern) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClickData(com.lowdragmc.lowdraglib.gui.util.ClickData) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) Minecraft(net.minecraft.client.Minecraft) MultiblockShapeInfo(com.lowdragmc.multiblocked.api.pattern.MultiblockShapeInfo) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) BlockPos(net.minecraft.util.math.BlockPos) IGuiTexture(com.lowdragmc.lowdraglib.gui.texture.IGuiTexture) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) TileEntity(net.minecraft.tileentity.TileEntity) Multiblocked(com.lowdragmc.multiblocked.Multiblocked) ArrayList(java.util.ArrayList) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) ArrayList(java.util.ArrayList) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)

Example 2 with SlotWidget

use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method initTraitUI.

protected void initTraitUI(TabContainer tabContainer, PlayerEntity PlayerEntity) {
    WidgetGroup group = new WidgetGroup(20, 0, 176, 256);
    tabContainer.addTab(new TabButton(0, tabContainer.containerGroup.widgets.size() * 20, 20, 20).setTexture(new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0, 1, 0.5), new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0.5, 1, 0.5)), group);
    group.addWidget(new ImageWidget(0, 0, 176, 256, new ResourceTexture(JSONUtils.getAsString(definition.traits, "background", "multiblocked:textures/gui/custom_gui.png"))));
    if (traits.size() > 0) {
        for (int row = 0; row < 3; row++) {
            for (int col = 0; col < 9; col++) {
                group.addWidget(new SlotWidget(PlayerEntity.inventory, col + (row + 1) * 9, 7 + col * 18, 173 + row * 18).setLocationInfo(true, false));
            }
        }
        for (int slot = 0; slot < 9; slot++) {
            group.addWidget(new SlotWidget(PlayerEntity.inventory, slot, 7 + slot * 18, 231).setLocationInfo(true, true));
        }
    }
    for (CapabilityTrait trait : traits.values()) {
        trait.createUI(this, group, PlayerEntity);
    }
}
Also used : SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) TabButton(com.lowdragmc.lowdraglib.gui.widget.TabButton) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget)

Example 3 with SlotWidget

use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.

the class ItemsContentWidget method onContentUpdate.

@Override
protected void onContentUpdate() {
    List<List<ItemStack>> stacks = Collections.singletonList(Arrays.stream(content.ingredient.getItems()).map(stack -> {
        ItemStack copy = stack.copy();
        copy.setCount(content.getAmount());
        return copy;
    }).collect(Collectors.toList()));
    if (itemHandler != null) {
        itemHandler.updateStacks(stacks);
    } else {
        itemHandler = new CycleItemStackHandler(stacks);
        addWidget(new SlotWidget(itemHandler, 0, 1, 1, false, false).setDrawOverlay(false).setOnAddedTooltips((s, l) -> {
            if (chance < 1) {
                l.add(chance == 0 ? new TranslationTextComponent("multiblocked.gui.content.chance_0") : new TranslationTextComponent("multiblocked.gui.content.chance_1", String.format("%.1f", chance * 100)));
            }
            if (perTick) {
                l.add(new TranslationTextComponent("multiblocked.gui.content.per_tick"));
            }
        }));
    }
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) Arrays(java.util.Arrays) TagCollectionManager(net.minecraft.tags.TagCollectionManager) LocalizationUtils(com.lowdragmc.lowdraglib.utils.LocalizationUtils) Item(net.minecraft.item.Item) ItemsIngredient(com.lowdragmc.multiblocked.api.recipe.ItemsIngredient) ArrayUtils(org.apache.commons.lang3.ArrayUtils) PhantomSlotWidget(com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ResourceBorderTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) LabelWidget(com.lowdragmc.lowdraglib.gui.widget.LabelWidget) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) TextTexture(com.lowdragmc.lowdraglib.gui.texture.TextTexture) ContentWidget(com.lowdragmc.multiblocked.api.gui.recipe.ContentWidget) TextFieldWidget(com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget) Collection(java.util.Collection) DraggableScrollableWidgetGroup(com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup) SwitchWidget(com.lowdragmc.lowdraglib.gui.widget.SwitchWidget) Items(net.minecraft.item.Items) Collectors(java.util.stream.Collectors) ButtonWidget(com.lowdragmc.lowdraglib.gui.widget.ButtonWidget) List(java.util.List) ColorRectTexture(com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture) ITagCollection(net.minecraft.tags.ITagCollection) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) ResourceLocation(net.minecraft.util.ResourceLocation) Collections(java.util.Collections) PhantomSlotWidget(com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 4 with SlotWidget

use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.

the class PatternWidget method reset.

private void reset(int index) {
    if (index >= patterns.length || index < 0)
        return;
    this.index = index;
    MBPattern pattern = patterns[index];
    if (pattern.controllerBase.isFormed()) {
        LongSet set = pattern.controllerBase.state.getMatchContext().getOrDefault("renderMask", LongSets.EMPTY_SET);
        Set<BlockPos> modelDisabled = set.stream().map(BlockPos::of).collect(Collectors.toSet());
        if (!modelDisabled.isEmpty()) {
            sceneWidget.setRenderedCore(pattern.blockMap.keySet().stream().filter(pos -> !modelDisabled.contains(pos)).collect(Collectors.toList()), null);
        } else {
            sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
        }
    } else {
        sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
    }
    if (slotWidgets != null) {
        for (SlotWidget slotWidget : slotWidgets) {
            removeWidget(slotWidget);
        }
    }
    slotWidgets = new SlotWidget[Math.min(pattern.parts.size(), 18)];
    IItemHandler itemHandler = new ItemStackHandler(pattern.parts);
    for (int i = 0; i < slotWidgets.length; i++) {
        slotWidgets[i] = new SlotWidget(itemHandler, i, 7 + (i % 9) * 18, 176 + (i / 9) * 18, false, false).setItemHook(this::itemHook);
        addWidget(slotWidgets[i]);
    }
    leftButton.setVisible(index > 0);
    rightButton.setVisible(index < patterns.length - 1);
    updateClientSlots();
    switchWidget.setPressed(pattern.controllerBase.isFormed());
}
Also used : CycleItemStackHandler(com.lowdragmc.lowdraglib.utils.CycleItemStackHandler) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) IItemHandler(net.minecraftforge.items.IItemHandler) LongSet(it.unimi.dsi.fastutil.longs.LongSet) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

SlotWidget (com.lowdragmc.lowdraglib.gui.widget.SlotWidget)4 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)3 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)3 CycleItemStackHandler (com.lowdragmc.lowdraglib.utils.CycleItemStackHandler)3 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)2 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)2 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)2 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)2 SwitchWidget (com.lowdragmc.lowdraglib.gui.widget.SwitchWidget)2 LongSet (it.unimi.dsi.fastutil.longs.LongSet)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)2 IGuiTexture (com.lowdragmc.lowdraglib.gui.texture.IGuiTexture)1 ResourceBorderTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture)1 ClickData (com.lowdragmc.lowdraglib.gui.util.ClickData)1 DraggableScrollableWidgetGroup (com.lowdragmc.lowdraglib.gui.widget.DraggableScrollableWidgetGroup)1 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)1 PhantomSlotWidget (com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget)1