Search in sources :

Example 6 with Pair

use of com.simibubi.create.foundation.utility.Pair in project Create by Creators-of-Create.

the class BasinCategory method draw.

@Override
public void draw(BasinRecipe recipe, PoseStack matrixStack, double mouseX, double mouseY) {
    List<Pair<Ingredient, MutableInt>> actualIngredients = ItemHelper.condenseIngredients(recipe.getIngredients());
    int size = actualIngredients.size() + recipe.getFluidIngredients().size();
    int outSize = recipe.getFluidResults().size() + recipe.getRollableResults().size();
    int xOffset = size < 3 ? (3 - size) * 19 / 2 : 0;
    HeatCondition requiredHeat = recipe.getRequiredHeat();
    int yOffset = 0;
    for (int i = 0; i < size; i++) AllGuiTextures.JEI_SLOT.render(matrixStack, 16 + xOffset + (i % 3) * 19, 50 - (i / 3) * 19 + yOffset);
    boolean noHeat = requiredHeat == HeatCondition.NONE;
    int vRows = (1 + outSize) / 2;
    for (int i = 0; i < outSize; i++) AllGuiTextures.JEI_SLOT.render(matrixStack, 141 - (outSize % 2 != 0 && i == outSize - 1 ? 0 : i % 2 == 0 ? 10 : -9), -19 * (i / 2) + 50 + yOffset);
    if (vRows <= 2)
        AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 136, -19 * (vRows - 1) + 32 + yOffset);
    AllGuiTextures shadow = noHeat ? AllGuiTextures.JEI_SHADOW : AllGuiTextures.JEI_LIGHT;
    shadow.render(matrixStack, 81, 58 + (noHeat ? 10 : 30));
    if (!needsHeating)
        return;
    AllGuiTextures heatBar = noHeat ? AllGuiTextures.JEI_NO_HEAT_BAR : AllGuiTextures.JEI_HEAT_BAR;
    heatBar.render(matrixStack, 4, 80);
    Minecraft.getInstance().font.draw(matrixStack, Lang.translate(requiredHeat.getTranslationKey()), 9, 86, requiredHeat.getColor());
}
Also used : HeatCondition(com.simibubi.create.content.contraptions.processing.HeatCondition) AllGuiTextures(com.simibubi.create.foundation.gui.AllGuiTextures) Pair(com.simibubi.create.foundation.utility.Pair)

Example 7 with Pair

use of com.simibubi.create.foundation.utility.Pair in project Create by Creators-of-Create.

the class AttributeFilterScreen method referenceItemChanged.

