use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.
the class MetaTileEntityLockedSafe method checkUnlockedItems.
private boolean checkUnlockedItems() {
CountableIngredient[] unlockComponents = getUnlockComponents();
for (int j = 0; j < unlockComponents.length; j++) {
CountableIngredient ingredient = unlockComponents[j];
if (ingredient == null)
continue;
int itemLeftToCheck = ingredient.getCount();
for (int i = 0; i < unlockInventory.getSlots(); i++) {
ItemStack otherStack = unlockInventory.getStackInSlot(i);
if (otherStack.isEmpty())
continue;
if (!ingredient.getIngredient().test(otherStack))
continue;
itemLeftToCheck -= otherStack.getCount();
}
if (itemLeftToCheck > 0)
return false;
}
return true;
}
use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.
the class MaterialRecipeHandler method processDust.
public static void processDust(OrePrefix dustPrefix, DustMaterial material) {
if (material instanceof GemMaterial) {
ItemStack gemStack = OreDictUnifier.get(OrePrefix.gem, material);
ItemStack tinyDarkAshStack = OreDictUnifier.get(OrePrefix.dustTiny, Materials.DarkAsh);
if (material.hasFlag(GemMaterial.MatFlags.CRYSTALLISABLE)) {
RecipeMaps.AUTOCLAVE_RECIPES.recipeBuilder().input(dustPrefix, material).fluidInputs(Materials.Water.getFluid(200)).chancedOutput(gemStack, 7000, 1000).duration(1600).EUt(24).buildAndRegister();
RecipeMaps.AUTOCLAVE_RECIPES.recipeBuilder().input(dustPrefix, material).fluidInputs(ModHandler.getDistilledWater(200)).chancedOutput(gemStack, 8000, 1000).duration(1200).EUt(24).buildAndRegister();
} else if (!material.hasFlag(Material.MatFlags.EXPLOSIVE) && !material.hasFlag(Material.MatFlags.FLAMMABLE)) {
RecipeMaps.IMPLOSION_RECIPES.recipeBuilder().input(dustPrefix, material, 4).outputs(GTUtility.copyAmount(3, gemStack), GTUtility.copyAmount(2, tinyDarkAshStack)).explosivesAmount(4).buildAndRegister();
}
} else if (material instanceof IngotMaterial) {
IngotMaterial metalMaterial = (IngotMaterial) material;
if (!material.hasFlag(Material.MatFlags.FLAMMABLE | MatFlags.NO_SMELTING)) {
boolean hasHotIngot = OrePrefix.ingotHot.doGenerateItem(metalMaterial);
ItemStack ingotStack = OreDictUnifier.get(hasHotIngot ? OrePrefix.ingotHot : OrePrefix.ingot, metalMaterial);
ItemStack nuggetStack = OreDictUnifier.get(OrePrefix.nugget, metalMaterial);
if (metalMaterial.blastFurnaceTemperature <= 0) {
ModHandler.addSmeltingRecipe(new UnificationEntry(dustPrefix, metalMaterial), ingotStack);
ModHandler.addSmeltingRecipe(new UnificationEntry(OrePrefix.dustTiny, metalMaterial), nuggetStack);
} else {
int duration = Math.max(1, (int) (material.getAverageMass() * metalMaterial.blastFurnaceTemperature / 50L));
ModHandler.removeFurnaceSmelting(new UnificationEntry(OrePrefix.ingot, metalMaterial));
BlastRecipeBuilder ingotSmeltingBuilder = RecipeMaps.BLAST_RECIPES.recipeBuilder().input(dustPrefix, material).outputs(ingotStack).blastFurnaceTemp(metalMaterial.blastFurnaceTemperature).duration(duration).EUt(120);
if (circuitRequiringMaterials.contains(material)) {
ingotSmeltingBuilder.inputs(new CountableIngredient(new IntCircuitIngredient(0), 0));
}
ingotSmeltingBuilder.buildAndRegister();
if (!hasHotIngot) {
BlastRecipeBuilder nuggetSmeltingBuilder = RecipeMaps.BLAST_RECIPES.recipeBuilder().input(OrePrefix.dustTiny, material).outputs(nuggetStack).blastFurnaceTemp(metalMaterial.blastFurnaceTemperature).duration(Math.max(1, duration / 9)).EUt(120);
if (circuitRequiringMaterials.contains(material)) {
nuggetSmeltingBuilder.notConsumable(IntCircuitIngredient.getIntegratedCircuit(0));
}
nuggetSmeltingBuilder.buildAndRegister();
}
if (hasHotIngot) {
RecipeMaps.VACUUM_RECIPES.recipeBuilder().input(OrePrefix.ingotHot, metalMaterial).outputs(OreDictUnifier.get(OrePrefix.ingot, metalMaterial)).duration(metalMaterial.blastFurnaceTemperature / 16).buildAndRegister();
}
if (metalMaterial.blastFurnaceTemperature <= 1000) {
ModHandler.addRCFurnaceRecipe(new UnificationEntry(dustPrefix, metalMaterial), ingotStack, duration);
ModHandler.addRCFurnaceRecipe(new UnificationEntry(OrePrefix.nugget, metalMaterial), nuggetStack, Math.max(1, duration / 9));
}
}
}
} else if (material.hasFlag(MatFlags.GENERATE_PLATE) && !material.hasFlag(EXCLUDE_PLATE_COMPRESSOR_RECIPE)) {
RecipeMaps.COMPRESSOR_RECIPES.recipeBuilder().input(dustPrefix, material).outputs(OreDictUnifier.get(OrePrefix.plate, material)).buildAndRegister();
}
}
use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.
the class MaterialRecipeHandler method processTinyDust.
public static void processTinyDust(OrePrefix orePrefix, DustMaterial material) {
ItemStack tinyDustStack = OreDictUnifier.get(orePrefix, material);
ItemStack dustStack = OreDictUnifier.get(OrePrefix.dust, material);
ModHandler.addShapedRecipe(String.format("tiny_dust_disassembling_%s", material.toString()), GTUtility.copyAmount(9, tinyDustStack), "X ", " ", 'X', new UnificationEntry(OrePrefix.dust, material));
ModHandler.addShapedRecipe(String.format("tiny_dust_assembling_%s", material.toString()), dustStack, "XXX", "XXX", "XXX", 'X', new UnificationEntry(orePrefix, material));
RecipeMaps.PACKER_RECIPES.recipeBuilder().input(orePrefix, material, 9).inputs(new CountableIngredient(new IntCircuitIngredient(1), 0)).outputs(dustStack).buildAndRegister();
RecipeMaps.UNPACKER_RECIPES.recipeBuilder().input(OrePrefix.dust, material).inputs(new CountableIngredient(new IntCircuitIngredient(1), 0)).outputs(GTUtility.copyAmount(9, tinyDustStack)).buildAndRegister();
}
use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.
the class RecipeMapBrewer method findRecipe.
@Nullable
@Override
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, MatchingMode mode) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, mode);
if (recipe != null || GTUtility.amountOfNonNullElements(fluidInputs) < 1 || GTUtility.amountOfNonEmptyStacks(inputs) < 1) {
return recipe;
}
ItemStack ingredientStack = inputs.get(0);
FluidStack potionFluid = fluidInputs.get(0);
PotionType potionType = PotionFluids.getPotionForFluid(potionFluid.getFluid());
if (potionType == null || potionFluid.amount < POTION_PER_INGREDIENT) {
// do not return recipes if not enough fluid or fluid doesn't match
return null;
}
ItemStack potionStack = new ItemStack(Items.POTIONITEM);
PotionUtils.addPotionToItemStack(potionStack, potionType);
ItemStack resultStack = BrewingRecipeRegistry.getOutput(potionStack, ingredientStack);
if (resultStack.isEmpty() || resultStack.getItem() != Items.POTIONITEM) {
// if no recipe matches, or output is not a simple potion, return null
return null;
}
PotionType resultingType = PotionUtils.getPotionFromItem(resultStack);
if (resultingType == null || resultingType == PotionTypes.EMPTY) {
// if output is not a simple potion or empty potion, return null
return null;
}
Fluid outputFluid = PotionFluids.getFluidForPotion(resultingType);
if (outputFluid == null) {
return null;
}
// otherwise, return recipe for fluid potion + ingredient -> new fluid potion
return recipeBuilder().inputs(// we can reuse recipe only if ingredient fully matches,
new CountableIngredient(new NBTIngredient(ingredientStack), 1)).fluidInputs(GTUtility.copyAmount(POTION_PER_INGREDIENT, potionFluid)).fluidOutputs(new FluidStack(outputFluid, POTION_PER_INGREDIENT)).build().getResult();
}
use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.
the class RecipeMapFluidCanner method findRecipe.
@Override
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, MatchingMode mode) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, mode);
if (inputs.size() == 0 || inputs.get(0).isEmpty() || recipe != null)
return recipe;
// Fail early if input isn't a fluid container
if (!inputs.get(0).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null))
return null;
// Make a copy to use for creating recipes
ItemStack inputStack = inputs.get(0).copy();
inputStack.setCount(1);
// Make another copy to use for draining and filling
ItemStack fluidHandlerItemStack = inputStack.copy();
IFluidHandlerItem fluidHandlerItem = fluidHandlerItemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (fluidHandlerItem == null)
return null;
FluidStack containerFluid = fluidHandlerItem.drain(Integer.MAX_VALUE, true);
if (containerFluid != null) {
// if we actually drained something, then it's draining recipe
return recipeBuilder().inputs(new CountableIngredient(new NBTIngredient(inputStack), 1)).outputs(fluidHandlerItem.getContainer()).fluidOutputs(containerFluid).duration(Math.max(16, containerFluid.amount / 64)).EUt(4).build().getResult();
}
// if we didn't drain anything, try filling container
if (!fluidInputs.isEmpty() && fluidInputs.get(0) != null) {
FluidStack inputFluid = fluidInputs.get(0).copy();
inputFluid.amount = fluidHandlerItem.fill(inputFluid, true);
if (inputFluid.amount > 0) {
return recipeBuilder().inputs(new CountableIngredient(new NBTIngredient(inputStack), 1)).fluidInputs(inputFluid).outputs(fluidHandlerItem.getContainer()).duration(Math.max(16, inputFluid.amount / 64)).EUt(4).build().getResult();
}
}
return null;
}
Aggregations