Search in sources :

Example 6 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.

the class BeltFunnelInteractionHandler method checkForFunnels.

public static boolean checkForFunnels(BeltInventory beltInventory, TransportedItemStack currentItem, float nextOffset) {
    boolean beltMovementPositive = beltInventory.beltMovementPositive;
    int firstUpcomingSegment = (int) Math.floor(currentItem.beltPosition);
    int step = beltMovementPositive ? 1 : -1;
    firstUpcomingSegment = Mth.clamp(firstUpcomingSegment, 0, beltInventory.belt.beltLength - 1);
    for (int segment = firstUpcomingSegment; beltMovementPositive ? segment <= nextOffset : segment + 1 >= nextOffset; segment += step) {
        BlockPos funnelPos = BeltHelper.getPositionForOffset(beltInventory.belt, segment).above();
        Level world = beltInventory.belt.getLevel();
        BlockState funnelState = world.getBlockState(funnelPos);
        if (!(funnelState.getBlock() instanceof BeltFunnelBlock))
            continue;
        Direction funnelFacing = funnelState.getValue(BeltFunnelBlock.HORIZONTAL_FACING);
        Direction movementFacing = beltInventory.belt.getMovementFacing();
        boolean blocking = funnelFacing == movementFacing.getOpposite();
        if (funnelFacing == movementFacing)
            continue;
        if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.PUSHING)
            continue;
        float funnelEntry = segment + .5f;
        if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.EXTENDED)
            funnelEntry += .499f * (beltMovementPositive ? -1 : 1);
        boolean hasCrossed = nextOffset > funnelEntry && beltMovementPositive || nextOffset < funnelEntry && !beltMovementPositive;
        if (!hasCrossed)
            return false;
        if (blocking)
            currentItem.beltPosition = funnelEntry;
        if (world.isClientSide || funnelState.getOptionalValue(BeltFunnelBlock.POWERED).orElse(false))
            if (blocking)
                return true;
            else
                continue;
        BlockEntity te = world.getBlockEntity(funnelPos);
        if (!(te instanceof FunnelTileEntity))
            return true;
        FunnelTileEntity funnelTE = (FunnelTileEntity) te;
        InvManipulationBehaviour inserting = funnelTE.getBehaviour(InvManipulationBehaviour.TYPE);
        FilteringBehaviour filtering = funnelTE.getBehaviour(FilteringBehaviour.TYPE);
        if (inserting == null || filtering != null && !filtering.test(currentItem.stack))
            if (blocking)
                return true;
            else
                continue;
        int amountToExtract = funnelTE.getAmountToExtract();
        ItemStack toInsert = currentItem.stack.copy();
        if (amountToExtract > toInsert.getCount())
            if (blocking)
                return true;
            else
                continue;
        if (amountToExtract != -1) {
            toInsert.setCount(amountToExtract);
            ItemStack remainder = inserting.simulate().insert(toInsert);
            if (!remainder.isEmpty())
                if (blocking)
                    return true;
                else
                    continue;
        }
        ItemStack remainder = inserting.insert(toInsert);
        if (toInsert.equals(remainder, false))
            if (blocking)
                return true;
            else
                continue;
        int notFilled = currentItem.stack.getCount() - toInsert.getCount();
        if (!remainder.isEmpty()) {
            remainder.grow(notFilled);
        } else if (notFilled > 0)
            remainder = ItemHandlerHelper.copyStackWithSize(currentItem.stack, notFilled);
        funnelTE.flap(true);
        funnelTE.onTransfer(toInsert);
        currentItem.stack = remainder;
        beltInventory.belt.sendData();
        if (blocking)
            return true;
    }
    return false;
}
Also used : BeltFunnelBlock(com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) Direction(net.minecraft.core.Direction) FunnelTileEntity(com.simibubi.create.content.logistics.block.funnel.FunnelTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 7 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.

the class DeployerTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    super.addBehaviours(behaviours);
    filtering = new FilteringBehaviour(this, new DeployerFilterSlot());
    behaviours.add(filtering);
    processingBehaviour = new BeltProcessingBehaviour(this).whenItemEnters((s, i) -> BeltDeployerCallbacks.onItemReceived(s, i, this)).whileItemHeld((s, i) -> BeltDeployerCallbacks.whenItemHeld(s, i, this));
    behaviours.add(processingBehaviour);
}
Also used : VecHelper(com.simibubi.create.foundation.utility.VecHelper) AABB(net.minecraft.world.phys.AABB) Direction(net.minecraft.core.Direction) Inventory(net.minecraft.world.entity.player.Inventory) Dist(net.minecraftforge.api.distmarker.Dist) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TooltipHelper(com.simibubi.create.foundation.item.TooltipHelper) TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour) FACING(com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Capability(net.minecraftforge.common.capabilities.Capability) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) PartialModel(com.jozufozu.flywheel.core.PartialModel) ItemStack(net.minecraft.world.item.ItemStack) RecipeWrapper(net.minecraftforge.items.wrapper.RecipeWrapper) Tag(net.minecraft.nbt.Tag) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ServerLevel(net.minecraft.server.level.ServerLevel) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) ServerPlayer(net.minecraft.server.level.ServerPlayer) Container(net.minecraft.world.Container) ClipContext(net.minecraft.world.level.ClipContext) AllRecipeTypes(com.simibubi.create.AllRecipeTypes) SequencedAssemblyRecipe(com.simibubi.create.content.contraptions.itemAssembly.SequencedAssemblyRecipe) AllBlocks(com.simibubi.create.AllBlocks) Nullable(javax.annotation.Nullable) SandPaperItem(com.simibubi.create.content.curiosities.tools.SandPaperItem) AllBlockPartials(com.simibubi.create.AllBlockPartials) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) Component(net.minecraft.network.chat.Component) SandPaperInv(com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe.SandPaperInv) AllTriggers(com.simibubi.create.foundation.advancement.AllTriggers) BeltProcessingBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour) Fluid(net.minecraft.world.level.ClipContext.Fluid) Block(net.minecraft.world.level.ClipContext.Block) MinecraftForge(net.minecraftforge.common.MinecraftForge) Recipe(net.minecraft.world.item.crafting.Recipe) Vec3(net.minecraft.world.phys.Vec3) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) InteractionHand(net.minecraft.world.InteractionHand) Mth(net.minecraft.util.Mth) LerpedFloat(com.simibubi.create.foundation.utility.animation.LerpedFloat) ListTag(net.minecraft.nbt.ListTag) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) BeltProcessingBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour)

