mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 02:55:04 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cab0aff563 | ||
|
|
144a37cebb | ||
|
|
2d18dcf42b | ||
|
|
5bbcc570f9 | ||
|
|
98c9f03e74 |
No files matched your search
@@ -1,11 +1,11 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.recipe.BookmarkRecipeId;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -22,6 +22,10 @@ import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,6 +35,7 @@ import java.util.HashMap;
|
||||
public class BookmarkPanel extends ItemPanel
|
||||
{
|
||||
|
||||
protected File bookmarkFile;
|
||||
protected boolean bookmarksIsLoaded = false;
|
||||
public int sortedStackIndex = -1;
|
||||
public int sortedNamespaceIndex = -1;
|
||||
@@ -88,7 +93,6 @@ public class BookmarkPanel extends ItemPanel
|
||||
{
|
||||
realItems.add(stackA);
|
||||
metadata.add(meta);
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
public void replaceItem(int idx, ItemStack stack)
|
||||
@@ -127,7 +131,6 @@ public class BookmarkPanel extends ItemPanel
|
||||
{
|
||||
realItems.remove(idx);
|
||||
metadata.remove(idx);
|
||||
needRefresh = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,7 +156,6 @@ public class BookmarkPanel extends ItemPanel
|
||||
{
|
||||
realItems.add(dst, realItems.remove(src));
|
||||
metadata.add(dst, metadata.remove(src));
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,15 +287,11 @@ public class BookmarkPanel extends ItemPanel
|
||||
for (PositionedStack stack : ingredients) {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack.item, saveStackSize);
|
||||
|
||||
if (nbTag.getInteger("Count") > 0) {
|
||||
|
||||
if (unique.get(nbTag) == null) {
|
||||
unique.put(nbTag, 1);
|
||||
sorted.add(nbTag);
|
||||
} else if (saveStackSize) {
|
||||
unique.put(nbTag, unique.get(nbTag) + 1);
|
||||
}
|
||||
|
||||
if (unique.get(nbTag) == null) {
|
||||
unique.put(nbTag, 1);
|
||||
sorted.add(nbTag);
|
||||
} else if (saveStackSize) {
|
||||
unique.put(nbTag, unique.get(nbTag) + 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -311,6 +309,7 @@ public class BookmarkPanel extends ItemPanel
|
||||
|
||||
}
|
||||
|
||||
fixCountOfNamespaces();
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
@@ -410,6 +409,43 @@ public class BookmarkPanel extends ItemPanel
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setBookmarkFile(String worldPath)
|
||||
{
|
||||
|
||||
final File dir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
||||
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
bookmarkFile = new File(dir, "bookmarks.ini");
|
||||
|
||||
if (!bookmarkFile.exists()) {
|
||||
final File globalBookmarks = new File(CommonUtils.getMinecraftDir(), "saves/NEI/global/bookmarks.ini");
|
||||
final File configBookmarks = new File(NEIClientConfig.configDir, "bookmarks.ini");
|
||||
final File defaultBookmarks = configBookmarks.exists()? configBookmarks: globalBookmarks;
|
||||
|
||||
if (defaultBookmarks.exists()) {
|
||||
|
||||
try {
|
||||
bookmarkFile.createNewFile();
|
||||
|
||||
InputStream src = new FileInputStream(defaultBookmarks);
|
||||
OutputStream dst = new FileOutputStream(bookmarkFile);
|
||||
|
||||
IOUtils.copy(src, dst);
|
||||
|
||||
src.close();
|
||||
dst.close();
|
||||
|
||||
} catch(IOException e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bookmarksIsLoaded = false;
|
||||
}
|
||||
|
||||
public void saveBookmarks()
|
||||
{
|
||||
@@ -451,12 +487,11 @@ public class BookmarkPanel extends ItemPanel
|
||||
|
||||
}
|
||||
|
||||
File file = NEIClientConfig.bookmarkFile;
|
||||
if (file != null) {
|
||||
try(FileWriter writer = new FileWriter(file)) {
|
||||
if (bookmarkFile != null) {
|
||||
try(FileWriter writer = new FileWriter(bookmarkFile)) {
|
||||
IOUtils.writeLines(strings, "\n", writer);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", file, e);
|
||||
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", bookmarkFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,17 +506,16 @@ public class BookmarkPanel extends ItemPanel
|
||||
|
||||
bookmarksIsLoaded = true;
|
||||
|
||||
File file = NEIClientConfig.bookmarkFile;
|
||||
if (file == null || !file.exists()) {
|
||||
if (bookmarkFile == null || !bookmarkFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> itemStrings;
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
NEIClientConfig.logger.info("Loading bookmarks from file {}", file);
|
||||
try (FileReader reader = new FileReader(bookmarkFile)) {
|
||||
NEIClientConfig.logger.info("Loading bookmarks from file {}", bookmarkFile);
|
||||
itemStrings = IOUtils.readLines(reader);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", file, e);
|
||||
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", bookmarkFile, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import static codechicken.nei.LayoutManager.searchField;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ItemPanel extends Widget
|
||||
{
|
||||
@@ -38,6 +41,8 @@ public class ItemPanel extends Widget
|
||||
@Deprecated
|
||||
public ArrayList<ItemStack> realItems = new ArrayList<>();
|
||||
|
||||
protected Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
|
||||
|
||||
public static class ItemPanelSlot
|
||||
{
|
||||
public ItemStack item;
|
||||
@@ -64,7 +69,6 @@ public class ItemPanel extends Widget
|
||||
public void setItems(ArrayList<ItemStack> items)
|
||||
{
|
||||
newItems = items;
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
public void refresh(GuiContainer gui)
|
||||
@@ -320,6 +324,10 @@ public class ItemPanel extends Widget
|
||||
return true;
|
||||
}
|
||||
|
||||
if (handleSearchInputClick(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (handleGUIContainerClick(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
}
|
||||
@@ -442,6 +450,24 @@ public class ItemPanel extends Widget
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleSearchInputClick(int mouseX, int mouseY, int button)
|
||||
{
|
||||
|
||||
if (searchField.contains(mouseX, mouseY)) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(draggedStack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
searchField.setText(SPECIAL_REGEX_CHARS.matcher(fluidStack.getLocalizedName()).replaceAll("\\\\$0"));
|
||||
} else {
|
||||
searchField.setText(SPECIAL_REGEX_CHARS.matcher(draggedStack.getDisplayName()).replaceAll("\\\\$0"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int mousex, int mousey, int button) {
|
||||
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
||||
|
||||
@@ -36,11 +36,6 @@ public class ItemsGrid
|
||||
protected boolean[] validSlotMap;
|
||||
protected boolean[] invalidSlotMap;
|
||||
|
||||
private int[] guiSize;
|
||||
|
||||
protected boolean needRefresh = false;
|
||||
|
||||
|
||||
public ArrayList<ItemStack> getItems()
|
||||
{
|
||||
return realItems;
|
||||
@@ -107,8 +102,6 @@ public class ItemsGrid
|
||||
|
||||
columns = width / SLOT_SIZE;
|
||||
rows = height / SLOT_SIZE;
|
||||
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -134,51 +127,14 @@ public class ItemsGrid
|
||||
}
|
||||
|
||||
page = Math.max(0, Math.min(page, numPages - 1));
|
||||
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
public void refresh(GuiContainer gui)
|
||||
{
|
||||
if (!needRefresh(gui)) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateGuiOverlapSlots(gui);
|
||||
shiftPage(0);
|
||||
|
||||
needRefresh = false;
|
||||
}
|
||||
|
||||
private boolean needRefresh(GuiContainer gui)
|
||||
{
|
||||
|
||||
if (needRefresh == true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (gui == null && guiSize == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gui == null) {
|
||||
guiSize = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (guiSize == null) {
|
||||
guiSize = new int[]{ gui.guiLeft, gui.guiTop, gui.width, gui.height };
|
||||
return true;
|
||||
}
|
||||
|
||||
if (gui.guiLeft != guiSize[0] || gui.guiTop != guiSize[1] || gui.width != guiSize[2] || gui.height != guiSize[3]) {
|
||||
guiSize = new int[]{ gui.guiLeft, gui.guiTop, gui.width, gui.height };
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateGuiOverlapSlots(GuiContainer gui)
|
||||
{
|
||||
invalidSlotMap = new boolean[rows * columns];
|
||||
@@ -197,9 +153,9 @@ public class ItemsGrid
|
||||
validColumn = true;
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
|
||||
if (!slotValid(gui, r, c) && !invalidSlotMap[columns * r + c]) {
|
||||
invalidSlotMap[columns * r + c] = true;
|
||||
final int idx = columns * r + c;
|
||||
if (!slotValid(gui, r, c) && idx >= 0 && idx < invalidSlotMap.length && !invalidSlotMap[idx]) {
|
||||
invalidSlotMap[idx] = true;
|
||||
validColumn = false;
|
||||
perPage--;
|
||||
}
|
||||
@@ -238,7 +194,7 @@ public class ItemsGrid
|
||||
|
||||
public boolean isInvalidSlot(int idx)
|
||||
{
|
||||
return invalidSlotMap[idx] == true;
|
||||
return invalidSlotMap[idx];
|
||||
}
|
||||
|
||||
public void draw(int mousex, int mousey)
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.regex.Pattern;
|
||||
public class NEIClientConfig {
|
||||
private static boolean configLoaded;
|
||||
private static boolean enabledOverride;
|
||||
private static String worldPath;
|
||||
|
||||
public static Logger logger = LogManager.getLogger("NotEnoughItems");
|
||||
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
|
||||
@@ -60,12 +61,14 @@ public class NEIClientConfig {
|
||||
new File("saves/NEI/client.dat"),
|
||||
new ConfigFile(new File(configDir, "client.cfg")));
|
||||
public static ConfigSet world;
|
||||
public static final File bookmarkFile = new File(configDir, "bookmarks.ini");
|
||||
public static final File handlerFile = new File(configDir, "handlers.csv");
|
||||
public static final File serialHandlersFile = new File(configDir, "serialhandlers.cfg");
|
||||
public static final File heightHackHandlersFile = new File(configDir, "heighthackhandlers.cfg");
|
||||
public static final File handlerOrderingFile = new File(configDir, "handlerordering.csv");
|
||||
|
||||
@Deprecated
|
||||
public static File bookmarkFile;
|
||||
|
||||
// Set of handlers that need to be run in serial
|
||||
public static HashSet<String> serialHandlers = new HashSet<>();
|
||||
|
||||
@@ -177,6 +180,15 @@ public class NEIClientConfig {
|
||||
tag.getTag("command.heal").setDefaultValue("");
|
||||
API.addOption(new OptionTextField("command.heal"));
|
||||
|
||||
tag.getTag("inventory.worldSpecificBookmarks").setComment("Global or world specific bookmarks").getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.worldSpecificBookmarks", true) {
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
super.onClick(button);
|
||||
initBookmarkFile(worldPath);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
tag.getTag("inventory.bookmarksEnabled").setComment("Enable/disable bookmarks").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarksEnabled", true));
|
||||
tag.getTag("inventory.saveCurrentRecipeInBookmarksEnabled").setComment("Save Current Recipe in Bookmarks").getBooleanValue(true);
|
||||
@@ -262,17 +274,22 @@ public class NEIClientConfig {
|
||||
return OptionList.getOptionList("nei.options");
|
||||
}
|
||||
|
||||
public static void loadWorld(String saveName) {
|
||||
public static void loadWorld(String worldPath) {
|
||||
NEIClientConfig.worldPath = worldPath;
|
||||
|
||||
setInternalEnabled(true);
|
||||
logger.debug("Loading "+(Minecraft.getMinecraft().isSingleplayer() ? "Local" : "Remote")+" World");
|
||||
bootNEI(ClientUtils.getWorld());
|
||||
|
||||
File saveDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + saveName);
|
||||
boolean newWorld = !saveDir.exists();
|
||||
if (newWorld)
|
||||
saveDir.mkdirs();
|
||||
final File specificDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
||||
final boolean newWorld = !specificDir.exists();
|
||||
|
||||
world = new ConfigSet(new File(saveDir, "NEI.dat"), new ConfigFile(new File(saveDir, "NEI.cfg")));
|
||||
if (newWorld) {
|
||||
specificDir.mkdirs();
|
||||
}
|
||||
|
||||
initBookmarkFile(worldPath);
|
||||
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
|
||||
onWorldLoad(newWorld);
|
||||
}
|
||||
|
||||
@@ -344,6 +361,16 @@ public class NEIClientConfig {
|
||||
ItemSorter.loadConfig();
|
||||
}
|
||||
|
||||
private static void initBookmarkFile(String worldPath)
|
||||
{
|
||||
|
||||
if (!global.config.getTag("inventory.worldSpecificBookmarks").getBooleanValue()) {
|
||||
worldPath = "global";
|
||||
}
|
||||
|
||||
ItemPanels.bookmarkPanel.setBookmarkFile(worldPath);
|
||||
}
|
||||
|
||||
public static boolean isWorldSpecific(String setting) {
|
||||
if(world == null) return false;
|
||||
ConfigTag tag = world.config.getTag(setting, false);
|
||||
|
||||
@@ -157,7 +157,10 @@ public class NEIClientUtils extends NEIServerUtils
|
||||
final List<Iterable<Integer>> handlerSlots;
|
||||
try {
|
||||
GuiInfo.readLock.lock();
|
||||
handlerSlots = GuiInfo.guiHandlers.stream().map(handler -> handler.getItemSpawnSlots(gui, typestack)).collect(Collectors.toCollection(LinkedList::new));
|
||||
handlerSlots = GuiInfo.guiHandlers.stream()
|
||||
.map(handler -> handler.getItemSpawnSlots(gui, typestack))
|
||||
.filter(x -> x != null)
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
} finally {
|
||||
GuiInfo.readLock.unlock();
|
||||
}
|
||||
|
||||
@@ -692,9 +692,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
@Override
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||
// Because some of the handlers *cough avaritia* are oversized
|
||||
Rectangle rect = new Rectangle(area);
|
||||
|
||||
return rect.contains(x, y, w, h);
|
||||
return area.intersects(x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,15 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize)
|
||||
{
|
||||
final String strId = Item.itemRegistry.getNameForObject(stack.getItem());
|
||||
|
||||
if (strId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString("strId", Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
nbTag.setInteger("Count", saveStackSize? stack.stackSize: 1);
|
||||
nbTag.setString("strId", strId);
|
||||
nbTag.setInteger("Count", Math.max(saveStackSize? stack.stackSize: 1, 1));
|
||||
nbTag.setShort("Damage", (short)stack.getItemDamage());
|
||||
|
||||
if (stack.hasTagCompound()) {
|
||||
|
||||
@@ -31,12 +31,15 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler
|
||||
{
|
||||
|
||||
if (GTDisplayFluid != null && GTDisplayFluid.isInstance(stack.getItem())) {
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
|
||||
nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
|
||||
nbTag.setInteger("Count", saveStackSize? fluidStack.amount: 1);
|
||||
return nbTag;
|
||||
if (fluidStack != null) {
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
|
||||
nbTag.setInteger("Count", saveStackSize? fluidStack.amount: 1);
|
||||
return nbTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -108,6 +108,9 @@ nei.options.keys.world.creative=Gamemode
|
||||
nei.options.keys.world.creative.tip=Cycle Gamemode
|
||||
|
||||
nei.options.inventory=Inventory
|
||||
nei.options.inventory.worldSpecificBookmarks=World Specific Bookmarks
|
||||
nei.options.inventory.worldSpecificBookmarks.true=Yes
|
||||
nei.options.inventory.worldSpecificBookmarks.false=No
|
||||
nei.options.inventory.bookmarksEnabled=Bookmarks Panel Visibility
|
||||
nei.options.inventory.bookmarksEnabled.true=Visible
|
||||
nei.options.inventory.bookmarksEnabled.false=Hidden
|
||||
|
||||
Reference in new issue
Block a user