Search in sources :

Example 1 with FilteringBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour in project Create_Aeronautics by Eriksonnaren.

the class CannonItemHandler method isItemValid.

public boolean isItemValid(int slot, ItemStack stack) {
    Optional<ItemStack> found = PotatoProjectileTypeManager.getTypeForStack(stack).map(($) -> {
        return stack;
    });
    if (!found.isPresent())
        return false;
    FilteringBehaviour filteringBehaviour = (FilteringBehaviour) this.te.getBehaviour(FilteringBehaviour.TYPE);
    return filteringBehaviour == null || filteringBehaviour.test(stack);
}
Also used : FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ItemStack(net.minecraft.item.ItemStack)

Example 2 with FilteringBehaviour

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

the class BasinTileEntity method tryClearingSpoutputOverflow.

private void tryClearingSpoutputOverflow() {
    BlockState blockState = getBlockState();
    if (!(blockState.getBlock() instanceof BasinBlock))
        return;
    Direction direction = blockState.getValue(BasinBlock.FACING);
    BlockEntity te = level.getBlockEntity(worldPosition.below().relative(direction));
    FilteringBehaviour filter = null;
    InvManipulationBehaviour inserter = null;
    if (te != null) {
        filter = TileEntityBehaviour.get(level, te.getBlockPos(), FilteringBehaviour.TYPE);
        inserter = TileEntityBehaviour.get(level, te.getBlockPos(), InvManipulationBehaviour.TYPE);
    }
    IItemHandler targetInv = te == null ? null : te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(inserter == null ? null : inserter.getInventory());
    IFluidHandler targetTank = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
    boolean update = false;
    for (Iterator<ItemStack> iterator = spoutputBuffer.iterator(); iterator.hasNext(); ) {
        ItemStack itemStack = iterator.next();
        if (direction == Direction.DOWN) {
            Block.popResource(level, worldPosition, itemStack);
            iterator.remove();
            update = true;
            continue;
        }
        if (targetInv == null)
            break;
        if (!ItemHandlerHelper.insertItemStacked(targetInv, itemStack, true).isEmpty())
            continue;
        if (filter != null && !filter.test(itemStack))
            continue;
        update = true;
        ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), false);
        iterator.remove();
        visualizedOutputItems.add(IntAttached.withZero(itemStack));
    }
    for (Iterator<FluidStack> iterator = spoutputFluidBuffer.iterator(); iterator.hasNext(); ) {
        FluidStack fluidStack = iterator.next();
        if (direction == Direction.DOWN) {
            iterator.remove();
            update = true;
            continue;
        }
        if (targetTank == null)
            break;
        for (boolean simulate : Iterate.trueAndFalse) {
            FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE;
            int fill = targetTank instanceof SmartFluidTankBehaviour.InternalFluidHandler ? ((SmartFluidTankBehaviour.InternalFluidHandler) targetTank).forceFill(fluidStack.copy(), action) : targetTank.fill(fluidStack.copy(), action);
            if (fill != fluidStack.getAmount())
                break;
            if (simulate)
                continue;
            update = true;
            iterator.remove();
            visualizedOutputFluids.add(IntAttached.withZero(fluidStack));
        }
    }
    if (update) {
        notifyChangeOfContents();
        sendData();
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) FluidStack(net.minecraftforge.fluids.FluidStack) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) FluidAction(net.minecraftforge.fluids.capability.IFluidHandler.FluidAction) Direction(net.minecraft.core.Direction) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) BlockState(net.minecraft.world.level.block.state.BlockState) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ItemStack(net.minecraft.world.item.ItemStack) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with FilteringBehaviour

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

the class BasinRecipe method match.

public static boolean match(BasinTileEntity basin, Recipe<?> recipe) {
    FilteringBehaviour filter = basin.getFilter();
    if (filter == null)
        return false;
    boolean filterTest = filter.test(recipe.getResultItem());
    if (recipe instanceof BasinRecipe) {
        BasinRecipe basinRecipe = (BasinRecipe) recipe;
        if (basinRecipe.getRollableResults().isEmpty() && !basinRecipe.getFluidResults().isEmpty())
            filterTest = filter.test(basinRecipe.getFluidResults().get(0));
    }
    if (!filterTest)
        return false;
    return apply(basin, recipe, true);
}
Also used : FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)

Example 4 with FilteringBehaviour

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

the class CapManipulationBehaviourBase method getAmountFromFilter.

public int getAmountFromFilter() {
    int amount = -1;
    FilteringBehaviour filter = tileEntity.getBehaviour(FilteringBehaviour.TYPE);
    if (filter != null && !filter.anyAmount())
        amount = filter.getAmount();
    return amount;
}
Also used : FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)

Example 5 with FilteringBehaviour

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

the class InvManipulationBehaviour method getFilterTest.

protected Predicate<ItemStack> getFilterTest(Predicate<ItemStack> customFilter) {
    Predicate<ItemStack> test = customFilter;
    FilteringBehaviour filter = tileEntity.getBehaviour(FilteringBehaviour.TYPE);
    if (filter != null)
        test = customFilter.and(filter::test);
    return test;
}
Also used : FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ItemStack(net.minecraft.world.item.ItemStack)

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