Search in sources :

Example 6 with BlockFace

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

the class MechanicalCrafterTileEntity method tryInsert.

public void tryInsert() {
    if (!inserting.hasInventory() && !isTargetingBelt()) {
        ejectWholeGrid();
        return;
    }
    boolean chagedPhase = phase != Phase.INSERTING;
    final List<Pair<Integer, Integer>> inserted = new LinkedList<>();
    DirectBeltInputBehaviour behaviour = getTargetingBelt();
    for (Entry<Pair<Integer, Integer>, ItemStack> entry : groupedItems.grid.entrySet()) {
        Pair<Integer, Integer> pair = entry.getKey();
        ItemStack stack = entry.getValue();
        BlockFace face = getTargetFace(level, worldPosition, getBlockState());
        ItemStack remainder = behaviour == null ? inserting.insert(stack.copy()) : behaviour.handleInsertion(stack, face.getFace(), false);
        if (!remainder.isEmpty()) {
            stack.setCount(remainder.getCount());
            continue;
        }
        inserted.add(pair);
    }
    inserted.forEach(groupedItems.grid::remove);
    if (groupedItems.grid.isEmpty())
        ejectWholeGrid();
    else
        phase = Phase.INSERTING;
    if (!inserted.isEmpty() || chagedPhase)
        sendData();
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BlockFace(com.simibubi.create.foundation.utility.BlockFace) ItemStack(net.minecraft.world.item.ItemStack) LinkedList(java.util.LinkedList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 7 with BlockFace

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

the class PipeConnection method manageFlows.

public boolean manageFlows(Level world, BlockPos pos, FluidStack internalFluid, Predicate<FluidStack> extractionPredicate) {
    // Only keep network if still valid
    Optional<FluidNetwork> retainedNetwork = network;
    network = Optional.empty();
    // chunk border
    if (!source.isPresent() && !determineSource(world, pos))
        return false;
    FlowSource flowSource = source.get();
    if (!hasFlow()) {
        if (!hasPressure())
            return false;
        // Try starting a new flow
        boolean prioritizeInbound = comparePressure() < 0;
        for (boolean trueFalse : Iterate.trueAndFalse) {
            boolean inbound = prioritizeInbound == trueFalse;
            if (pressure.get(inbound) == 0)
                continue;
            if (tryStartingNewFlow(inbound, inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid))
                return true;
        }
        return false;
    }
    // Manage existing flow
    Flow flow = this.flow.get();
    FluidStack provided = flow.inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid;
    if (!hasPressure() || provided.isEmpty() || !provided.isFluidEqual(flow.fluid)) {
        this.flow = Optional.empty();
        return true;
    }
    // Overwrite existing flow
    if (flow.inbound != comparePressure() < 0) {
        boolean inbound = !flow.inbound;
        if (inbound && !provided.isEmpty() || !inbound && !internalFluid.isEmpty()) {
            FluidPropagator.resetAffectedFluidNetworks(world, pos, side);
            tryStartingNewFlow(inbound, inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid);
            return true;
        }
    }
    flowSource.whileFlowPresent(world, flow.inbound);
    if (!flowSource.isEndpoint())
        return false;
    if (!flow.inbound)
        return false;
    // Layer III
    network = retainedNetwork;
    if (!hasNetwork())
        network = Optional.of(new FluidNetwork(world, new BlockFace(pos, side), flowSource::provideHandler));
    network.get().tick();
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) BlockFace(com.simibubi.create.foundation.utility.BlockFace)

Example 8 with BlockFace

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

the class PipeConnection method determineSource.

public boolean determineSource(Level world, BlockPos pos) {
    BlockPos relative = pos.relative(side);
    // cannot use world.isLoaded because it always returns true on client
    if (world.getChunk(relative.getX() >> 4, relative.getZ() >> 4, ChunkStatus.FULL, false) == null)
        return false;
    BlockFace location = new BlockFace(pos, side);
    if (FluidPropagator.isOpenEnd(world, pos, side)) {
        if (previousSource.orElse(null) instanceof OpenEndedPipe)
            source = previousSource;
        else
            source = Optional.of(new OpenEndedPipe(location));
        return true;
    }
    if (FluidPropagator.hasFluidCapability(world, location.getConnectedPos(), side.getOpposite())) {
        source = Optional.of(new FlowSource.FluidHandler(location));
        return true;
    }
    FluidTransportBehaviour behaviour = TileEntityBehaviour.get(world, relative, FluidTransportBehaviour.TYPE);
    source = Optional.of(behaviour == null ? new FlowSource.Blocked(location) : new FlowSource.OtherPipe(location));
    return true;
}
Also used : BlockFace(com.simibubi.create.foundation.utility.BlockFace) BlockPos(net.minecraft.core.BlockPos)

Example 9 with BlockFace

use of com.simibubi.create.foundation.utility.BlockFace 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 10 with BlockFace

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

the class OpenEndedPipe method fromNBT.

public static OpenEndedPipe fromNBT(CompoundTag compound, BlockPos tilePos) {
    BlockFace fromNBT = BlockFace.fromNBT(compound.getCompound("Location"));
    OpenEndedPipe oep = new OpenEndedPipe(new BlockFace(tilePos, fromNBT.getFace()));
    oep.fluidHandler.readFromNBT(compound);
    oep.wasPulling = compound.getBoolean("Pulling");
    return oep;
}
Also used : BlockFace(com.simibubi.create.foundation.utility.BlockFace)

Aggregations

BlockFace (com.simibubi.create.foundation.utility.BlockFace)11 BlockPos (net.minecraft.core.BlockPos)7 Direction (net.minecraft.core.Direction)6 Pair (com.simibubi.create.foundation.utility.Pair)3 ArrayList (java.util.ArrayList)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)2 TileEntityBehaviour (com.simibubi.create.foundation.tileEntity.TileEntityBehaviour)2 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ItemStack (net.minecraft.world.item.ItemStack)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 BlockEntityType (net.minecraft.world.level.block.entity.BlockEntityType)2 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)2 InstancedRenderDispatcher (com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher)1 AllBlocks (com.simibubi.create.AllBlocks)1