public int matches(List<FluidStack> input) { // how often we can apply the alloy int times = Integer.MAX_VALUE; List<FluidStack> needed = Lists.newLinkedList(fluids); // for each liquid in the input for(FluidStack fluid : input) { // check if it's needed ListIterator<FluidStack> iter = needed.listIterator(); while(iter.hasNext()) { FluidStack need = iter.next(); if(fluid.containsFluid(need)) { // and if it matches, remove iter.remove(); // check how often we can apply the recipe with this if(fluid.amount / need.amount < times) { times = fluid.amount / need.amount; } break; } } } // if the needed array is empty we found everything we needed return needed.isEmpty() ? times : 0; }
public AlloyRecipe(FluidStack result, FluidStack... input) { this.result = result; if(result == null || result.getFluid() == null) { throw new TinkerAPIException("Invalid Alloy recipe: No result for alloy present"); } if(input == null || input.length < 2) { throw new TinkerAPIException("Invalid Alloy recipe: Less than 2 fluids to alloy"); } ImmutableList.Builder<FluidStack> builder = ImmutableList.builder(); for(FluidStack liquid : input) { if(liquid == null) { throw new TinkerAPIException("Invalid Alloy recipe: Input cannot be null"); } if(liquid.amount < 1) { throw new TinkerAPIException("Invalid Alloy recipe: Fluid amount can't be less than 1"); } if(liquid.containsFluid(result)) { throw new TinkerAPIException("Invalid Alloy recipe: Result cannot be contained in inputs"); } builder.add(liquid); } fluids = builder.build(); }
public static boolean matches(@Nullable IStillRecipe recipe, @Nullable FluidStack item) { if (recipe == null || item == null) { return false; } return item.containsFluid(recipe.getInput()); }
@Nullable @Override public FluidStack isValidFluidStack(FluidStack stack) { return (fluidStack != null && stack != null && stack.containsFluid(fluidStack)) ? fluidStack.copy() : null; }
@Override public boolean apply(@Nullable ItemStack stack) { if (stack == null) { return false; } else { FluidStack fluidStack = FluidUtil.getFluidContained(stack); return fluidStack == null && this.fluid == null || fluidStack != null && fluidStack.containsFluid(fluid); } } }
@Override public boolean isValidInput(@Nonnull RecipeLevel machineLevel, @Nonnull MachineRecipeInput machineInput) { if (machineInput.isFluid()) { return machineInput.fluid.containsFluid(fluid); } else { return input.contains(machineInput.item); } }
@Override public FluidStack drain( final FluidStack resource, final boolean doDrain ) { if ( resource == null ) { return null; } final FluidStack a = getAccessableFluid(); if ( a != null && resource.containsFluid( a ) ) // right type of fluid. { final int aboutHowMuch = resource.amount; final int mbThatCanBeRemoved = Math.min( a.amount, aboutHowMuch - aboutHowMuch % TileEntityBitTank.MB_PER_BIT_CONVERSION ); if ( mbThatCanBeRemoved > 0 ) { a.amount = mbThatCanBeRemoved; if ( doDrain ) { final int bitCount = mbThatCanBeRemoved * TileEntityBitTank.BITS_PER_MB_CONVERSION / TileEntityBitTank.MB_PER_BIT_CONVERSION; extractBits( 0, bitCount, false ); } return a; } } return null; }
@Nullable private RecipePair getRecipe() { IInventoryAdapter inventory = getInternalInventory(); ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN); FluidStack liquid = moltenTank.getFluid(); RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory); IFabricatorRecipe recipe = recipePair.getRecipe(); if (liquid != null && recipe != null && !liquid.containsFluid(recipe.getLiquid())) { return RecipePair.EMPTY; } return recipePair; }
public static String[][] matches(@Nullable ICarpenterRecipe recipe, @Nullable FluidStack resource, ItemStack item, IInventory inventoryCrafting) { if (recipe == null) { return null; } FluidStack liquid = recipe.getFluidResource(); if (liquid != null) { if (resource == null || !resource.containsFluid(liquid)) { return null; } } ItemStack box = recipe.getBox(); if (!box.isEmpty() && !ItemStackUtil.isCraftingEquivalent(box, item)) { return null; } IDescriptiveRecipe internal = recipe.getCraftingGridRecipe(); return RecipeUtil.matches(internal, inventoryCrafting); }
private RecipeMatch matchRecipe(NNList<MachineRecipeInput> recipeInputs) { if (!isValid() || recipeInputs == null || recipeInputs.size() < requiredItems + 1) { return null; } FluidStack inputFluid = null; RecipeMatch m = new RecipeMatch(); for (MachineRecipeInput in : recipeInputs) { if (in.isFluid()) { inputFluid = in.fluid; } else { m.setRecipeInput(getRecipeInput(in.slotNumber, in.item)); } } if (requiredItems == 1) { m.r1 = m.r0; } m.in = inputFluidStacks.get(m.r0, m.r1); m.out = outputFluidStacks.get(m.r0, m.r1); if (inputFluid != null && inputFluid.containsFluid(m.in)) { return m; } else { return null; } }
@Override public boolean isRecipe(@Nonnull RecipeLevel machineLevel, @Nonnull NNList<MachineRecipeInput> inputs) { if (!machineLevel.canMake(recipelevel)) { return false; } // we need exactly 2 inputs, an item and the fluid in the tank if (inputs.size() != 2) { return false; } ItemStack machineItemStack = getInputItem(inputs); // input item stack if (Prep.isInvalid(machineItemStack)) { return false; } if (!input.contains(machineItemStack)) { return false; } FluidStack machineFluid = getInputFluid(inputs); // filling always needs a fluid in the tank, emptying not if (isFilling && machineFluid.amount == 0) { return false; } // fluid in tank must match recipe or tank must be empty if (machineFluid.amount != 0 && !machineFluid.containsFluid(fluid)) { return false; } return true; }
private boolean canOperate() { if (getInventory().get(0).isEmpty()) return false; else { ItemStack itemstack = getInventory().get(0); if (isItemValidForSlot(0, itemstack) && tank.getFluidAmount() <= tank.getCapacity() - 50) if(tank.getFluid() == null || tank.getFluid().containsFluid(new FluidStack(FluidRegistry.getFluid("honey"), 0))) return true; return false; } }
public void liquifyItem() { if (canOperate()) { if (tank.getFluid() == null || tank.getFluid().containsFluid(new FluidStack(FluidRegistry.getFluid("honey"), 0))) { if (tank.getFluidAmount() <= tank.getCapacity() - 50) { tank.fill(new FluidStack(FluidRegistry.getFluid("honey"), 50), true); getInventory().get(0).shrink(1); if (getInventory().get(0).getCount() <= 0) getInventory().set(0, ItemStack.EMPTY); } } } }
FluidStack contents = properties.getContents(); if (tank.getFluid() != null) { if (contents == null || contents.amount <= properties.getCapacity() - tank.getFluid().amount && contents.containsFluid(new FluidStack(tank.getFluid(), 0))) { recepticle.fill(tank.drain(new FluidStack(tank.getFluid(), tank.getFluid().amount), true), true); markDirty();
FluidStack contents = properties.getContents(); if (contents != null) { if (tank.getFluid() == null || tank.getFluid().amount < tank.getCapacity() && tank.getFluid().containsFluid(new FluidStack(contents.getFluid(), 0))) { tank.fill(recepticle.drain(new FluidStack(contents.getFluid(), tank.getCapacity()), true), true); markDirty(); FluidStack contents = properties.getContents(); if (tank.getFluid() != null) { if (contents == null || contents.amount <= properties.getCapacity() - tank.getFluid().amount && contents.containsFluid(new FluidStack(tank.getFluid(), 0))) { recepticle.fill(tank.drain(new FluidStack(tank.getFluid(), tank.getFluid().amount), true), true); markDirty();