mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
backport: 1.16.5
- fix: can not show overlay
This commit is contained in:
1 parent
1939619ed4
commit
5df4fafc5b
12 files changed
+51
-79
No files matched your search
@@ -1,13 +1,11 @@
|
||||
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;
|
||||
@@ -43,8 +41,6 @@ public class JustEnoughCalculation {
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event) {
|
||||
handler.init();
|
||||
Adapter.init();
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
||||
@@ -9,7 +9,7 @@ import me.towdium.jecalculation.data.structure.*;
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
@@ -72,10 +72,13 @@ public class Controller {
|
||||
}
|
||||
|
||||
private static void export(String s, Function<Recipes, NBTTagCompound> r) {
|
||||
EntityClientPlayerMP player = Utilities.getPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
File f = JecaConfig.getDataFile(s);
|
||||
Utilities.Json.write(r.apply(getRecipes()), f);
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.export", f.getAbsolutePath()));
|
||||
player.addChatMessage(new ChatComponentTranslation("jecalculation.chat.export", f.getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static void export(String group) {
|
||||
|
||||
@@ -124,7 +124,7 @@ public interface ILabel {
|
||||
* For registering, see {@link Serializer}.
|
||||
*/
|
||||
class Merger {
|
||||
private Utilities.Relation<String, MergerFunction> functions = new Utilities.Relation<>();
|
||||
private final Utilities.Relation<String, MergerFunction> functions = new Utilities.Relation<>();
|
||||
|
||||
private Merger() {
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public interface ILabel {
|
||||
public static final String KEY_IDENTIFIER = "type";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
|
||||
private HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
|
||||
private final HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
|
||||
|
||||
private Serializer() {
|
||||
}
|
||||
@@ -272,6 +272,7 @@ public interface ILabel {
|
||||
return guess.isEmpty() ? labels.get(0) : guess.get(0);
|
||||
}
|
||||
|
||||
// to test if the labels can be converted to other labels (like oreDict)
|
||||
public Pair<List<ILabel>, List<ILabel>> guess(List<ILabel> labels, @Nullable Class<?> context) {
|
||||
List<ILabel> suggest = new ReversedIterator<>(handlers.get(Priority.SUGGEST)).stream()
|
||||
.flatMap(h -> h.convert(labels,
|
||||
@@ -295,7 +296,7 @@ public interface ILabel {
|
||||
|
||||
class RegistryEditor {
|
||||
|
||||
private ArrayList<Record> records = new ArrayList<>();
|
||||
private final ArrayList<Record> records = new ArrayList<>();
|
||||
|
||||
private RegistryEditor() {
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -116,6 +117,8 @@ public class CostList {
|
||||
private int index;
|
||||
|
||||
public Calculator() throws ArithmeticException {
|
||||
EntityClientPlayerMP player = Utilities.getPlayer();
|
||||
|
||||
HashSet<CostList> set = new HashSet<>();
|
||||
set.add(CostList.this);
|
||||
Pair<Recipe, Long> next = find(true);
|
||||
@@ -144,8 +147,8 @@ public class CostList {
|
||||
addCatalyst(next.one.getLabel(Recipe.IO.CATALYST));
|
||||
next = find(true);
|
||||
}
|
||||
if (count++ > 1000) {
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
if (count++ > 1000 && player != null) {
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.max_loop"));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ public class JecaGui extends GuiContainer {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
public static boolean mouseIn(int xPos, int yPos, int xSize, int ySize, int xMouse, int yMouse) {
|
||||
return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,11 @@ public class GuiCraft extends WContainer implements IGui {
|
||||
refreshCalculator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsTransfer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void setMode(RecordCraft.Mode mode) {
|
||||
record.mode = mode;
|
||||
Controller.setRCraft(record);
|
||||
@@ -193,6 +198,7 @@ public class GuiCraft extends WContainer implements IGui {
|
||||
.map(i -> i.matches(l))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(ILabel::copy)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.gui.guis.pickers.IPicker;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.widgets.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static me.towdium.jecalculation.gui.Resource.*;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-16.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiDisamb extends IPicker.Impl implements IGui {
|
||||
// protected WLabelScroll up = new WLabelScroll(25, 48, 7, 3, WLabel.Mode.PICKER, true);
|
||||
// protected WLabelScroll down = new WLabelScroll(25, 105, 7, 3, WLabel.Mode.PICKER, true);
|
||||
// protected List<List<ILabel>> record;
|
||||
//
|
||||
// public GuiDisamb(List<List<ILabel>> record) {
|
||||
// this.record = record;
|
||||
// WSwitcher switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(i -> setPage(i.getIndex()));
|
||||
// ListenerValue<WLabelScroll, Integer> consumer = (i, v) -> callback.accept(i.get(v).copy().multiply(-1));
|
||||
// add(new WPanel());
|
||||
// add(new WIcon(7, 24, 20, 20, ICN_TEXT, "common.search"));
|
||||
// add(new WIcon(7, 48, 18, 54, ICN_LIST, "disamb.list"));
|
||||
// add(new WIcon(7, 105, 18, 54, ICN_LABEL, "disamb.label"));
|
||||
// add(new WSearch(25, 24, 90, up.setListener(consumer), down.setListener(consumer)));
|
||||
// add(switcher, up, down);
|
||||
// setPage(0);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// protected void setPage(int n) {
|
||||
// up.setLabels(record.get(n));
|
||||
// down.setLabels(ILabel.CONVERTER.guess(record.get(n)).one);
|
||||
// }
|
||||
}
|
||||
@@ -140,6 +140,11 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsTransfer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setNewGroup(boolean b) {
|
||||
if (b) {
|
||||
remove(neu, label, clear, copy, save);
|
||||
|
||||
@@ -13,4 +13,8 @@ import me.towdium.jecalculation.gui.widgets.IContainer;
|
||||
public interface IGui extends IContainer {
|
||||
default void onVisible(JecaGui gui) {
|
||||
}
|
||||
|
||||
default boolean acceptsTransfer() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -58,9 +58,13 @@ public class WContainer implements IContainer {
|
||||
public boolean onDraw(JecaGui gui, int mouseX, int mouseY) {
|
||||
IWidget[] w = new IWidget[1];
|
||||
widgets.forEach(widget -> {
|
||||
if(widget.onDraw(gui, mouseX, mouseY)) w[0] = widget;
|
||||
if (widget.onDraw(gui, mouseX, mouseY))
|
||||
w[0] = widget;
|
||||
});
|
||||
if(w[0] != null) w[0].onDraw(gui, mouseX, mouseY);
|
||||
if (w[0] != null)
|
||||
w[0].onDraw(gui, mouseX, mouseY);
|
||||
if (overlay != null)
|
||||
overlay.onDraw(gui, mouseX, mouseY);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -68,7 +72,8 @@ public class WContainer implements IContainer {
|
||||
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
boolean b = overlay != null && overlay.onMouseClicked(gui, xMouse, yMouse, button);
|
||||
return b || new Utilities.ReversedIterator<>(widgets).stream()
|
||||
.anyMatch(i -> i.onMouseClicked(gui, xMouse, yMouse, button));
|
||||
.anyMatch(i -> i.onMouseClicked(gui, xMouse, yMouse,
|
||||
button));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,21 +86,22 @@ public class WContainer implements IContainer {
|
||||
public boolean onMouseReleased(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
boolean b = overlay != null && overlay.onMouseReleased(gui, xMouse, yMouse, button);
|
||||
return b || new Utilities.ReversedIterator<>(widgets).stream()
|
||||
.anyMatch(i -> i.onMouseReleased(gui, xMouse, yMouse, button));
|
||||
.anyMatch(i -> i.onMouseReleased(gui, xMouse, yMouse,
|
||||
button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
|
||||
boolean b = overlay != null && overlay.onMouseScroll(gui, xMouse, yMouse, diff);
|
||||
return b || new Utilities.ReversedIterator<>(widgets).stream()
|
||||
.anyMatch(i -> i.onMouseScroll(gui, xMouse, yMouse, diff));
|
||||
.anyMatch(i -> i.onMouseScroll(gui, xMouse, yMouse, diff));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
|
||||
boolean b = overlay != null && overlay.onTooltip(gui, xMouse, yMouse, tooltip);
|
||||
return b || new Utilities.ReversedIterator<>(widgets).stream()
|
||||
.anyMatch(i -> i.onTooltip(gui, xMouse, yMouse, tooltip));
|
||||
.anyMatch(i -> i.onTooltip(gui, xMouse, yMouse, tooltip));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -4,30 +4,24 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.*;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.CostList;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import scala.tools.cmd.Opt;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NEIPlugin {
|
||||
|
||||
public static void init() {
|
||||
GuiContainerManager.addTooltipHandler(new JecaTooltipHandler());
|
||||
Adapter.init();
|
||||
}
|
||||
|
||||
private static ItemStack currentItemStack;
|
||||
|
||||
public static ILabel getLabelUnderMouse() {
|
||||
if (NEIPlugin.currentItemStack == null) return ILabel.EMPTY;
|
||||
if (NEIPlugin.currentItemStack == null)
|
||||
return ILabel.EMPTY;
|
||||
return ILabel.Converter.from(NEIPlugin.currentItemStack);
|
||||
}
|
||||
|
||||
@@ -38,14 +32,14 @@ public class NEIPlugin {
|
||||
public static Optional<ItemStack> getCatalyst(@Nonnull IRecipeHandler handler) {
|
||||
final String handlerName = handler.toString().split("@")[0];
|
||||
final String handlerID;
|
||||
if(handler instanceof TemplateRecipeHandler) {
|
||||
handlerID = (((TemplateRecipeHandler)handler).getOverlayIdentifier());
|
||||
if (handler instanceof TemplateRecipeHandler) {
|
||||
handlerID = (((TemplateRecipeHandler) handler).getOverlayIdentifier());
|
||||
} else {
|
||||
handlerID = null;
|
||||
}
|
||||
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, handlerID);
|
||||
|
||||
if(info == null) {
|
||||
if (info == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ItemStack itemStack = info.getItemStack();
|
||||
@@ -69,6 +63,4 @@ public class NEIPlugin {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user