mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 18:44:42 +00:00
begin work
This commit is contained in:
commit
db2ad29b52
124 files changed
+11799
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package com.glodblock.github.nei;
|
||||
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminal;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import com.glodblock.github.nei.recipes.FluidRecipe;
|
||||
import com.glodblock.github.network.CPacketTransferRecipe;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandler {
|
||||
|
||||
public static final FluidPatternTerminalRecipeTransferHandler INSTANCE = new FluidPatternTerminalRecipeTransferHandler();
|
||||
public static final HashSet<String> notOtherSet = new HashSet<>();
|
||||
public static final HashSet<String> craftSet = new HashSet<>();
|
||||
|
||||
static {
|
||||
notOtherSet.add("smelting");
|
||||
notOtherSet.add("brewing");
|
||||
craftSet.add("crafting");
|
||||
craftSet.add("crafting2x2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if (isCorrectGui(firstGui)) {
|
||||
List<OrderStack<?>> in = FluidRecipe.getPackageInputs(recipe, recipeIndex);
|
||||
List<OrderStack<?>> out = FluidRecipe.getPackageOutputs(recipe, recipeIndex, !notUseOther(recipe));
|
||||
boolean craft = shouldCraft(recipe);
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketTransferRecipe(in, out, craft));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCorrectGui(GuiContainer firstGui) {
|
||||
return firstGui instanceof GuiFluidPatternTerminal;
|
||||
}
|
||||
|
||||
private boolean notUseOther(IRecipeHandler recipeHandler) {
|
||||
return notOtherSet.contains(recipeHandler.getOverlayIdentifier());
|
||||
}
|
||||
|
||||
private boolean shouldCraft(IRecipeHandler recipeHandler) {
|
||||
return craftSet.contains(recipeHandler.getOverlayIdentifier());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.glodblock.github.nei;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminal;
|
||||
import com.glodblock.github.nei.recipes.FluidRecipe;
|
||||
|
||||
public class NEI_FC_Config implements IConfigureNEI {
|
||||
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
for (String identifier : FluidRecipe.getSupportRecipes()) {
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternTerminal.class, FluidPatternTerminalRecipeTransferHandler.INSTANCE, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return FluidCraft.MODNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return FluidCraft.VERSION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.glodblock.github.nei.object;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface IFluidDummy {
|
||||
|
||||
FluidStack getFluidStack();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.glodblock.github.nei.object;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IRecipeExtractor {
|
||||
|
||||
List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs);
|
||||
|
||||
List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.glodblock.github.nei.object;
|
||||
|
||||
public class IllegalOrderStackID extends RuntimeException {
|
||||
|
||||
public IllegalOrderStackID(int id) {
|
||||
super("Illegal type id: " + id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.glodblock.github.nei.object;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.glodblock.github.util.Util;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class OrderStack<T> {
|
||||
|
||||
private final T RealStack;
|
||||
private final int index;
|
||||
|
||||
public final static int ITEM = 1;
|
||||
public final static int FLUID = 2;
|
||||
public final static int CUSTOM = 3;
|
||||
|
||||
public OrderStack(T stack, int order) {
|
||||
if (stack == null || order < 0)
|
||||
throw new IllegalArgumentException("Trying to create a null or negative order stack!");
|
||||
this.RealStack = stack;
|
||||
this.index = order;
|
||||
}
|
||||
|
||||
public T getStack() {
|
||||
return RealStack;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public static OrderStack<ItemStack> pack(PositionedStack stack, int index) {
|
||||
if (stack != null && stack.items != null && stack.items.length > 0) {
|
||||
if (Items.feather.getDamage(stack.items[0]) == OreDictionary.WILDCARD_VALUE) {
|
||||
ItemStack tmp = stack.items[0].copy();
|
||||
tmp.setItemDamage(0);
|
||||
return new OrderStack<>(tmp, index);
|
||||
}
|
||||
else return new OrderStack<>(stack.items[0].copy(), index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static OrderStack<?> packFluid(PositionedStack stack, int index) {
|
||||
if (stack != null && stack.items != null && stack.items.length > 0) {
|
||||
FluidStack fluid = Util.getFluidFromItem(stack.items[0]);
|
||||
if (fluid != null) return new OrderStack<>(fluid.copy(), index);
|
||||
else return pack(stack, index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void customNBTWriter(NBTTagCompound buf) {
|
||||
}
|
||||
|
||||
protected T customNBTReader(NBTTagCompound buf) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final void writeToNBT(NBTTagCompound buf) {
|
||||
if (RealStack instanceof ItemStack) {
|
||||
NBTTagCompound tmp = new NBTTagCompound();
|
||||
tmp.setByte("t", (byte) ITEM);
|
||||
((ItemStack) RealStack).writeToNBT(tmp);
|
||||
buf.setTag(index + ":", tmp);
|
||||
}
|
||||
else if (RealStack instanceof FluidStack) {
|
||||
NBTTagCompound tmp = new NBTTagCompound();
|
||||
tmp.setByte("t", (byte) FLUID);
|
||||
((FluidStack) RealStack).writeToNBT(tmp);
|
||||
buf.setTag(index + ":", tmp);
|
||||
}
|
||||
else {
|
||||
NBTTagCompound tmp = new NBTTagCompound();
|
||||
tmp.setByte("t", (byte) CUSTOM);
|
||||
customNBTWriter(tmp);
|
||||
buf.setTag(index + ":", tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public static OrderStack<?> readFromNBT(NBTTagCompound buf, @Nullable OrderStack<?> dummy, int index) {
|
||||
if (!buf.hasKey(index + ":")) return null;
|
||||
NBTTagCompound info = buf.getCompoundTag(index + ":");
|
||||
byte id = info.getByte("t");
|
||||
switch (id) {
|
||||
case ITEM:
|
||||
return new OrderStack<>(ItemStack.loadItemStackFromNBT(info), index);
|
||||
case FLUID:
|
||||
return new OrderStack<>(FluidStack.loadFluidStackFromNBT(info), index);
|
||||
case CUSTOM:
|
||||
if (dummy == null) throw new IllegalOrderStackID(id);
|
||||
return new OrderStack<>(dummy.customNBTReader(buf), index);
|
||||
default:
|
||||
throw new IllegalOrderStackID(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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