Example 8 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.

the class BasinTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(this));
    filtering = new FilteringBehaviour(this, new BasinValueBox()).moveText(new Vec3(2, -8, 0)).withCallback(newFilter -> contentsChanged = true).forRecipes();
    behaviours.add(filtering);
    inputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.INPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true);
    outputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.OUTPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true).forbidInsertion();
    behaviours.add(inputTank);
    behaviours.add(outputTank);
    fluidCapability = LazyOptional.of(() -> {
        LazyOptional<? extends IFluidHandler> inputCap = inputTank.getCapability();
        LazyOptional<? extends IFluidHandler> outputCap = outputTank.getCapability();
        return new CombinedTankWrapper(inputCap.orElse(null), outputCap.orElse(null));
    });
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) LazyOptional(net.minecraftforge.common.util.LazyOptional) Vec3(net.minecraft.world.phys.Vec3) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper)

Example 9 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.

the class StockpileSwitchTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    filtering = new FilteringBehaviour(this, new FilteredDetectorFilterSlot()).moveText(new Vec3(0, 5, 0)).withCallback($ -> updateCurrentLevel());
    behaviours.add(filtering);
    InterfaceProvider towardBlockFacing = InterfaceProvider.towardBlockFacing();
    behaviours.add(observedInventory = new InvManipulationBehaviour(this, towardBlockFacing).bypassSidedness());
    behaviours.add(observedTank = new TankManipulationBehaviour(this, towardBlockFacing).bypassSidedness());
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) InterfaceProvider(com.simibubi.create.foundation.tileEntity.behaviour.inventory.CapManipulationBehaviourBase.InterfaceProvider) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) TankManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.TankManipulationBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) TickPriority(net.minecraft.world.ticks.TickPriority) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) Mth(net.minecraft.util.Mth) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) Vec3(net.minecraft.world.phys.Vec3) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) InterfaceProvider(com.simibubi.create.foundation.tileEntity.behaviour.inventory.CapManipulationBehaviourBase.InterfaceProvider) TankManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.TankManipulationBehaviour)

Example 10 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create by Creators-of-Create.

the class FunnelTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    invManipulation = new InvManipulationBehaviour(this, (w, p, s) -> new BlockFace(p, AbstractFunnelBlock.getFunnelFacing(s).getOpposite()));
    behaviours.add(invManipulation);
    filtering = new FilteringBehaviour(this, new FunnelFilterSlotPositioning());
    filtering.showCountWhen(this::supportsAmountOnFilter);
    filtering.onlyActiveWhen(this::supportsFiltering);
    behaviours.add(filtering);
    behaviours.add(new DirectBeltInputBehaviour(this).onlyInsertWhen(this::supportsDirectBeltInput).setInsertionHandler(this::handleDirectBeltInput));
}
Also used : InstancedRenderDispatcher(com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher) AllPackets(com.simibubi.create.foundation.networking.AllPackets) IHaveHoveringInformation(com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation) VecHelper(com.simibubi.create.foundation.utility.VecHelper) AABB(net.minecraft.world.phys.AABB) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) BeltHelper(com.simibubi.create.content.contraptions.relays.belt.BeltHelper) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) Dist(net.minecraftforge.api.distmarker.Dist) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) AllConfigs(com.simibubi.create.foundation.config.AllConfigs) BlockFace(com.simibubi.create.foundation.utility.BlockFace) WeakReference(java.lang.ref.WeakReference) AllBlocks(com.simibubi.create.AllBlocks) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) DistExecutor(net.minecraftforge.fml.DistExecutor) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) Vec3(net.minecraft.world.phys.Vec3) Shape(com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock.Shape) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) FunnelFlapPacket(com.simibubi.create.content.logistics.packet.FunnelFlapPacket) ItemStack(net.minecraft.world.item.ItemStack) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) AllSoundEvents(com.simibubi.create.AllSoundEvents) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BlockFace(com.simibubi.create.foundation.utility.BlockFace) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour)

Aggregations

FilteringBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)15 ItemStack (net.minecraft.world.item.ItemStack)7 InvManipulationBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour)6 BlockState (net.minecraft.world.level.block.state.BlockState)6 BlockPos (net.minecraft.core.BlockPos)5 Direction (net.minecraft.core.Direction)5 Vec3 (net.minecraft.world.phys.Vec3)5 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)4 TileEntityBehaviour (com.simibubi.create.foundation.tileEntity.TileEntityBehaviour)3 List (java.util.List)3 CompoundTag (net.minecraft.nbt.CompoundTag)3 BlockEntityType (net.minecraft.world.level.block.entity.BlockEntityType)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 AllBlocks (com.simibubi.create.AllBlocks)2 SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)2 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)2 InterfaceProvider (com.simibubi.create.foundation.tileEntity.behaviour.inventory.CapManipulationBehaviourBase.InterfaceProvider)2 TankManipulationBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.inventory.TankManipulationBehaviour)2 VecHelper (com.simibubi.create.foundation.utility.VecHelper)2