use of gregtech.integration.jei.recipe.GTRecipeWrapper in project GregTech by GregTechCEu.
the class RGNode method transferRecipe.
public boolean transferRecipe(ModularUIContainer x, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
if (isSelected) {
Object obj = recipeLayout.getFocus() == null ? null : recipeLayout.getFocus().getValue();
if (head instanceof ItemStack && obj instanceof ItemStack) {
if (!((ItemStack) head).isItemEqual((ItemStack) obj)) {
return false;
}
} else if (head instanceof FluidStack && obj instanceof FluidStack) {
if (!((FluidStack) head).isFluidEqual((FluidStack) obj)) {
return false;
}
} else {
return false;
}
if (!doTransfer)
return true;
RGNode.this.recipePer = 0;
// items
List<ItemStack> itemInputs = new ArrayList<>();
recipeLayout.getItemStacks().getGuiIngredients().values().forEach(it -> {
if (it.isInput() && it.getDisplayedIngredient() != null) {
ItemStack input = it.getDisplayedIngredient();
for (ItemStack itemInput : itemInputs) {
if (itemInput.isItemEqual(input)) {
itemInput.setCount(itemInput.getCount() + input.getCount());
return;
}
}
itemInputs.add(input.copy());
} else if (head instanceof ItemStack && !it.isInput()) {
for (ItemStack ingredient : it.getAllIngredients()) {
if (((ItemStack) head).isItemEqual(ingredient)) {
RGNode.this.recipePer += ingredient.getCount();
break;
}
}
}
});
// fluids
List<FluidStack> fluidInputs = new ArrayList<>();
recipeLayout.getFluidStacks().getGuiIngredients().values().forEach(it -> {
if (it.isInput() && it.getDisplayedIngredient() != null) {
FluidStack input = it.getDisplayedIngredient();
for (FluidStack fluidInput : fluidInputs) {
if (fluidInput.isFluidEqual(input)) {
fluidInput.amount += input.amount;
return;
}
}
fluidInputs.add(input.copy());
} else if (head instanceof FluidStack && !it.isInput()) {
for (FluidStack ingredient : it.getAllIngredients()) {
if (((FluidStack) head).isFluidEqual(ingredient)) {
RGNode.this.recipePer += ingredient.amount;
break;
}
}
}
});
// CHECK GTCE RECIPES
Recipe recipe = null;
if (recipeLayout instanceof RecipeLayout) {
IRecipeWrapper recipeWrapper = ObfuscationReflectionHelper.getPrivateValue(RecipeLayout.class, (RecipeLayout) recipeLayout, "recipeWrapper");
if (recipeWrapper instanceof GTRecipeWrapper) {
recipe = ((GTRecipeWrapper) recipeWrapper).getRecipe();
}
}
IRecipeCategory<?> category = recipeLayout.getRecipeCategory();
List<Object> catalysts = GTJeiPlugin.jeiRuntime.getRecipeRegistry().getRecipeCatalysts(category);
ItemStack catalyst = null;
if (recipe != null) {
// GT
int tierRequire = GTUtility.getTierByVoltage(recipe.getEUt());
for (Object o : catalysts) {
if (o instanceof ItemStack) {
MetaTileEntity mte = MachineItemBlock.getMetaTileEntity((ItemStack) o);
if (mte instanceof SimpleMachineMetaTileEntity) {
if (tierRequire < ((SimpleMachineMetaTileEntity) mte).getTier()) {
catalyst = (ItemStack) o;
break;
}
}
}
}
}
if (catalyst == null) {
for (Object o : catalysts) {
if (o instanceof ItemStack) {
catalyst = (ItemStack) o;
break;
}
}
}
setRecipe(itemInputs, fluidInputs, catalyst, recipePer);
return true;
}
return false;
}
Aggregations