mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-18 11:19:23 +00:00
begin work
This commit is contained in:
commit
db2ad29b52
124 files changed
+11799
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package com.glodblock.github.nei.recipes;
|
||||
|
||||
import com.glodblock.github.nei.recipes.extractor.GregTech5RecipeExtractor;
|
||||
import com.glodblock.github.nei.recipes.extractor.VanillaRecipeExtractor;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
import gregtech.api.util.GT_Recipe;
|
||||
|
||||
public class DefaultExtractorLoader implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FluidRecipe.addRecipeMap("smelting", new VanillaRecipeExtractor(false));
|
||||
FluidRecipe.addRecipeMap("brewing", new VanillaRecipeExtractor(false));
|
||||
FluidRecipe.addRecipeMap("crafting", new VanillaRecipeExtractor(true));
|
||||
FluidRecipe.addRecipeMap("crafting2x2", new VanillaRecipeExtractor(true));
|
||||
|
||||
if (ModAndClassUtil.GT5) {
|
||||
for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) {
|
||||
FluidRecipe.addRecipeMap(tMap.mNEIName, new GregTech5RecipeExtractor(tMap.mNEIName.equals("gt.recipe.scanner") || tMap.mNEIName.equals("gt.recipe.fakeAssemblylineProcess")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.glodblock.github.nei.recipes;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class FluidRecipe {
|
||||
|
||||
private static final HashMap<String, IRecipeExtractor> IdentifierMap = new HashMap<>();
|
||||
|
||||
public static void addRecipeMap(String recipeIdentifier, IRecipeExtractor extractor) {
|
||||
IdentifierMap.put(recipeIdentifier, extractor);
|
||||
}
|
||||
|
||||
public static List<OrderStack<?>> getPackageInputs(IRecipeHandler recipe, int index) {
|
||||
if (recipe == null || !IdentifierMap.containsKey(recipe.getOverlayIdentifier())) return new ArrayList<>();
|
||||
IRecipeExtractor extractor = IdentifierMap.get(recipe.getOverlayIdentifier());
|
||||
if (extractor == null) return new ArrayList<>();
|
||||
List<PositionedStack> tmp = new ArrayList<>(recipe.getIngredientStacks(index));
|
||||
return extractor.getInputIngredients(tmp);
|
||||
}
|
||||
|
||||
public static List<OrderStack<?>> getPackageOutputs(IRecipeHandler recipe, int index, boolean useOther) {
|
||||
if (recipe == null || !IdentifierMap.containsKey(recipe.getOverlayIdentifier())) return new ArrayList<>();
|
||||
IRecipeExtractor extractor = IdentifierMap.get(recipe.getOverlayIdentifier());
|
||||
if (extractor == null) return new ArrayList<>();
|
||||
List<PositionedStack> tmp = new ArrayList<>(Collections.singleton(recipe.getResultStack(index)));
|
||||
if (useOther) tmp.addAll(recipe.getOtherStacks(index));
|
||||
return extractor.getOutputIngredients(tmp);
|
||||
}
|
||||
|
||||
public static List<String> getSupportRecipes() {
|
||||
return new ArrayList<>(IdentifierMap.keySet());
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package com.glodblock.github.nei.recipes.extractor;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import gregtech.common.items.GT_FluidDisplayItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GregTech5RecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
boolean r;
|
||||
|
||||
public GregTech5RecipeExtractor(boolean removeSpecial) {
|
||||
r = removeSpecial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
|
||||
List<PositionedStack> compressed = compress(rawInputs);
|
||||
if (r) compressed.remove(compressed.size() - 1);
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < compressed.size(); i ++) {
|
||||
if (compressed.get(i) == null) continue;
|
||||
ItemStack item = compressed.get(i).items[0];
|
||||
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(compressed.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
|
||||
List<PositionedStack> compressed = compress(rawOutputs);
|
||||
if (r) compressed.remove(compressed.size() - 1);
|
||||
List<OrderStack<?>> tmp = new LinkedList<>();
|
||||
for (int i = 0; i < compressed.size(); i ++) {
|
||||
if (compressed.get(i) == null) continue;
|
||||
ItemStack item = compressed.get(i).items[0];
|
||||
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(compressed.get(i), i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private List<PositionedStack> compress(List<PositionedStack> list) {
|
||||
List<PositionedStack> comp = new LinkedList<>();
|
||||
for (PositionedStack positionedStack : list) {
|
||||
if (positionedStack == null) continue;
|
||||
ItemStack currentStack = positionedStack.items[0];
|
||||
if (currentStack.stackSize == 0) continue;
|
||||
boolean find = false;
|
||||
for (PositionedStack storedStack : comp) {
|
||||
if (storedStack == null) continue;
|
||||
ItemStack firstStack = storedStack.items[0];
|
||||
boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack);
|
||||
if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) {
|
||||
find = true;
|
||||
storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize;
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
comp.add(positionedStack.copy());
|
||||
}
|
||||
}
|
||||
return comp.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.glodblock.github.nei.recipes.extractor;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class VanillaRecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
private boolean c;
|
||||
|
||||
public VanillaRecipeExtractor(boolean isCraft) {
|
||||
c = isCraft;
|
||||
}
|
||||
|
||||
@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;
|
||||
final int col = (rawInputs.get(i).relx - 25) / 18;
|
||||
final int row = (rawInputs.get(i).rely - 6) / 18;
|
||||
int index = col + row * 3;
|
||||
OrderStack<?> stack = OrderStack.pack(rawInputs.get(i), c ? index : i);
|
||||
if (stack != null) tmp.add(stack);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user