use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class ToolUtility method applyHammerDrops.
public static void applyHammerDrops(Random random, IBlockState blockState, List<ItemStack> drops, int fortuneLevel, EntityPlayer player) {
ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().getMetaFromState(blockState));
Recipe recipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
if (recipe != null && !recipe.getOutputs().isEmpty()) {
drops.clear();
for (ItemStack outputStack : recipe.getResultItemOutputs(Integer.MAX_VALUE, random, 0)) {
outputStack = outputStack.copy();
if (!(player instanceof FakePlayer) && OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) {
int growAmount = Math.round(outputStack.getCount() * random.nextFloat());
if (fortuneLevel > 0) {
int i = Math.max(0, random.nextInt(fortuneLevel + 2) - 1);
growAmount += outputStack.getCount() * i;
}
outputStack.grow(growAmount);
}
drops.add(outputStack);
}
}
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class WorkableTieredMetaTileEntity method canInputFluid.
protected boolean canInputFluid(FluidStack inputFluid) {
RecipeMap<?> recipeMap = workable.recipeMap;
if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
// if recipe map forces input of given fluid, return true
return true;
Set<Recipe> matchingRecipes = null;
for (IFluidTank fluidTank : importFluids) {
FluidStack fluidInTank = fluidTank.getFluid();
if (fluidInTank != null) {
if (matchingRecipes == null) {
// if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
} else {
// else, remove recipes that don't contain fluid in this tank from list
matchingRecipes.removeIf(recipe -> !recipe.hasInputFluid(fluidInTank));
}
}
}
if (matchingRecipes == null) {
// if all tanks are empty, generally fluid can be inserted if there are recipes for it
return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
} else {
// otherwise, we can insert fluid only if one of recipes accept it as input
return matchingRecipes.stream().anyMatch(recipe -> recipe.hasInputFluid(inputFluid));
}
}
use of gregtech.api.recipes.Recipe in project GregTech by GregTechCE.
the class MetaTileEntityMacerator method createWorkable.
@Override
protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
final RecipeLogicEnergy result = new RecipeLogicEnergy(this, recipeMap, () -> energyContainer) {
@Override
protected int getMachineTierForRecipe(Recipe recipe) {
int tier = GTUtility.getTierByVoltage(getMaxVoltage());
if (tier > GTValues.MV) {
return tier - GTValues.MV;
}
return 0;
}
};
result.enableOverclockVoltage();
return result;
}
Aggregations