mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
feat: support forestry
This commit is contained in:
1 parent
f141891b3e
commit
9b36a0666b
11 files changed
+246
-20
No files matched your search
@@ -2,15 +2,15 @@
|
||||
|
||||
# Just Enough Calculation Mod
|
||||
|
||||
Hey, this is a small add on to [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) (Not Enough Items), in
|
||||
Hey, this is a small add-on to [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) (Not Enough Items), in
|
||||
order to help you calculate the amount of resources to craft a specific amount of item. .
|
||||
|
||||
This might be a little confusing, here's a example:
|
||||
This might be a little confusing, here's an example:
|
||||
|
||||
- you want to know how many wood log do you need to craft 40 stairs, simply load the recipe you want to use and it will
|
||||
- you want to know how many wood logs do you need to craft 40 stairs, simply load the recipe you want to use, and it will
|
||||
tell you 13 logs should be enough, that's all.
|
||||
|
||||
This mod is focused on calculation so you might find it powerful and high performance in some complicated cases. Have fun!
|
||||
This mod is focused on calculation, so you might find it powerful and high performance in some complicated cases. Have fun!
|
||||
|
||||
For all the release files, description or videos, refer to
|
||||
the [release page](https://minecraft.curseforge.com/projects/just-enough-calculation).
|
||||
@@ -22,6 +22,9 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula
|
||||
- [ ] OreDict 识别存在问题
|
||||
- [ ] capability
|
||||
- [ ] gui 界面 z-level 过高,会遮住 nei 的各种 gui
|
||||
- [ ] 重启游戏之后 最近物品 存在问题
|
||||
- [ ] 判断 NEI 版本,适配旧版本
|
||||
|
||||
|
||||
[1]: http://cf.way2muchnoise.eu/full_just-enough-calculation_downloads.svg
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ dependencies {
|
||||
compile "codechicken:NotEnoughItems:${mc_version}-${nei_version}:universal"
|
||||
compile 'codechicken:CodeChickenLib:1.7.10-1.1.3.138:dev'
|
||||
compile 'codechicken:CodeChickenCore:1.7.10-1.0.7.+:dev'
|
||||
compile 'forestry:forestry_1.7.10-4.3.1.44'
|
||||
compile 'org.reflections:reflections:0.9.12'
|
||||
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,11 +1,13 @@
|
||||
package me.towdium.jecalculation;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.nei.Adapter;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.network.ClientHandler;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -41,6 +43,8 @@ public class JustEnoughCalculation {
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event) {
|
||||
handler.init();
|
||||
Adapter.init();
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
||||
@@ -86,7 +86,8 @@ public class JecaGui extends GuiContainer {
|
||||
*/
|
||||
public static boolean onMouse() {
|
||||
Optional<JecaGui> optionalJecaGui = currentJecaGui();
|
||||
if(!optionalJecaGui.isPresent()) return false;
|
||||
if (!optionalJecaGui.isPresent())
|
||||
return false;
|
||||
JecaGui gui = optionalJecaGui.get();
|
||||
int mouseX = getMouseX();
|
||||
int mouseY = getMouseY();
|
||||
@@ -348,7 +349,8 @@ public class JecaGui extends GuiContainer {
|
||||
|
||||
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
|
||||
IIcon fluidIcon = f.getFlowingIcon();
|
||||
if(fluidIcon == null) fluidIcon = f.getStillIcon();
|
||||
if (fluidIcon == null)
|
||||
fluidIcon = f.getStillIcon();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
setColor(f.getColor() & 0x00FFFFFF);
|
||||
if (fluidIcon != null)
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.nei.Adapter;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.CostList;
|
||||
@@ -12,7 +13,6 @@ import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -147,15 +147,15 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
ArrayList<Trio<ILabel, CostList, CostList>> output = new ArrayList<>();
|
||||
disambCache = new HashMap<>();
|
||||
|
||||
|
||||
List<Object[]> recipeInputs = new ArrayList<>();
|
||||
List<Object[]> recipeOutputs = new ArrayList<>();
|
||||
Adapter.handleRecipe(recipe, recipeIndex, recipeInputs, recipeOutputs);
|
||||
|
||||
// input
|
||||
recipe.getIngredientStacks(recipeIndex)
|
||||
.stream()
|
||||
.map((positionedStack) -> positionedStack.items)
|
||||
.forEach(i -> merge(input, Arrays.asList(i), recipe));
|
||||
recipeInputs.forEach(i -> merge(input, Arrays.asList(i), recipe));
|
||||
// output
|
||||
PositionedStack resultStack = recipe.getResultStack(recipeIndex);
|
||||
if (resultStack != null)
|
||||
merge(output, Arrays.asList(resultStack.items), recipe);
|
||||
recipeOutputs.forEach(o -> merge(output, Arrays.asList(o), recipe));
|
||||
|
||||
// catalyst. Ignore multiple catalyst
|
||||
NEIPlugin.getCatalyst(recipe)
|
||||
@@ -170,7 +170,7 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void merge(ArrayList<Trio<ILabel, CostList, CostList>> dst, List<ItemStack> gi, IRecipeHandler context) {
|
||||
private void merge(ArrayList<Trio<ILabel, CostList, CostList>> dst, List<Object> gi, IRecipeHandler context) {
|
||||
List<ILabel> list = gi.stream()
|
||||
.map(ILabel.Converter::from)
|
||||
.filter(i -> i != ILabel.EMPTY)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.nei.adapter.Forestry;
|
||||
import me.towdium.jecalculation.nei.adapter.IAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Adapter {
|
||||
public static List<IAdapter> adapters = new ArrayList<>();
|
||||
|
||||
public static void init() {
|
||||
if (Loader.isModLoaded("Forestry")) {
|
||||
JustEnoughCalculation.logger.info("Forestry is installed");
|
||||
adapters.add(new Forestry());
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
// raw inputs
|
||||
recipe.getIngredientStacks(index)
|
||||
.stream()
|
||||
.map((positionedStack) -> (Object[]) positionedStack.items)
|
||||
.forEach(inputs::add);
|
||||
|
||||
// raw outputs
|
||||
PositionedStack resultStack = recipe.getResultStack(index);
|
||||
if (resultStack != null)
|
||||
outputs.add(resultStack.items);
|
||||
|
||||
for (IAdapter adapter : adapters) {
|
||||
adapter.handleRecipe(recipe, index, inputs, outputs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
public class JecaOverlayHandler implements IOverlayHandler {
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
JustEnoughCalculation.logger.info("shift ? " + shift);
|
||||
if (shift && firstGui instanceof JecaGui) {
|
||||
if (firstGui instanceof JecaGui) {
|
||||
JecaGui gui = (JecaGui) firstGui;
|
||||
if (gui.root instanceof GuiRecipe) {
|
||||
((GuiRecipe) gui.root).transfer(recipe, recipeIndex);
|
||||
@@ -23,9 +22,6 @@ public class JecaOverlayHandler implements IOverlayHandler {
|
||||
JecaGui.displayGui(true, true, guiRecipe);
|
||||
guiRecipe.transfer(recipe, recipeIndex);
|
||||
}
|
||||
} else {
|
||||
System.out.println(firstGui.getClass().toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.towdium.jecalculation.nei.adapter;
|
||||
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@ParametersAreNonnullByDefault
|
||||
public class AdapterUtil {
|
||||
|
||||
static Optional<Class> getClass(String classPath) {
|
||||
try {
|
||||
return Optional.of(Class.forName(classPath));
|
||||
} catch (ClassNotFoundException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package me.towdium.jecalculation.nei.adapter;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import forestry.core.recipes.nei.PositionedFluidTank;
|
||||
import forestry.core.recipes.nei.RecipeHandlerBase;
|
||||
import forestry.factory.recipes.nei.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Forestry implements IAdapter {
|
||||
@Override
|
||||
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if (recipe instanceof RecipeHandlerBase) {
|
||||
RecipeHandlerBase base = (RecipeHandlerBase) recipe;
|
||||
bottler(base, index, inputs);
|
||||
carpenter(base, index, inputs);
|
||||
centrifuge(base, index, outputs);
|
||||
fabricator(base, index, inputs);
|
||||
fermenter(base, index, inputs, outputs);
|
||||
moistener(base, index, inputs, outputs);
|
||||
squeezer(base, index, inputs, outputs);
|
||||
still(base, index, inputs, outputs);
|
||||
}
|
||||
}
|
||||
|
||||
private void bottler(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
|
||||
if (recipe instanceof NEIHandlerBottler) {
|
||||
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
|
||||
if(fluids.size() >= 1)
|
||||
inputs.add(fluids.get(0).toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void carpenter(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
|
||||
if (recipe instanceof NEIHandlerCarpenter) {
|
||||
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
|
||||
if(fluids.size() >= 1)
|
||||
inputs.add(fluids.get(0).toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void centrifuge(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> outputs) {
|
||||
if (recipe instanceof NEIHandlerCentrifuge) {
|
||||
List<PositionedStack> otherStacks = recipe.getOtherStacks(recipeIndex);
|
||||
otherStacks.stream()
|
||||
.map(positionedStack -> positionedStack.items)
|
||||
.forEach(outputs::add);
|
||||
}
|
||||
}
|
||||
|
||||
private void fabricator(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs) {
|
||||
if (recipe instanceof NEIHandlerFabricator) {
|
||||
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
|
||||
if(fluids.size() >= 1)
|
||||
inputs.add(fluids.get(0).toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void fermenter(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if(recipe instanceof NEIHandlerFermenter) {
|
||||
List<PositionedFluidTank> tanks = getTanks(recipe, recipeIndex);
|
||||
tanks.forEach(tank -> {
|
||||
Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
|
||||
if (tank.position.x == 30) {
|
||||
// source
|
||||
inputs.add(fluids);
|
||||
} else {
|
||||
// outputs
|
||||
outputs.add(fluids);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void moistener(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if(recipe instanceof NEIHandlerMoistener) {
|
||||
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
|
||||
if(fluids.size() >= 1)
|
||||
inputs.add(fluids.get(0).toArray());
|
||||
List<PositionedStack> otherStacks = recipe.getOtherStacks(recipeIndex);
|
||||
otherStacks.forEach(positionedStack -> {
|
||||
ItemStack[] items = positionedStack.items;
|
||||
if(positionedStack.relx == 34) {
|
||||
// item
|
||||
inputs.add(items);
|
||||
} else {
|
||||
// product
|
||||
outputs.add(items);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void squeezer(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if(recipe instanceof NEIHandlerSqueezer) {
|
||||
List<List<FluidStack>> fluids = getFluids(recipe, recipeIndex);
|
||||
if(fluids.size() >= 1)
|
||||
outputs.add(fluids.get(0).toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void still(RecipeHandlerBase recipe, int recipeIndex, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if(recipe instanceof NEIHandlerStill) {
|
||||
getTanks(recipe, recipeIndex).forEach(tank -> {
|
||||
Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray();
|
||||
if(tank.position.x == 30) {
|
||||
// input
|
||||
inputs.add(fluids);
|
||||
} else {
|
||||
// output
|
||||
outputs.add(fluids);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It won't check the type
|
||||
*
|
||||
* @param recipe recipe
|
||||
* @param recipeIndex index
|
||||
* @return fluid tanks
|
||||
*/
|
||||
private List<List<FluidStack>> getFluids(RecipeHandlerBase recipe, int recipeIndex) {
|
||||
return ((RecipeHandlerBase.CachedBaseRecipe) recipe.arecipes.get(recipeIndex)).getFluidTanks()
|
||||
.stream()
|
||||
.map(positionedFluidTank -> Arrays
|
||||
.stream(positionedFluidTank.tanks)
|
||||
.map(FluidTank::getFluid)
|
||||
.collect(
|
||||
Collectors.toList()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private List<PositionedFluidTank> getTanks(RecipeHandlerBase recipe, int recipeIndex) {
|
||||
return ((RecipeHandlerBase.CachedBaseRecipe) recipe.arecipes.get(recipeIndex)).getFluidTanks();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.towdium.jecalculation.nei.adapter;
|
||||
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface IAdapter {
|
||||
void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs);
|
||||
}
|
||||
Reference in new issue
Block a user