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);
}
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();
}
}
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);
}
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;
}
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;
}
Aggregations