Search in sources :

Example 1 with TraceabilityPredicate

use of com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate 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 TraceabilityPredicate

use of com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate in project Multiblocked by Low-Drag-MC.

the class PatternWidget method initializePattern.

private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, HashSet<ItemStackKey> blockDrops) {
    Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
    ControllerTileEntity controllerBase = null;
    BlockPos multiPos = locateNextRegion(500);
    BlockInfo[][][] blocks = shapeInfo.getBlocks();
    for (int x = 0; x < blocks.length; x++) {
        BlockInfo[][] aisle = blocks[x];
        for (int y = 0; y < aisle.length; y++) {
            BlockInfo[] column = aisle[y];
            for (int z = 0; z < column.length; z++) {
                TileEntity tileEntity = column[z].getTileEntity();
                BlockState blockState = column[z].getBlockState();
                if (tileEntity == null && blockState.getBlock().hasTileEntity(blockState)) {
                    tileEntity = blockState.getBlock().createTileEntity(blockState, world);
                }
                if (tileEntity instanceof ControllerTileEntity) {
                    controllerBase = (ControllerTileEntity) tileEntity;
                }
                blockMap.put(multiPos.offset(x, y, z), new BlockInfo(blockState, tileEntity));
            }
        }
    }
    world.addBlocks(blockMap);
    Map<ItemStackKey, PartInfo> parts = gatherBlockDrops(blockMap);
    blockDrops.addAll(parts.keySet());
    Map<BlockPos, TraceabilityPredicate> predicateMap = new HashMap<>();
    if (controllerBase != null) {
        loadControllerFormed(predicateMap.keySet(), controllerBase);
        predicateMap = controllerBase.state.getMatchContext().get("predicates");
    }
    return controllerBase == null ? null : new MBPattern(blockMap, parts.values().stream().sorted((one, two) -> {
        if (one.isController)
            return -1;
        if (two.isController)
            return +1;
        if (one.isTile && !two.isTile)
            return -1;
        if (two.isTile && !one.isTile)
            return +1;
        if (one.blockId != two.blockId)
            return two.blockId - one.blockId;
        return two.amount - one.amount;
    }).map(PartInfo::getItemStack).toArray(ItemStack[]::new), predicateMap, controllerBase);
}
Also used : HashMap(java.util.HashMap) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) ItemStackKey(com.lowdragmc.lowdraglib.utils.ItemStackKey) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)

Example 3 with TraceabilityPredicate

use of com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate in project Multiblocked by Low-Drag-MC.

the class PatternError method getCandidates.

public List<List<ItemStack>> getCandidates() {
    TraceabilityPredicate predicate = worldState.predicate;
    List<List<ItemStack>> candidates = new ArrayList<>();
    for (SimplePredicate common : predicate.common) {
        candidates.add(common.getCandidates());
    }
    for (SimplePredicate limited : predicate.limited) {
        candidates.add(limited.getCandidates());
    }
    return candidates;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate) SimplePredicate(com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate)

Aggregations

TraceabilityPredicate (com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)3 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)2 ItemStackKey (com.lowdragmc.lowdraglib.utils.ItemStackKey)2 SimplePredicate (com.lowdragmc.multiblocked.api.pattern.predicates.SimplePredicate)2 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ColorRectTexture (com.lowdragmc.lowdraglib.gui.texture.ColorRectTexture)1 IGuiTexture (com.lowdragmc.lowdraglib.gui.texture.IGuiTexture)1 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)1 TextTexture (com.lowdragmc.lowdraglib.gui.texture.TextTexture)1 ClickData (com.lowdragmc.lowdraglib.gui.util.ClickData)1 ButtonWidget (com.lowdragmc.lowdraglib.gui.widget.ButtonWidget)1 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 SceneWidget (com.lowdragmc.lowdraglib.gui.widget.SceneWidget)1 SlotWidget (com.lowdragmc.lowdraglib.gui.widget.SlotWidget)1 SwitchWidget (com.lowdragmc.lowdraglib.gui.widget.SwitchWidget)1 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)1 CycleItemStackHandler (com.lowdragmc.lowdraglib.utils.CycleItemStackHandler)1