use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class RecipeMapWorkableHandler method update.
@Override
public void update() {
if (getMetaTileEntity().getWorld().isRemote)
return;
if (progressTime == 0) {
long maxVoltage = getMaxVoltage();
Recipe pickedRecipe = recipeMap.findRecipe(previousRecipe, maxVoltage, metaTileEntity.getImportItems(), metaTileEntity.getImportFluids());
if (pickedRecipe != null && setupAndConsumeRecipeInputs(pickedRecipe)) {
if (pickedRecipe.canBeBuffered()) {
this.previousRecipe = pickedRecipe;
} else
this.previousRecipe = null;
setupRecipe(pickedRecipe);
}
} else if (workingEnabled) {
if (drawEnergy(recipeEUt)) {
if (++progressTime >= maxProgressTime) {
completeRecipe();
}
}
}
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class RecipeMapFormingPress method findRecipe.
@Override
@Nullable
public Recipe findRecipe(long voltage, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs);
if (inputs.size() < 2 || inputs.get(0).isEmpty() || inputs.get(1).isEmpty())
return recipe;
if (recipe == null) {
if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(inputs.get(0))) {
ItemStack output = GTUtility.copyAmount(1, inputs.get(1));
output.setStackDisplayName(inputs.get(0).getDisplayName());
return this.recipeBuilder().cannotBeBuffered().notOptimized().notConsumable(MetaItems.SHAPE_MOLD_NAME).inputs(GTUtility.copyAmount(1, inputs.get(1))).outputs(output).duration(128).EUt(8).build().getResult();
}
if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(inputs.get(1))) {
ItemStack output = GTUtility.copyAmount(1, inputs.get(0));
output.setStackDisplayName(inputs.get(1).getDisplayName());
return this.recipeBuilder().cannotBeBuffered().notOptimized().notConsumable(MetaItems.SHAPE_MOLD_NAME).inputs(GTUtility.copyAmount(1, inputs.get(0))).outputs(output).duration(128).EUt(8).build().getResult();
}
return null;
}
for (ItemStack mold : inputs) {
if (MetaItems.SCHEMATIC_CRAFTING.getStackForm().isItemEqual(mold)) {
NBTTagCompound tag = mold.getTagCompound();
if (tag == null)
tag = new NBTTagCompound();
if (!tag.hasKey("credit_security_id"))
tag.setLong("credit_security_id", System.nanoTime());
mold.setTagCompound(tag);
RecipeBuilder<?> builder = this.recipeBuilder().fromRecipe(recipe).cannotBeBuffered();
List<ItemStack> outputs = builder.getOutputs();
ItemStack stack = outputs.get(0);
stack.setTagCompound(tag);
outputs.set(0, stack);
return builder.build().getResult();
}
}
return recipe;
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class RecipeMapPrinter method findRecipe.
@Override
@Nullable
public Recipe findRecipe(long voltage, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs);
if (recipe != null || inputs.size() == 0 || inputs.get(0).isEmpty())
return recipe;
ItemStack firstInputItem = inputs.get(0);
if (fluidInputs.size() != 0 && fluidInputs.get(0) != null) {
FluidStack fluidStack = fluidInputs.get(0);
EnumDyeColor dyeColor = GregTechAPI.LIQUID_DYE_MAP.get(fluidStack.getFluid());
if (dyeColor != null && fluidStack.amount >= GTValues.L) {
ItemStack dyeItemStack = new ItemStack(Items.DYE, 1, dyeColor.getDyeDamage());
ItemStack colouredItem = ModHandler.getRecipeOutput(null, dyeItemStack, firstInputItem);
if (colouredItem.isEmpty())
return null;
return recipeBuilder().inputs(GTUtility.copyAmount(1, firstInputItem)).fluidInputs(GTUtility.copyAmount(GTValues.L, fluidStack)).outputs(colouredItem).EUt(2).duration(32).build().getResult();
}
}
return null;
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class AbstractRecipeLogic method trySearchNewRecipe.
protected void trySearchNewRecipe() {
long maxVoltage = getMaxVoltage();
Recipe currentRecipe = null;
IItemHandlerModifiable importInventory = getInputInventory();
IMultipleTankHandler importFluids = getInputTank();
if (previousRecipe != null && previousRecipe.matches(false, importInventory, importFluids)) {
// if previous recipe still matches inputs, try to use it
currentRecipe = previousRecipe;
} else {
boolean dirty = checkRecipeInputsDirty(importInventory, importFluids);
if (dirty || forceRecipeRecheck) {
this.forceRecipeRecheck = false;
// else, try searching new recipe for given inputs
currentRecipe = findRecipe(maxVoltage, importInventory, importFluids);
if (currentRecipe != null) {
this.previousRecipe = currentRecipe;
}
}
}
if (currentRecipe != null && setupAndConsumeRecipeInputs(currentRecipe)) {
setupRecipe(currentRecipe);
}
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class ImplosionRecipeBuilder method build.
public ValidationResult<Recipe> build() {
// Adjust the explosive type and the explosive amount. This is done here because it was null otherwise, for some reason
int amount = Math.max(1, explosivesAmount / 2);
if (explosivesType == null) {
this.explosivesType = new ItemStack(Blocks.TNT, amount);
} else {
this.explosivesType = new ItemStack(explosivesType.getItem(), amount, explosivesType.getMetadata());
}
inputs.add(CountableIngredient.from(explosivesType));
Recipe recipe = new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs, duration, EUt, hidden);
if (!recipe.getRecipePropertyStorage().store(ImmutableMap.of(ImplosionExplosiveProperty.getInstance(), explosivesType))) {
return ValidationResult.newResult(EnumValidationResult.INVALID, recipe);
}
return ValidationResult.newResult(finalizeAndValidate(), recipe);
}
Aggregations