Skip to content
Permalink
Browse files

Reduce itemstack copies in BottlerRecipeCategory (#2383)

* get rid of some unnecessary itemstack copies in BottlerRecipeMaker

* rename some methods for clarity
  • Loading branch information
temp1011 authored and Nedelosk committed Mar 5, 2019
1 parent 013f7f1 commit ee973829bea80e6cb1ea5385762dfdfe52a258b7
Showing with 14 additions and 15 deletions.
  1. +14 −15 src/main/java/forestry/factory/recipes/jei/bottler/BottlerRecipeMaker.java
@@ -14,6 +14,7 @@
import net.minecraftforge.fluids.capability.IFluidTankProperties;

import mezz.jei.api.ingredients.IIngredientRegistry;
import mezz.jei.api.ingredients.VanillaTypes;

public class BottlerRecipeMaker {

@@ -22,33 +23,31 @@ private BottlerRecipeMaker() {

public static List<BottlerRecipeWrapper> getBottlerRecipes(IIngredientRegistry ingredientRegistry) {
List<BottlerRecipeWrapper> recipes = new ArrayList<>();
for (ItemStack stack : ingredientRegistry.getAllIngredients(ItemStack.class)) {
for (ItemStack stack : ingredientRegistry.getAllIngredients(VanillaTypes.ITEM)) {
if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
IFluidHandlerItem fluidHandler = stack.copy().getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (fluidHandler != null) {
final boolean canDrain = canDrain(fluidHandler);
final boolean canFill = canFill(fluidHandler);

if (canDrain) {
if (hasDrainProperty(fluidHandler)) {
FluidStack drainedFluid = fluidHandler.drain(Integer.MAX_VALUE, true);
if (drainedFluid != null) {
ItemStack drained = fluidHandler.getContainer();
recipes.add(new BottlerRecipeWrapper(stack, drainedFluid, drained, false));
}
}

if (canFill) {
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
IFluidHandlerItem fillingCapability = stack.copy().getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (fillingCapability != null) {
int fill = fillingCapability.fill(new FluidStack(fluid, Integer.MAX_VALUE), true);
if (fill > 0) {
if (hasFillProperty(fluidHandler)) {
IFluidHandlerItem fillingCapability = stack.copy().getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (fillingCapability != null) {
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
int testFill = fillingCapability.fill(new FluidStack(fluid, Integer.MAX_VALUE), false); //try to reduce itemstack copies
if (testFill > 0) {
IFluidHandlerItem copiedCap = stack.copy().getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
int fill = copiedCap.fill(new FluidStack(fluid, Integer.MAX_VALUE), true);
FluidStack filledFluid = new FluidStack(fluid, fill);
ItemStack filled = fillingCapability.getContainer();
ItemStack filled = copiedCap.getContainer();
recipes.add(new BottlerRecipeWrapper(stack, filledFluid, filled, true));
}
} else {
break;
}
}
}
@@ -58,7 +57,7 @@ private BottlerRecipeMaker() {
return recipes;
}

private static boolean canDrain(IFluidHandler fluidHandler) {
private static boolean hasDrainProperty(IFluidHandler fluidHandler) {
for (IFluidTankProperties properties : fluidHandler.getTankProperties()) {
if (properties.canDrain()) {
return true;
@@ -67,7 +66,7 @@ private static boolean canDrain(IFluidHandler fluidHandler) {
return false;
}

private static boolean canFill(IFluidHandler fluidHandler) {
private static boolean hasFillProperty(IFluidHandler fluidHandler) {
for (IFluidTankProperties properties : fluidHandler.getTankProperties()) {
if (properties.canFill()) {
return true;

0 comments on commit ee97382

Please sign in to comment.
You can’t perform that action at this time.