use of gregtech.api.recipes.Recipe.ChanceEntry in project GregTech by GregTechCE.
the class RecipeBuilder method chancedOutput.
public R chancedOutput(ItemStack stack, int chance, int tierChanceBoost) {
if (stack == null || stack.isEmpty()) {
return (R) this;
}
if (0 >= chance || chance > Recipe.getMaxChancedValue()) {
GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.", Recipe.getMaxChancedValue(), chance);
GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
this.chancedOutputs.add(new ChanceEntry(stack.copy(), chance, tierChanceBoost));
return (R) this;
}
use of gregtech.api.recipes.Recipe.ChanceEntry in project GregTech by GregTechCE.
the class GTRecipeWrapper method getIngredients.
@Override
public void getIngredients(IIngredients ingredients) {
if (!recipe.getInputs().isEmpty()) {
List<CountableIngredient> recipeInputs = recipe.getInputs();
List<List<ItemStack>> matchingInputs = new ArrayList<>(recipeInputs.size());
for (CountableIngredient ingredient : recipeInputs) {
List<ItemStack> ingredientValues = Arrays.stream(ingredient.getIngredient().getMatchingStacks()).map(ItemStack::copy).sorted(OreDictUnifier.getItemStackComparator()).collect(Collectors.toList());
ingredientValues.forEach(stack -> {
if (ingredient.getCount() == 0) {
notConsumedInput.add(stack);
stack.setCount(1);
} else
stack.setCount(ingredient.getCount());
});
matchingInputs.add(ingredientValues);
}
ingredients.setInputLists(VanillaTypes.ITEM, matchingInputs);
}
if (!recipe.getFluidInputs().isEmpty()) {
List<FluidStack> recipeInputs = recipe.getFluidInputs().stream().map(FluidStack::copy).collect(Collectors.toList());
recipeInputs.forEach(stack -> {
if (stack.amount == 0) {
notConsumedFluidInput.add(stack);
stack.amount = 1;
}
});
ingredients.setInputs(VanillaTypes.FLUID, recipeInputs);
}
if (!recipe.getOutputs().isEmpty() || !recipe.getChancedOutputs().isEmpty()) {
List<ItemStack> recipeOutputs = recipe.getOutputs().stream().map(ItemStack::copy).collect(Collectors.toList());
List<ChanceEntry> chancedOutputs = recipe.getChancedOutputs();
for (ChanceEntry chancedEntry : chancedOutputs) {
ItemStack chancedStack = chancedEntry.getItemStack();
chanceOutput.put(chancedStack, chancedEntry);
recipeOutputs.add(chancedStack);
}
recipeOutputs.sort(Comparator.comparingInt(stack -> {
ChanceEntry chanceEntry = chanceOutput.get(stack);
if (chanceEntry == null)
return 0;
return chanceEntry.getChance();
}));
ingredients.setOutputs(VanillaTypes.ITEM, recipeOutputs);
}
if (!recipe.getFluidOutputs().isEmpty()) {
List<FluidStack> recipeOutputs = recipe.getFluidOutputs().stream().map(FluidStack::copy).collect(Collectors.toList());
ingredients.setOutputs(VanillaTypes.FLUID, recipeOutputs);
}
}
use of gregtech.api.recipes.Recipe.ChanceEntry in project GregTech by GregTechCE.
the class GTRecipeWrapper method addTooltip.
public void addTooltip(int slotIndex, boolean input, Object ingredient, List<String> tooltip) {
boolean notConsumed = false;
ChanceEntry entry = null;
if (ingredient instanceof FluidStack) {
FluidStack fluidStack = ((FluidStack) ingredient);
if (notConsumedFluidInput.contains(fluidStack))
notConsumed = true;
} else if (ingredient instanceof ItemStack) {
ItemStack itemStack = ((ItemStack) ingredient);
if (notConsumedInput.contains(itemStack))
notConsumed = true;
else
entry = chanceOutput.get(itemStack);
} else {
throw new IllegalArgumentException("Unknown ingredient type: " + ingredient.getClass());
}
if (entry != null && !input) {
double chance = entry.getChance() / 100.0;
double boost = entry.getBoostPerTier() / 100.0;
tooltip.add(I18n.format("gregtech.recipe.chance", chance, boost));
} else if (notConsumed && input) {
tooltip.add(I18n.format("gregtech.recipe.not_consumed"));
}
}
Aggregations