private void referenceItemChanged(ItemStack stack) {
    lastItemScanned = stack;
    if (stack.isEmpty()) {
        attributeSelector.active = false;
        attributeSelector.visible = false;
        attributeSelectorLabel.text = referenceH.plainCopy().withStyle(ChatFormatting.ITALIC);
        add.active = false;
        addInverted.active = false;
        attributeSelector.calling(s -> {
        });
        return;
    }
    add.active = true;
    addInverted.active = true;
    attributeSelector.titled(stack.getHoverName().plainCopy().append("..."));
    attributesOfItem.clear();
    for (ItemAttribute itemAttribute : ItemAttribute.types) attributesOfItem.addAll(itemAttribute.listAttributesOf(stack, minecraft.level));
    List<Component> options = attributesOfItem.stream().map(a -> a.format(false)).collect(Collectors.toList());
    attributeSelector.forOptions(options);
    attributeSelector.active = true;
    attributeSelector.visible = true;
    attributeSelector.setState(0);
    attributeSelector.calling(i -> {
        attributeSelectorLabel.setTextAndTrim(options.get(i), true, 112);
        ItemAttribute selected = attributesOfItem.get(i);
        for (Pair<ItemAttribute, Boolean> existing : menu.selectedAttributes) {
            CompoundTag testTag = new CompoundTag();
            CompoundTag testTag2 = new CompoundTag();
            existing.getFirst().serializeNBT(testTag);
            selected.serializeNBT(testTag2);
            if (testTag.equals(testTag2)) {
                add.active = false;
                addInverted.active = false;
                return;
            }
        }
        add.active = true;
        addInverted.active = true;
    });
    attributeSelector.onChanged();
}
Also used : AllPackets(com.simibubi.create.foundation.networking.AllPackets) Arrays(java.util.Arrays) SelectionScrollInput(com.simibubi.create.foundation.gui.widget.SelectionScrollInput) Component(net.minecraft.network.chat.Component) Label(com.simibubi.create.foundation.gui.widget.Label) IconButton(com.simibubi.create.foundation.gui.widget.IconButton) Option(com.simibubi.create.content.logistics.item.filter.FilterScreenPacket.Option) Inventory(net.minecraft.world.entity.player.Inventory) Collectors(java.util.stream.Collectors) AllIcons(com.simibubi.create.foundation.gui.AllIcons) Pair(com.simibubi.create.foundation.utility.Pair) MutableComponent(net.minecraft.network.chat.MutableComponent) AllGuiTextures(com.simibubi.create.foundation.gui.AllGuiTextures) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) List(java.util.List) TextComponent(net.minecraft.network.chat.TextComponent) CompoundTag(net.minecraft.nbt.CompoundTag) ChatFormatting(net.minecraft.ChatFormatting) WhitelistMode(com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode) Lang(com.simibubi.create.foundation.utility.Lang) ItemStack(net.minecraft.world.item.ItemStack) Indicator(com.simibubi.create.foundation.gui.widget.Indicator) Component(net.minecraft.network.chat.Component) MutableComponent(net.minecraft.network.chat.MutableComponent) TextComponent(net.minecraft.network.chat.TextComponent) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 8 with Pair

use of com.simibubi.create.foundation.utility.Pair in project Create by Creators-of-Create.

the class PumpTileEntity method searchForEndpointRecursively.

