Search in sources :

Example 1 with CycleItemStackHandler

use of com.lowdragmc.lowdraglib.utils.CycleItemStackHandler 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 CycleItemStackHandler

use of com.lowdragmc.lowdraglib.utils.CycleItemStackHandler 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)

Aggregations

ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)2 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)2 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)2 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)2 SlotWidget (com.lowdragmc.lowdraglib.gui.widget.SlotWidget)2 SwitchWidget (com.lowdragmc.lowdraglib.gui.widget.SwitchWidget)2 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)2 CycleItemStackHandler (com.lowdragmc.lowdraglib.utils.CycleItemStackHandler)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)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 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 LabelWidget (com.lowdragmc.lowdraglib.gui.widget.LabelWidget)1 PhantomSlotWidget (com.lowdragmc.lowdraglib.gui.widget.PhantomSlotWidget)1 SceneWidget (com.lowdragmc.lowdraglib.gui.widget.SceneWidget)1 TextFieldWidget (com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget)1