use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.
the class CrudeBurningCategory method setRecipe.
@Override
public void setRecipe(IRecipeLayout recipeLayout, CrudeBurningRecipe recipe, IIngredients ingredients) {
IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
NonNullList<FluidIngredient> fluidIngredients = NonNullList.of(recipe.getFluidIngredient());
List<FluidStack> out = new ArrayList<FluidStack>();
fluidStacks.init(0, true, 81, 7);
fluidStacks.set(0, withImprovedVisibility(recipe.getFluidIngredient().getMatchingFluidStacks().stream().map(fluid -> {
out.add(fluid);
return fluid;
}).collect(Collectors.toList())));
addFluidTooltip(fluidStacks, fluidIngredients, out);
}
use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.
the class CrudeBurningRecipeSerializer method fromNetwork.
@Override
public CrudeBurningRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
int burnTime = buffer.readInt();
FluidIngredient fluid = FluidIngredient.read(buffer);
return new CrudeBurningRecipe(recipeId, fluid, burnTime);
}
use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.
the class BasinRecipe method apply.
private static boolean apply(BasinTileEntity basin, Recipe<?> recipe, boolean test) {
boolean isBasinRecipe = recipe instanceof BasinRecipe;
IItemHandler availableItems = basin.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
IFluidHandler availableFluids = basin.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
if (availableItems == null || availableFluids == null)
return false;
HeatLevel heat = BasinTileEntity.getHeatLevelOf(basin.getLevel().getBlockState(basin.getBlockPos().below(1)));
if (isBasinRecipe && !((BasinRecipe) recipe).getRequiredHeat().testBlazeBurner(heat))
return false;
List<ItemStack> recipeOutputItems = new ArrayList<>();
List<FluidStack> recipeOutputFluids = new ArrayList<>();
List<Ingredient> ingredients = new LinkedList<>(recipe.getIngredients());
ingredients.sort(Comparator.comparingInt(i -> i.getItems().length));
List<FluidIngredient> fluidIngredients = isBasinRecipe ? ((BasinRecipe) recipe).getFluidIngredients() : Collections.emptyList();
for (boolean simulate : Iterate.trueAndFalse) {
if (!simulate && test)
return true;
int[] extractedItemsFromSlot = new int[availableItems.getSlots()];
int[] extractedFluidsFromTank = new int[availableFluids.getTanks()];
Ingredients: for (int i = 0; i < ingredients.size(); i++) {
Ingredient ingredient = ingredients.get(i);
for (int slot = 0; slot < availableItems.getSlots(); slot++) {
if (simulate && availableItems.getStackInSlot(slot).getCount() <= extractedItemsFromSlot[slot])
continue;
ItemStack extracted = availableItems.extractItem(slot, 1, true);
if (!ingredient.test(extracted))
continue;
// Catalyst items are never consumed
if (extracted.hasContainerItem() && extracted.getContainerItem().sameItem(extracted))
continue Ingredients;
if (!simulate)
availableItems.extractItem(slot, 1, false);
else if (extracted.hasContainerItem())
recipeOutputItems.add(extracted.getContainerItem().copy());
extractedItemsFromSlot[slot]++;
continue Ingredients;
}
// something wasn't found
return false;
}
boolean fluidsAffected = false;
FluidIngredients: for (int i = 0; i < fluidIngredients.size(); i++) {
FluidIngredient fluidIngredient = fluidIngredients.get(i);
int amountRequired = fluidIngredient.getRequiredAmount();
for (int tank = 0; tank < availableFluids.getTanks(); tank++) {
FluidStack fluidStack = availableFluids.getFluidInTank(tank);
if (simulate && fluidStack.getAmount() <= extractedFluidsFromTank[tank])
continue;
if (!fluidIngredient.test(fluidStack))
continue;
int drainedAmount = Math.min(amountRequired, fluidStack.getAmount());
if (!simulate) {
fluidStack.shrink(drainedAmount);
fluidsAffected = true;
}
amountRequired -= drainedAmount;
if (amountRequired != 0)
continue;
extractedFluidsFromTank[tank] += drainedAmount;
continue FluidIngredients;
}
// something wasn't found
return false;
}
if (fluidsAffected) {
basin.getBehaviour(SmartFluidTankBehaviour.INPUT).forEach(TankSegment::onFluidStackChanged);
basin.getBehaviour(SmartFluidTankBehaviour.OUTPUT).forEach(TankSegment::onFluidStackChanged);
}
if (simulate) {
if (recipe instanceof BasinRecipe) {
recipeOutputItems.addAll(((BasinRecipe) recipe).rollResults());
recipeOutputFluids.addAll(((BasinRecipe) recipe).getFluidResults());
} else
recipeOutputItems.add(recipe.getResultItem());
}
if (!basin.acceptOutputs(recipeOutputItems, recipeOutputFluids, simulate))
return false;
}
return true;
}
use of com.simibubi.create.foundation.fluid.FluidIngredient in project createaddition by mrh0.
the class CrudeBurningRecipeSerializer method readFromJson.
@Override
public CrudeBurningRecipe readFromJson(ResourceLocation recipeId, JsonObject json) {
int burnTime = (json.get("burnTime")).getAsInt();
FluidIngredient fluid = FluidIngredient.deserialize(json.get("input"));
return new CrudeBurningRecipe(recipeId, fluid, burnTime);
}
use of com.simibubi.create.foundation.fluid.FluidIngredient in project Create by Creators-of-Create.
the class BasinCategory method setIngredients.
@Override
public void setIngredients(BasinRecipe recipe, IIngredients ingredients) {
List<Ingredient> itemIngredients = new ArrayList<>(recipe.getIngredients());
HeatCondition requiredHeat = recipe.getRequiredHeat();
if (!requiredHeat.testBlazeBurner(HeatLevel.NONE))
itemIngredients.add(Ingredient.of(AllBlocks.BLAZE_BURNER.get()));
if (!requiredHeat.testBlazeBurner(HeatLevel.KINDLED))
itemIngredients.add(Ingredient.of(AllItems.BLAZE_CAKE.get()));
ingredients.setInputIngredients(itemIngredients);
ingredients.setInputLists(VanillaTypes.FLUID, recipe.getFluidIngredients().stream().map(FluidIngredient::getMatchingFluidStacks).collect(Collectors.toList()));
if (!recipe.getRollableResults().isEmpty())
ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem());
if (!recipe.getFluidResults().isEmpty())
ingredients.setOutputs(VanillaTypes.FLUID, recipe.getFluidResults());
}
Aggregations