mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 10:55:06 +00:00
refactor 6
This commit is contained in:
1 parent
5b62c4fdc8
commit
8d072f0c89
78 files changed
+525
-882
No files matched your search
+3
-11
@@ -4,8 +4,7 @@ import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx;
|
||||
import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import com.glodblock.github.nei.recipes.FluidRecipe;
|
||||
import com.glodblock.github.network.CPacketTransferRecipe;
|
||||
@@ -29,11 +28,8 @@ public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandle
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if (isCorrectGui(firstGui)) {
|
||||
boolean priority = false;
|
||||
if (firstGui instanceof GuiFluidPatternTerminalEx) {
|
||||
priority = ((GuiFluidPatternTerminalEx) firstGui).container.prioritize;
|
||||
}
|
||||
if (firstGui instanceof FCGuiEncodeTerminal) {
|
||||
boolean priority = ((FCGuiEncodeTerminal) firstGui).container.prioritize;
|
||||
List<OrderStack<?>> in = FluidRecipe.getPackageInputs(recipe, recipeIndex, priority);
|
||||
List<OrderStack<?>> out = FluidRecipe.getPackageOutputs(recipe, recipeIndex, !notUseOther(recipe));
|
||||
boolean craft = shouldCraft(recipe);
|
||||
@@ -41,10 +37,6 @@ public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandle
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCorrectGui(GuiContainer firstGui) {
|
||||
return firstGui instanceof GuiFluidPatternTerminal || firstGui instanceof GuiFluidPatternTerminalEx;
|
||||
}
|
||||
|
||||
private boolean notUseOther(IRecipeHandler recipeHandler) {
|
||||
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipeHandler;
|
||||
return notOtherSet.contains(tRecipe.getOverlayIdentifier());
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.glodblock.github.nei.object;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface IFluidDummy {
|
||||
|
||||
FluidStack getFluidStack();
|
||||
}
|
||||
@@ -38,12 +38,12 @@ public final class FluidRecipe {
|
||||
byte numFluids = 0;
|
||||
for (OrderStack<?> orderStack : out) {
|
||||
if (orderStack != null && orderStack.getStack() instanceof FluidStack) {
|
||||
reordered.add(new OrderStack(orderStack.getStack(), numFluids++));
|
||||
reordered.add(new OrderStack<>(orderStack.getStack(), numFluids++));
|
||||
}
|
||||
}
|
||||
for (OrderStack<?> orderStack : out) {
|
||||
if (orderStack != null && orderStack.getStack() instanceof ItemStack) {
|
||||
reordered.add(new OrderStack(orderStack.getStack(), numFluids++));
|
||||
reordered.add(new OrderStack<>(orderStack.getStack(), numFluids++));
|
||||
}
|
||||
}
|
||||
return reordered;
|
||||
|
||||
+4
-20
@@ -20,38 +20,22 @@ public class EnderIORecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawInputs.size(); i++) {
|
||||
if (rawInputs.get(i) == null) continue;
|
||||
OrderStack<?> stack = OrderStack.pack(rawInputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawInputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
OrderStack<?> stack = OrderStack.pack(rawOutputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawOutputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
|
||||
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
List<OrderStack<?>> tmp;
|
||||
if (tRecipe.arecipes.get(index) instanceof VatRecipeHandler.InnerVatRecipe) {
|
||||
VatRecipeHandler.InnerVatRecipe vatRecipe = (VatRecipeHandler.InnerVatRecipe) tRecipe.arecipes.get(index);
|
||||
ArrayList<PositionedStack> inputs = ReflectEIO.getInputs(vatRecipe);
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
if (inputs.get(i) == null) continue;
|
||||
OrderStack<?> stack = OrderStack.pack(rawInputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
tmp = ExtractorUtil.packItemStack(inputs);
|
||||
FluidStack in = ReflectEIO.getInputFluid(vatRecipe);
|
||||
if (in != null) {
|
||||
tmp.add(new OrderStack<>(in, inputs.size()));
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.glodblock.github.nei.recipes.extractor;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ExtractorUtil {
|
||||
|
||||
public static List<OrderStack<?>> packItemStack(List<PositionedStack> items) {
|
||||
AtomicInteger index = new AtomicInteger(-1);
|
||||
return items.stream()
|
||||
.map(item -> {
|
||||
index.getAndIncrement();
|
||||
return OrderStack.pack(item, index.get());
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<OrderStack<?>> packItemStack(
|
||||
List<PositionedStack> items, Function<PositionedStack, Object> transformer) {
|
||||
AtomicInteger index = new AtomicInteger(-1);
|
||||
return items.stream()
|
||||
.map(item -> {
|
||||
index.getAndIncrement();
|
||||
Object o = transformer.apply(item);
|
||||
return o != null ? new OrderStack<>(o, index.get()) : null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+2
-15
@@ -10,7 +10,6 @@ import forestry.core.recipes.nei.RecipeHandlerBase;
|
||||
import forestry.factory.recipes.nei.NEIHandlerFabricator;
|
||||
import forestry.factory.recipes.nei.NEIHandlerSqueezer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -29,24 +28,12 @@ public class ForestryRecipeExtractor implements IRecipeExtractorLegacy {
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawInputs.size(); i++) {
|
||||
if (rawInputs.get(i) == null) continue;
|
||||
OrderStack<?> stack = OrderStack.pack(rawInputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawInputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
OrderStack<?> stack = OrderStack.pack(rawOutputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawOutputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,8 +5,4 @@ public class GTPPRecipeExtractor extends GregTech5RecipeExtractor {
|
||||
public GTPPRecipeExtractor() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
public GTPPRecipeExtractor(boolean removeSpecial) {
|
||||
super(removeSpecial);
|
||||
}
|
||||
}
|
||||
+19
-36
@@ -5,10 +5,9 @@ import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import gregtech.api.enums.ItemList;
|
||||
import gregtech.common.items.GT_FluidDisplayItem;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -23,44 +22,12 @@ public class GregTech5RecipeExtractor implements IRecipeExtractor {
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
if (removeSpecial) removeSpecial(rawInputs);
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawInputs.size(); i++) {
|
||||
if (rawInputs.get(i) == null) continue;
|
||||
ItemStack item = rawInputs.get(i).items[0].copy();
|
||||
OrderStack<?> stack;
|
||||
if (item.getItem() instanceof GT_FluidDisplayItem) {
|
||||
NBTTagCompound aNBT = item.getTagCompound();
|
||||
int amt = (int) aNBT.getLong("mFluidDisplayAmount");
|
||||
if (amt <= 0) continue;
|
||||
stack = new OrderStack<>(new FluidStack(FluidRegistry.getFluid(item.getItemDamage()), amt), i);
|
||||
tmp.add(stack);
|
||||
} else {
|
||||
stack = OrderStack.pack(rawInputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawInputs, GregTech5RecipeExtractor::getFluidFromDisplay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
ItemStack item = rawOutputs.get(i).items[0].copy();
|
||||
OrderStack<?> stack;
|
||||
if (item.getItem() instanceof GT_FluidDisplayItem) {
|
||||
NBTTagCompound aNBT = item.getTagCompound();
|
||||
int amt = (int) aNBT.getLong("mFluidDisplayAmount");
|
||||
if (amt <= 0) continue;
|
||||
stack = new OrderStack<>(new FluidStack(FluidRegistry.getFluid(item.getItemDamage()), amt), i);
|
||||
tmp.add(stack);
|
||||
} else {
|
||||
stack = OrderStack.pack(rawOutputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawOutputs, GregTech5RecipeExtractor::getFluidFromDisplay);
|
||||
}
|
||||
|
||||
private void removeSpecial(List<PositionedStack> list) {
|
||||
@@ -74,4 +41,20 @@ public class GregTech5RecipeExtractor implements IRecipeExtractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFluidFromDisplay(PositionedStack stack) {
|
||||
if (stack != null) {
|
||||
ItemStack item = stack.items[0].copy();
|
||||
if (item.getItem() instanceof GT_FluidDisplayItem) {
|
||||
if (item.getTagCompound() != null) {
|
||||
Fluid fluid = FluidRegistry.getFluid(item.getItemDamage());
|
||||
int amt = (int) item.getTagCompound().getLong("mFluidDisplayAmount");
|
||||
return amt > 0 && fluid != null ? new FluidStack(fluid, amt) : null;
|
||||
}
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+17
-33
@@ -5,7 +5,6 @@ import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import gregapi.item.ItemFluidDisplay;
|
||||
import gregapi.recipes.Recipe;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -21,42 +20,12 @@ public class GregTech6RecipeExtractor implements IRecipeExtractor {
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
this.removeMachine(rawInputs);
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawInputs.size(); i++) {
|
||||
if (rawInputs.get(i) == null) continue;
|
||||
ItemStack item = rawInputs.get(i).items[0].copy();
|
||||
OrderStack<?> stack;
|
||||
if (item.getItem() instanceof ItemFluidDisplay) {
|
||||
FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item);
|
||||
if (fluid == null || fluid.amount <= 0) continue;
|
||||
stack = new OrderStack<>(fluid, i);
|
||||
tmp.add(stack);
|
||||
} else {
|
||||
stack = OrderStack.pack(rawInputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawInputs, GregTech6RecipeExtractor::getFluidFromDisplay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
ItemStack item = rawOutputs.get(i).items[0].copy();
|
||||
OrderStack<?> stack;
|
||||
if (item.getItem() instanceof ItemFluidDisplay) {
|
||||
FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item);
|
||||
if (fluid == null || fluid.amount <= 0) continue;
|
||||
stack = new OrderStack<>(fluid, i);
|
||||
tmp.add(stack);
|
||||
} else {
|
||||
stack = OrderStack.pack(rawOutputs.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawOutputs, GregTech6RecipeExtractor::getFluidFromDisplay);
|
||||
}
|
||||
|
||||
private void removeMachine(List<PositionedStack> list) {
|
||||
@@ -72,4 +41,19 @@ public class GregTech6RecipeExtractor implements IRecipeExtractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFluidFromDisplay(PositionedStack stack) {
|
||||
if (stack != null) {
|
||||
ItemStack item = stack.items[0].copy();
|
||||
if (item.getItem() instanceof ItemFluidDisplay) {
|
||||
if (item.getTagCompound() != null) {
|
||||
FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item);
|
||||
return fluid != null && fluid.amount > 0 ? fluid : null;
|
||||
}
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
-12
@@ -20,22 +20,12 @@ public class IndustrialCraftRecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawInputs.size(); i++) {
|
||||
if (rawInputs.get(i) == null) continue;
|
||||
tmp.add(OrderStack.pack(rawInputs.get(i), i));
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawInputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
tmp.add(OrderStack.pack(rawOutputs.get(i), i));
|
||||
}
|
||||
return tmp;
|
||||
return ExtractorUtil.packItemStack(rawOutputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-10
@@ -30,15 +30,6 @@ public class VanillaRecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < rawOutputs.size(); i++) {
|
||||
if (rawOutputs.get(i) == null) continue;
|
||||
final int col = (rawOutputs.get(i).relx - 25) / 18;
|
||||
final int row = (rawOutputs.get(i).rely - 6) / 18;
|
||||
int index = col + row * 3;
|
||||
OrderStack<?> stack = OrderStack.pack(rawOutputs.get(i), c ? index : i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
return getInputIngredients(rawOutputs);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user