mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: convert gt fluid from nei item panel
This commit is contained in:
1 parent
e5767d75ab
commit
21eb93ea01
9 files changed
+36
-10
No files matched your search
@@ -5,6 +5,8 @@ import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.nei.adapter.*;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -12,6 +14,16 @@ import java.util.List;
|
||||
public class Adapter {
|
||||
public static List<IAdapter> adapters = new ArrayList<>();
|
||||
|
||||
public static Object convertFluid(ItemStack itemStack) {
|
||||
String name = Utilities.getName(itemStack);
|
||||
String modId = name.substring(0, name.indexOf(":"));
|
||||
String itemId = name.substring(name.indexOf(":") + 1);
|
||||
if (Loader.isModLoaded("gregtech")) {
|
||||
return GregTech.convertFluid(itemStack);
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Start=====");
|
||||
if (Loader.isModLoaded("Forestry")) {
|
||||
|
||||
@@ -39,7 +39,8 @@ public class NEIPlugin {
|
||||
public static ILabel getLabelUnderMouse() {
|
||||
if (NEIPlugin.currentItemStack == null)
|
||||
return ILabel.EMPTY;
|
||||
return ILabel.Converter.from(NEIPlugin.currentItemStack);
|
||||
Object stack = Adapter.convertFluid(NEIPlugin.currentItemStack);
|
||||
return ILabel.Converter.from(stack);
|
||||
}
|
||||
|
||||
public static void setLabelUnderMouse(ItemStack itemStack) {
|
||||
|
||||
@@ -67,17 +67,17 @@ public class GregTech implements IAdapter {
|
||||
|
||||
protected void handleDefault(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
Object[] objects = Arrays.stream(inputs.get(i)).map(o -> this.convertFluid((ItemStack) o)).toArray();
|
||||
Object[] objects = Arrays.stream(inputs.get(i)).map(o -> GregTech.convertFluid((ItemStack) o)).toArray();
|
||||
inputs.set(i, objects);
|
||||
}
|
||||
List<PositionedStack> otherStacks = recipe.getOtherStacks(index);
|
||||
outputs.addAll(otherStacks.stream()
|
||||
.map(positionedStack -> positionedStack.items)
|
||||
.map(itemStacks -> Arrays.stream(itemStacks).map(this::convertFluid).toArray())
|
||||
.map(itemStacks -> Arrays.stream(itemStacks).map(GregTech::convertFluid).toArray())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
protected Object convertFluid(ItemStack itemStack) {
|
||||
public static Object convertFluid(ItemStack itemStack) {
|
||||
FluidStack fluidStack = getFluidFromDisplayStack(itemStack);
|
||||
return fluidStack == null ? itemStack : fluidStack;
|
||||
}
|
||||
|
||||
@@ -88,11 +88,19 @@ public class Utilities {
|
||||
// MOD NAME
|
||||
@Nullable
|
||||
public static String getModName(Item item) {
|
||||
String name = GameData.getItemRegistry().getNameForObject(item);
|
||||
String name = getName(item);
|
||||
String id = name.substring(0, name.indexOf(":"));
|
||||
return id.equals("minecraft") ? "Minecraft" : Loader.instance().getIndexedModList().get(id).getName();
|
||||
}
|
||||
|
||||
public static String getName(Item item) {
|
||||
return GameData.getItemRegistry().getNameForObject(item);
|
||||
}
|
||||
|
||||
public static String getName(ItemStack itemStack) {
|
||||
return getName(itemStack.getItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* If fluid is lava or water, return 'Minecraft'.
|
||||
* If has still icon or flowing icon, get the icon name, or return 'unknown';
|
||||
|
||||
Reference in new issue
Block a user