protected boolean searchForEndpointRecursively(Map<BlockPos, Pair<Integer, Map<Direction, Boolean>>> pipeGraph, Set<BlockFace> targets, Map<Integer, Set<BlockFace>> validFaces, BlockFace currentFace, boolean pull) {
    BlockPos currentPos = currentFace.getPos();
    if (!pipeGraph.containsKey(currentPos))
        return false;
    Pair<Integer, Map<Direction, Boolean>> pair = pipeGraph.get(currentPos);
    int distance = pair.getFirst();
    boolean atLeastOneBranchSuccessful = false;
    for (Direction nextFacing : Iterate.directions) {
        if (nextFacing == currentFace.getFace())
            continue;
        Map<Direction, Boolean> map = pair.getSecond();
        if (!map.containsKey(nextFacing))
            continue;
        BlockFace localTarget = new BlockFace(currentPos, nextFacing);
        if (targets.contains(localTarget)) {
            validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(localTarget);
            atLeastOneBranchSuccessful = true;
            continue;
        }
        if (map.get(nextFacing) != pull)
            continue;
        if (!searchForEndpointRecursively(pipeGraph, targets, validFaces, new BlockFace(currentPos.relative(nextFacing), nextFacing.getOpposite()), pull))
            continue;
        validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(localTarget);
        atLeastOneBranchSuccessful = true;
    }
    if (atLeastOneBranchSuccessful)
        validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(currentFace);
    return atLeastOneBranchSuccessful;
}
Also used : Direction(net.minecraft.core.Direction) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) HashSet(java.util.HashSet) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) Chaser(com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser) Map(java.util.Map) BlockFace(com.simibubi.create.foundation.utility.BlockFace) Nullable(javax.annotation.Nullable) BlockAndTintGetter(net.minecraft.world.level.BlockAndTintGetter) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IdentityHashMap(java.util.IdentityHashMap) Iterate(com.simibubi.create.foundation.utility.Iterate) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) Set(java.util.Set) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Pair(com.simibubi.create.foundation.utility.Pair) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) Couple(com.simibubi.create.foundation.utility.Couple) BlockPos(net.minecraft.core.BlockPos) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) Entry(java.util.Map.Entry) LevelAccessor(net.minecraft.world.level.LevelAccessor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) LerpedFloat(com.simibubi.create.foundation.utility.animation.LerpedFloat) BlockFace(com.simibubi.create.foundation.utility.BlockFace) Direction(net.minecraft.core.Direction) BlockPos(net.minecraft.core.BlockPos) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HashMap(java.util.HashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashSet(java.util.HashSet)

Example 9 with Pair

use of com.simibubi.create.foundation.utility.Pair in project Create by Creators-of-Create.

the class FluidPropagator method propagateChangedPipe.

public static void propagateChangedPipe(LevelAccessor world, BlockPos pipePos, BlockState pipeState) {
    List<Pair<Integer, BlockPos>> frontier = new ArrayList<>();
    Set<BlockPos> visited = new HashSet<>();
    Set<Pair<PumpTileEntity, Direction>> discoveredPumps = new HashSet<>();
    frontier.add(Pair.of(0, pipePos));
    // Visit all connected pumps to update their network
    while (!frontier.isEmpty()) {
        Pair<Integer, BlockPos> pair = frontier.remove(0);
        BlockPos currentPos = pair.getSecond();
        if (visited.contains(currentPos))
            continue;
        visited.add(currentPos);
        BlockState currentState = currentPos.equals(pipePos) ? pipeState : world.getBlockState(currentPos);
        FluidTransportBehaviour pipe = getPipe(world, currentPos);
        if (pipe == null)
            continue;
        pipe.wipePressure();
        for (Direction direction : getPipeConnections(currentState, pipe)) {
            BlockPos target = currentPos.relative(direction);
            if (!world.isAreaLoaded(target, 0))
                continue;
            BlockEntity tileEntity = world.getBlockEntity(target);
            BlockState targetState = world.getBlockState(target);
            if (tileEntity instanceof PumpTileEntity) {
                if (!AllBlocks.MECHANICAL_PUMP.has(targetState) || targetState.getValue(PumpBlock.FACING).getAxis() != direction.getAxis())
                    continue;
                discoveredPumps.add(Pair.of((PumpTileEntity) tileEntity, direction.getOpposite()));
                continue;
            }
            if (visited.contains(target))
                continue;
            FluidTransportBehaviour targetPipe = getPipe(world, target);
            if (targetPipe == null)
                continue;
            Integer distance = pair.getFirst();
            if (distance >= getPumpRange() && !targetPipe.hasAnyPressure())
                continue;
            if (targetPipe.canHaveFlowToward(targetState, direction.getOpposite()))
                frontier.add(Pair.of(distance + 1, target));
        }
    }
    discoveredPumps.forEach(pair -> pair.getFirst().updatePipesOnSide(pair.getSecond()));
}
Also used : ArrayList(java.util.ArrayList) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Pair(com.simibubi.create.foundation.utility.Pair) HashSet(java.util.HashSet) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

Pair (com.simibubi.create.foundation.utility.Pair)9 ArrayList (java.util.ArrayList)6 BlockPos (net.minecraft.core.BlockPos)5 Direction (net.minecraft.core.Direction)5 BlockState (net.minecraft.world.level.block.state.BlockState)4 BlockFace (com.simibubi.create.foundation.utility.BlockFace)3 HashSet (java.util.HashSet)3 ItemStack (net.minecraft.world.item.ItemStack)3 HeatCondition (com.simibubi.create.content.contraptions.processing.HeatCondition)2 AllGuiTextures (com.simibubi.create.foundation.gui.AllGuiTextures)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 Set (java.util.Set)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)1 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)1 Flow (com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow)1