mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-14 17:24:41 +00:00
Compare commits
63
Commits
2.8.140-GTNH
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e6b31de18 | ||
|
|
1a27b02412 | ||
|
|
0185cd64b1 | ||
|
|
fbbeafcd79 | ||
|
|
9839d1d08f | ||
|
|
84d42de15f | ||
|
|
d04e1c8e83 | ||
|
|
514af5669c | ||
|
|
41c2b96c88 | ||
|
|
8e1541eab1 | ||
|
|
9411541fd8 | ||
|
|
ae0d6c6108 | ||
|
|
aea4c2866a | ||
|
|
c1a525594c | ||
|
|
afc8a2380b | ||
|
|
a0b2430458 | ||
|
|
4dc6be839b | ||
|
|
030795e3c7 | ||
|
|
897a22ad17 | ||
|
|
5faed21218 | ||
|
|
aa9da2e0a0 | ||
|
|
e9a3a494d5 | ||
|
|
ebe83f970f | ||
|
|
ad9beb7f90 | ||
|
|
68bdb51c6b | ||
|
|
e4e1964dec | ||
|
|
560618024f | ||
|
|
e2a2d2a9df | ||
|
|
7163630cb1 | ||
|
|
ab168ad6ba | ||
|
|
e13e3483f0 | ||
|
|
de26547b64 | ||
|
|
c49f8808fd | ||
|
|
1c6cc8b693 | ||
|
|
43ae1b613a | ||
|
|
402c4325a6 | ||
|
|
550e85c456 | ||
|
|
1673079cbb | ||
|
|
e6174c446a | ||
|
|
869b4571b0 | ||
|
|
35f5400ecb | ||
|
|
1e2801c891 | ||
|
|
1b3b495fec | ||
|
|
2844ea35bc | ||
|
|
c020ecbf1f | ||
|
|
a105a60a1a | ||
|
|
3a4a6734dc | ||
|
|
11f9194de9 | ||
|
|
a685efb3b7 | ||
|
|
9f3697bb67 | ||
|
|
18abb880f8 | ||
|
|
5868187410 | ||
|
|
f84c4ef2bd | ||
|
|
a54c414595 | ||
|
|
3c472a02cb | ||
|
|
382278bebb | ||
|
|
55c9811a2b | ||
|
|
0ec87a8b9e | ||
|
|
939845a9ed | ||
|
|
c9db437dd1 | ||
|
|
b1f20104a6 | ||
|
|
ab8d5f275f | ||
|
|
9e87f2b158 |
No files matched your search
@@ -33,12 +33,10 @@ body:
|
||||
description: What Java version are you using? It's worth mentioning that if you play on Java9+ you should try update to latest minor release (e.g. prefer Java 17.0.6 over 17.0.2) of that version.
|
||||
options:
|
||||
- Java 8
|
||||
- Java 9
|
||||
- Java 11
|
||||
- Java 17
|
||||
- Java 19
|
||||
- Java 20
|
||||
- Java 21
|
||||
- java 25
|
||||
- java 26
|
||||
- Other (Please Specify)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -3,9 +3,9 @@ name: Build and test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
push:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
|
||||
+3
-1
@@ -28,6 +28,7 @@ whitelist.json
|
||||
*.iws
|
||||
src/main/resources/mixins.*([!.]).json
|
||||
*.bat
|
||||
*.sh
|
||||
*.DS_Store
|
||||
!gradlew.bat
|
||||
.factorypath
|
||||
@@ -35,4 +36,5 @@ addon.local.gradle
|
||||
addon.local.gradle.kts
|
||||
addon.late.local.gradle
|
||||
addon.late.local.gradle.kts
|
||||
layout.json
|
||||
layout.json
|
||||
|
||||
@@ -75,7 +75,7 @@ All items that match `filter` will show your information page. See `config/NEI/c
|
||||
|
||||
#### Item Information Config File
|
||||
|
||||
If you're a modpack creator and want to make custom item information pages, they can easily be added in `config/NEI/informationpages.cfg`, which has a few more examples.
|
||||
If you're a modpack creator and want to make custom item information pages, they can easily be added in `config/NEI/informationpages.cfg`, which has a few more examples. The file is not created automatically: use the Export button in the NEI options under Tools > Default Config Files to copy the defaults to `config/NEI`.
|
||||
|
||||
## Other items of note:
|
||||
|
||||
|
||||
+10
-5
@@ -5,8 +5,8 @@ configurations.create('gtnhlibEmbed') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api('com.github.GTNewHorizons:CodeChickenCore:1.4.19:dev')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:GTNHLib:0.11.48:dev')
|
||||
api('com.github.GTNewHorizons:CodeChickenCore:1.4.22:dev')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:GTNHLib:0.11.54:dev')
|
||||
|
||||
shadowImplementation('org.apache.commons:commons-csv:1.10.0')
|
||||
|
||||
@@ -23,13 +23,18 @@ dependencies {
|
||||
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
|
||||
testRuntimeOnly("org.lwjgl.lwjgl:lwjgl:2.9.3");
|
||||
|
||||
compileOnly("com.github.GTNewHorizons:GTNHLib:0.11.48") { transitive = false }
|
||||
gtnhlibEmbed("com.github.GTNewHorizons:GTNHLib:0.11.48") { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:GTNHLib:0.11.54") { transitive = false }
|
||||
gtnhlibEmbed("com.github.GTNewHorizons:GTNHLib:0.11.54") { transitive = false }
|
||||
}
|
||||
|
||||
def embedArchiveOperations = gtnhGradle.archiveOperations
|
||||
def gtnhlibEmbedContents = configurations.gtnhlibEmbed.elements.map { files ->
|
||||
files.collect { embedArchiveOperations.zipTree(it.asFile) }
|
||||
}
|
||||
|
||||
[tasks.jar, tasks.shadowJar].each {
|
||||
it.configure {
|
||||
from({ project.configurations.getByName('gtnhlibEmbed').collect { zipTree(it) } }) {
|
||||
from(gtnhlibEmbedContents) {
|
||||
include 'com/gtnewhorizon/gtnhlib/color/ColorResource.class'
|
||||
include 'com/gtnewhorizon/gtnhlib/color/ColorResource$*.class'
|
||||
}
|
||||
|
||||
@@ -186,6 +186,11 @@ modrinthRelations = required-project\:codechickencore-unofficial
|
||||
# Leave this empty if you don't want to publish on CurseForge.
|
||||
curseForgeProjectId = 358228
|
||||
|
||||
# Comma-separated supported CurseForge environments: client, server (case-insensitive).
|
||||
# Use client or server for mods that only support one environment. Defaults to client,server.
|
||||
# These tags describe where the mod can run, not whether installation is required on both sides.
|
||||
curseForgeEnvironments = client,server
|
||||
|
||||
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
|
||||
# Syntax: type1:name1;type2:name2;...
|
||||
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,7 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@@ -29,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@@ -57,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
Vendored
+12
-23
@@ -19,12 +19,12 @@
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@@ -51,7 +51,7 @@ echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@@ -65,29 +65,18 @@ echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.29'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.34'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.ItemsGrid.ItemsGridSlot;
|
||||
import codechicken.nei.api.GuiInfo;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.ShortcutInputHandler;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
@@ -55,12 +56,14 @@ public abstract class AbstractSubpanel<T extends ItemsGrid<? extends ItemsGridSl
|
||||
}
|
||||
|
||||
protected void updateLinePadding() {
|
||||
GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
|
||||
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
|
||||
final INEIGuiHandler[] handlers = GuiInfo.getGuiHandlersSnapshot();
|
||||
final Rectangle4i rect = new Rectangle4i(this.x, this.y - 1, 10, 2);
|
||||
this.linePaddingStart = 0;
|
||||
|
||||
while (GuiInfo
|
||||
.hideItemPanelSlot(guiContainer, new Rectangle4i(this.x + this.linePaddingStart, this.y - 1, 10, 2))) {
|
||||
while (this.linePaddingStart < this.w && GuiInfo.hideItemPanelSlot(guiContainer, rect, handlers)) {
|
||||
this.linePaddingStart += 10;
|
||||
rect.x += 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@@ -30,6 +32,8 @@ public class AutoFocusWidget implements IContainerInputHandler {
|
||||
|
||||
protected boolean autofocus = false;
|
||||
protected Point mouse;
|
||||
protected Point pendingMouse;
|
||||
protected GuiTextField textInputHolder;
|
||||
|
||||
public AutoFocusWidget() {
|
||||
GuiContainerManager.addInputHandler(this);
|
||||
@@ -38,32 +42,83 @@ public class AutoFocusWidget implements IContainerInputHandler {
|
||||
public void load(GuiContainer gui) {
|
||||
this.autofocus = LayoutManager.searchField.isVisible() && NEIClientConfig.searchWidgetAutofocus() != 0
|
||||
&& isAllowedGuiAutoSearchFocus(gui);
|
||||
this.mouse = getMousePosition();
|
||||
this.mouse = null;
|
||||
this.pendingMouse = null;
|
||||
|
||||
if (this.autofocus) {
|
||||
beginTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
protected void beginTextInput() {
|
||||
if (this.textInputHolder == null) {
|
||||
this.textInputHolder = new GuiTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
this.textInputHolder.setFocused(true);
|
||||
}
|
||||
|
||||
protected void endTextInput() {
|
||||
if (this.textInputHolder != null) {
|
||||
this.textInputHolder.setFocused(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void guiTick() {
|
||||
if (!this.autofocus) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Point current = getMousePosition();
|
||||
|
||||
if (this.mouse == null) {
|
||||
if (current.equals(this.pendingMouse)) {
|
||||
this.mouse = current;
|
||||
}
|
||||
|
||||
this.pendingMouse = current;
|
||||
} else if (!this.mouse.equals(current)) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected void cancel() {
|
||||
if (this.autofocus) {
|
||||
this.autofocus = false;
|
||||
endTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
||||
|
||||
if (this.autofocus) {
|
||||
this.autofocus = false;
|
||||
|
||||
if (!this.mouse.equals(getMousePosition())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NEIClientConfig.searchWidgetAutofocus() == 2
|
||||
&& GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindInventory)) {
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER
|
||||
|| keyCode == Keyboard.KEY_ESCAPE) {
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ChatAllowedCharacters.isAllowedCharacter(keyChar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.autofocus = false;
|
||||
|
||||
LayoutManager.searchField.setFocus(true);
|
||||
endTextInput();
|
||||
|
||||
final String oldText = LayoutManager.searchField.text();
|
||||
LayoutManager.searchField.handleKeyPress(keyCode, keyChar);
|
||||
return true;
|
||||
|
||||
return !LayoutManager.searchField.text().equals(oldText);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -76,13 +131,13 @@ public class AutoFocusWidget implements IContainerInputHandler {
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,22 +146,22 @@ public class AutoFocusWidget implements IContainerInputHandler {
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
this.autofocus = false;
|
||||
cancel();
|
||||
}
|
||||
|
||||
protected boolean isAllowedGuiAutoSearchFocus(GuiContainer gui) {
|
||||
|
||||
@@ -572,9 +572,10 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
|
||||
return;
|
||||
} else if (this.sortableGroup != null) {
|
||||
final int overRowIndex = grid.getRowIndex(mousey);
|
||||
final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1);
|
||||
|
||||
if (overRowIndex >= 0 && this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
|
||||
if (overRowIndex >= 0 && !isOverNamespaceControls(mousex, mousey)
|
||||
&& !this.sortableGroup.matches(this.grid, this.grid.getRowGroupId(overRowIndex))) {
|
||||
this.grid.moveGroup(this.sortableGroup, overRowIndex);
|
||||
}
|
||||
|
||||
@@ -1022,14 +1023,18 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
this.mouseDownSlot = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int shift, int mousex, int mousey) {
|
||||
|
||||
if ((!inEditingState() || this.sortableGroup != null) && new Rectangle4i(
|
||||
private boolean isOverNamespaceControls(int mousex, int mousey) {
|
||||
return new Rectangle4i(
|
||||
namespacePrev.x,
|
||||
namespacePrev.y,
|
||||
namespaceNext.x + namespaceNext.w - namespacePrev.x,
|
||||
namespacePrev.h).contains(mousex, mousey)) {
|
||||
namespacePrev.h).contains(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int shift, int mousex, int mousey) {
|
||||
|
||||
if ((!inEditingState() || this.sortableGroup != null) && isOverNamespaceControls(mousex, mousey)) {
|
||||
|
||||
if (shift > 0) {
|
||||
this.storage.prevNamespace();
|
||||
@@ -1105,10 +1110,10 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
}
|
||||
|
||||
if (super.onMouseWheel(shift, mousex, mousey)) {
|
||||
final int overRowIndex = grid.getRowIndex(mousey);
|
||||
final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1);
|
||||
|
||||
if (this.sortableGroup != null && overRowIndex >= 0
|
||||
&& this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
|
||||
&& !this.sortableGroup.matches(this.grid, this.grid.getRowGroupId(overRowIndex))) {
|
||||
this.grid.moveGroup(this.sortableGroup, overRowIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package codechicken.nei;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@@ -12,7 +10,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -37,8 +36,10 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import codechicken.core.ClassDiscoverer;
|
||||
@@ -50,8 +51,13 @@ import codechicken.nei.api.IConfigureNEI;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.bookmark.tree.GuiCraftingTree;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiUsageRecipe;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.RecipeHandlerRef;
|
||||
import codechicken.nei.recipe.RecipeItemInputHandler;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.recipe.debug.DebugHandlerWidget;
|
||||
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
@@ -67,6 +73,22 @@ public class ClientHandler {
|
||||
|
||||
private static ClientHandler instance;
|
||||
private final ArrayList<EntityItem> SMPmagneticItems = new ArrayList<>();
|
||||
private static final String HANDLER_ORDERING = "handlerordering.csv";
|
||||
public static final List<String> DEFAULT_CONFIGS = ImmutableList.of(
|
||||
"serialhandlers.cfg",
|
||||
"heighthackhandlers.cfg",
|
||||
"hiddenhandlers.cfg",
|
||||
"enableautofocus.cfg",
|
||||
"guicraftablesblacklist.cfg",
|
||||
"defaultbookmarkcontainers.cfg",
|
||||
"hiddenitems.cfg",
|
||||
"guidfilters.cfg",
|
||||
"informationpages.cfg",
|
||||
"collapsibleitems.cfg",
|
||||
"recipeidblacklist.cfg",
|
||||
"handlers.csv",
|
||||
"catalysts.csv",
|
||||
HANDLER_ORDERING);
|
||||
private World lastworld;
|
||||
|
||||
public void addSMPMagneticItem(int i, World world) {
|
||||
@@ -160,17 +182,30 @@ public class ClientHandler {
|
||||
StackInfo.loadGuidFilters();
|
||||
}
|
||||
|
||||
public static void loadSettingsFile(String resource, Consumer<Stream<String>> callback) {
|
||||
loadSettingsFile(resource, (file, writer) -> {
|
||||
String folder = resource.substring(resource.lastIndexOf(".") + 1);
|
||||
URL defaultResource = ClientHandler.class.getResource("/assets/nei/" + folder + "/" + resource);
|
||||
private static URL getDefaultResource(String resource) {
|
||||
final String folder = resource.substring(resource.lastIndexOf(".") + 1);
|
||||
return ClientHandler.class.getResource("/assets/nei/" + folder + "/" + resource);
|
||||
}
|
||||
|
||||
if (defaultResource != null) {
|
||||
try {
|
||||
IOUtils.copy(defaultResource.openStream(), writer);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}, callback);
|
||||
public static boolean exportDefaultConfig(String resource) {
|
||||
final File file = new File(NEIClientConfig.configDir, resource);
|
||||
if (file.exists() && !NEIClientUtils.backupFile(file)) return false;
|
||||
|
||||
if (HANDLER_ORDERING.equals(resource)) {
|
||||
return writeDefaultHandlerOrdering();
|
||||
}
|
||||
|
||||
final URL url = getDefaultResource(resource);
|
||||
if (url == null) return false;
|
||||
|
||||
try {
|
||||
FileUtils.copyURLToFile(url, file);
|
||||
NEIClientConfig.logger.info("Exported default '{}' to {}", resource, file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to export default '{}' to file {}", resource, file, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean loadSettingsResource(String resource, Consumer<Stream<String>> callback) {
|
||||
@@ -196,30 +231,24 @@ public class ClientHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean loadSettingsFile(String resource, BiConsumer<File, FileWriter> createDefault,
|
||||
Consumer<Stream<String>> callback) {
|
||||
File file = new File(NEIClientConfig.configDir, resource);
|
||||
public static boolean loadSettingsFile(String resource, Consumer<Stream<String>> callback) {
|
||||
final File file = new File(NEIClientConfig.configDir, resource);
|
||||
final boolean fromJar = !file.exists();
|
||||
|
||||
if (!file.exists() && createDefault != null) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
NEIClientConfig.logger.info("Creating default '{}' {}", resource, file);
|
||||
createDefault.accept(file, writer);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to save default '{}' to file {}", resource, file, e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final URL url = fromJar ? getDefaultResource(resource) : file.toURI().toURL();
|
||||
if (url == null) return false;
|
||||
|
||||
if (file.exists()) {
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
NEIClientConfig.logger.info("Loading '{}' file {}", resource, file);
|
||||
try (InputStreamReader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) {
|
||||
NEIClientConfig.logger.info("Loading '{}' from {}", resource, fromJar ? "JAR" : file);
|
||||
callback.accept(
|
||||
IOUtils.readLines(reader).stream()
|
||||
.map(line -> line.contains("#") ? line.substring(0, line.indexOf('#')) : line)
|
||||
.map(String::trim).filter(line -> !line.isEmpty()));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load '{}' file {}", resource, file, e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load '{}' file {}", resource, file, e);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -292,26 +321,46 @@ public class ClientHandler {
|
||||
}
|
||||
|
||||
public static void loadHandlerOrdering() {
|
||||
final String COMMA_DELIMITER = ",";
|
||||
final String[] defaultHandlerOrdering = {
|
||||
loadSettingsFile(
|
||||
HANDLER_ORDERING,
|
||||
lines -> lines.map(line -> line.split(",")).filter(parts -> parts.length == 2).forEach(parts -> {
|
||||
String handlerId = parts[0];
|
||||
int ordering = Integer.parseInt(parts[1]);
|
||||
NEIClientConfig.handlerOrdering.put(handlerId, ordering);
|
||||
}));
|
||||
}
|
||||
|
||||
private static boolean writeDefaultHandlerOrdering() {
|
||||
final File file = new File(NEIClientConfig.configDir, HANDLER_ORDERING);
|
||||
final List<String> lines = Lists.newArrayList(
|
||||
"# Each line in this file should either be a comment (starts with '#') or an ordering.",
|
||||
"# Ordering lines are <handler ID>,<ordering number>.",
|
||||
"# Handlers will be sorted in order of number ascending, so smaller numbers first.",
|
||||
"# Any handlers that are missing from this file will be assigned to 0.", "# Negative numbers are fine.",
|
||||
"# If you delete this file, it will be regenerated with all registered handler IDs.", };
|
||||
"# Any handlers that are missing from this file keep their own order, 0 for most of them.",
|
||||
"# Negative numbers are fine.");
|
||||
final Map<String, Integer> orders = new TreeMap<>();
|
||||
final List<IRecipeHandler> handlers = new ArrayList<>();
|
||||
handlers.addAll(GuiCraftingRecipe.craftinghandlers);
|
||||
handlers.addAll(GuiCraftingRecipe.serialCraftingHandlers);
|
||||
handlers.addAll(GuiUsageRecipe.usagehandlers);
|
||||
handlers.addAll(GuiUsageRecipe.serialUsageHandlers);
|
||||
|
||||
loadSettingsFile("handlerordering.csv", (file, writer) -> {
|
||||
List<String> toWrite = Lists.newArrayList(defaultHandlerOrdering);
|
||||
GuiRecipeTab.handlerMap.keySet().stream().sorted()
|
||||
.forEach(handlerId -> toWrite.add(String.format("%s" + COMMA_DELIMITER + "0", handlerId)));
|
||||
try {
|
||||
IOUtils.writeLines(toWrite, "\n", writer);
|
||||
} catch (IOException e) {}
|
||||
}, lines -> lines.map(line -> line.split(COMMA_DELIMITER)).filter(parts -> parts.length == 2).forEach(parts -> {
|
||||
String handlerId = parts[0];
|
||||
int ordering = Integer.parseInt(parts[1]);
|
||||
NEIClientConfig.handlerOrdering.put(handlerId, ordering);
|
||||
}));
|
||||
for (IRecipeHandler handler : handlers) {
|
||||
orders.putIfAbsent(
|
||||
NEIClientConfig.HANDLER_ID_FUNCTION.apply(handler),
|
||||
NEIClientConfig.getHandlerOrder(handler));
|
||||
}
|
||||
|
||||
orders.forEach((handlerId, order) -> lines.add(handlerId + "," + order));
|
||||
|
||||
try {
|
||||
NEIClientConfig.logger.info("Creating default '{}' {}", HANDLER_ORDERING, file);
|
||||
FileUtils.writeLines(file, StandardCharsets.UTF_8.name(), lines, "\n");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to save default '{}' to file {}", HANDLER_ORDERING, file, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadPluginsList() {
|
||||
@@ -398,6 +447,11 @@ public class ClientHandler {
|
||||
if (event.world == mc.theWorld) {
|
||||
NEIClientConfig.unloadWorld();
|
||||
ItemMobSpawner.clearEntityReferences();
|
||||
RecipeItemInputHandler.instance.clearTooltipCache();
|
||||
RecipeHandlerRef.clearCache();
|
||||
ItemPanels.itemPanel.craftablesPanel.clearGuiReferences();
|
||||
DebugHandlerWidget.instance.clearGuiReferences();
|
||||
NEIController.manager = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTBase.NBTPrimitive;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -34,6 +38,7 @@ public class CollapsibleItems {
|
||||
public ItemFilter filter;
|
||||
public boolean expanded = false;
|
||||
public String displayName = "";
|
||||
public String unlocalizedName;
|
||||
|
||||
public void setFilter(String filter) {
|
||||
this.filter = ItemStackFilterParser.parse(filter.trim());
|
||||
@@ -45,15 +50,38 @@ public class CollapsibleItems {
|
||||
this.guid = guid;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
if (this.unlocalizedName != null && !this.unlocalizedName.isEmpty()) {
|
||||
final String translated = StatCollector.translateToLocal(this.unlocalizedName);
|
||||
|
||||
if (!translated.equals(this.unlocalizedName)) {
|
||||
return translated;
|
||||
}
|
||||
}
|
||||
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack stack) {
|
||||
return this.filter.matches(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiGroup {
|
||||
|
||||
private String unlocalizedName;
|
||||
|
||||
public ApiGroup setName(String unlocalizedName) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String STATE_KEY = "collapsibleitems";
|
||||
|
||||
protected static File statesFile;
|
||||
protected static final List<GroupItem> groups = new ArrayList<>();
|
||||
protected static final List<Supplier<GroupItem>> apiGroups = new CopyOnWriteArrayList<>();
|
||||
protected static final Map<ItemStack, Integer> cache = new ConcurrentHashMap<>();
|
||||
|
||||
private CollapsibleItems() {}
|
||||
@@ -76,11 +104,57 @@ public class CollapsibleItems {
|
||||
ClientHandler.loadSettingsFile(
|
||||
"collapsibleitems.cfg",
|
||||
lines -> parseFile(lines.collect(Collectors.toCollection(ArrayList::new))));
|
||||
|
||||
for (Supplier<GroupItem> apiGroup : CollapsibleItems.apiGroups) {
|
||||
try {
|
||||
addGroup(apiGroup.get());
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Failed to add API group", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadStates();
|
||||
}
|
||||
|
||||
public static ApiGroup registerGroup(String filter) {
|
||||
final ApiGroup apiGroup = new ApiGroup();
|
||||
|
||||
CollapsibleItems.apiGroups.add(() -> {
|
||||
GroupItem group = new GroupItem();
|
||||
group.setFilter(filter);
|
||||
group.unlocalizedName = apiGroup.unlocalizedName;
|
||||
return group;
|
||||
});
|
||||
|
||||
return apiGroup;
|
||||
}
|
||||
|
||||
public static ApiGroup registerGroup(Iterable<ItemStack> items) {
|
||||
final ApiGroup apiGroup = new ApiGroup();
|
||||
final ItemStackSet filter = new ItemStackSet();
|
||||
|
||||
for (ItemStack stack : items) {
|
||||
if (stack != null) filter.add(stack.copy());
|
||||
}
|
||||
|
||||
if (filter.isEmpty()) return apiGroup;
|
||||
|
||||
final String key = filter.keys().stream()
|
||||
.map(stack -> Item.itemRegistry.getNameForObject(stack.getItem()) + ":" + stack.getItemDamage())
|
||||
.sorted().collect(Collectors.joining(","));
|
||||
final String guid = UUID.nameUUIDFromBytes(key.getBytes()).toString();
|
||||
|
||||
CollapsibleItems.apiGroups.add(() -> {
|
||||
GroupItem group = new GroupItem();
|
||||
group.setFilter(filter, guid);
|
||||
group.unlocalizedName = apiGroup.unlocalizedName;
|
||||
return group;
|
||||
});
|
||||
|
||||
return apiGroup;
|
||||
}
|
||||
|
||||
private static void parseFile(List<String> itemStrings) {
|
||||
final JsonParser parser = new JsonParser();
|
||||
GroupItem group = new GroupItem();
|
||||
@@ -91,17 +165,8 @@ public class CollapsibleItems {
|
||||
if (itemStr.startsWith("; ")) {
|
||||
JsonObject settings = parser.parse(itemStr.substring(2)).getAsJsonObject();
|
||||
|
||||
if (settings.get("displayName") != null) {
|
||||
group.displayName = settings.get("displayName").getAsString();
|
||||
}
|
||||
|
||||
if (settings.get("unlocalizedName") != null) {
|
||||
String unlocalizedName = settings.get("unlocalizedName").getAsString();
|
||||
String displayName = StatCollector.translateToLocal(unlocalizedName);
|
||||
|
||||
if (!displayName.equals(unlocalizedName)) {
|
||||
group.displayName = displayName;
|
||||
}
|
||||
group.unlocalizedName = settings.get("unlocalizedName").getAsString();
|
||||
}
|
||||
|
||||
if (settings.get("expanded") != null) {
|
||||
@@ -175,7 +240,7 @@ public class CollapsibleItems {
|
||||
public static String getDisplayName(int groupIndex) {
|
||||
|
||||
if (groupIndex < CollapsibleItems.groups.size()) {
|
||||
return CollapsibleItems.groups.get(groupIndex).displayName;
|
||||
return CollapsibleItems.groups.get(groupIndex).getDisplayName();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -227,17 +292,17 @@ public class CollapsibleItems {
|
||||
|
||||
if (NEIClientConfig.world.nbt.hasKey(STATE_KEY)) {
|
||||
NBTTagCompound states = NEIClientConfig.world.nbt.getCompoundTag(STATE_KEY);
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, NBTPrimitive> list = (Map<String, NBTPrimitive>) states.tagMap;
|
||||
final Map<String, NBTBase> list = states.tagMap;
|
||||
final Map<String, GroupItem> mapping = new HashMap<>();
|
||||
|
||||
for (GroupItem group : CollapsibleItems.groups) {
|
||||
mapping.put(group.guid, group);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, NBTPrimitive> nbtEntry : list.entrySet()) {
|
||||
for (Map.Entry<String, NBTBase> nbtEntry : list.entrySet()) {
|
||||
if (mapping.containsKey(nbtEntry.getKey())) {
|
||||
mapping.get(nbtEntry.getKey()).expanded = nbtEntry.getValue().func_150290_f() == 1;
|
||||
mapping.get(nbtEntry.getKey()).expanded = ((NBTPrimitive) nbtEntry.getValue()).func_150290_f()
|
||||
== 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
|
||||
|
||||
public abstract class CompositeTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
protected static final int SCREEN_MARGIN = 8 * 2 + 10;
|
||||
protected static final int RESERVED_HEIGHT = 40;
|
||||
|
||||
protected final List<ItemsTooltipLineHandler> lines = new ArrayList<>();
|
||||
protected final Dimension size = new Dimension();
|
||||
|
||||
protected boolean created = false;
|
||||
protected int screenHeight = 0;
|
||||
|
||||
protected abstract void createLines();
|
||||
|
||||
protected boolean needsUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
ensureCreated();
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
if (this.size.height == 0) return;
|
||||
|
||||
for (ItemsTooltipLineHandler line : this.lines) {
|
||||
line.draw(x, y);
|
||||
y += line.getSize().height;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ensureCreated() {
|
||||
boolean update = needsUpdate();
|
||||
update = this.screenHeight != (this.screenHeight = GuiDraw.displaySize().height) || update;
|
||||
|
||||
if (this.created && !update) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.created = true;
|
||||
this.lines.clear();
|
||||
this.size.setSize(0, 0);
|
||||
|
||||
createLines();
|
||||
fitToScreen();
|
||||
|
||||
for (ItemsTooltipLineHandler line : this.lines) {
|
||||
this.size.width = Math.max(this.size.width, line.getSize().width);
|
||||
this.size.height += line.getSize().height;
|
||||
}
|
||||
}
|
||||
|
||||
protected void fitToScreen() {
|
||||
if (this.lines.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<ItemsTooltipLineHandler> ordered = new ArrayList<>(this.lines);
|
||||
ordered.sort(Comparator.comparingInt(ItemsTooltipLineHandler::getRows));
|
||||
|
||||
int budget = availableHeight() / ItemsTooltipLineHandler.SLOT_SIZE;
|
||||
int rest = ordered.size();
|
||||
|
||||
for (ItemsTooltipLineHandler line : ordered) {
|
||||
final int fair = Math.max(1, budget / rest);
|
||||
|
||||
if (line.getRows() > fair) {
|
||||
line.setMaxRows(fair);
|
||||
}
|
||||
|
||||
budget -= line.getRows();
|
||||
rest--;
|
||||
}
|
||||
}
|
||||
|
||||
protected int availableHeight() {
|
||||
return GuiDraw.displaySize().height - SCREEN_MARGIN
|
||||
- RESERVED_HEIGHT
|
||||
- this.lines.size() * ItemsTooltipLineHandler.headerHeight();
|
||||
}
|
||||
|
||||
protected static int maxLineRows() {
|
||||
final int height = GuiDraw.displaySize().height - SCREEN_MARGIN
|
||||
- RESERVED_HEIGHT
|
||||
- ItemsTooltipLineHandler.headerHeight();
|
||||
return Math.max(1, height / ItemsTooltipLineHandler.SLOT_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -16,13 +16,13 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
@@ -32,7 +32,6 @@ import codechicken.nei.api.API;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.RecipeHandlerRef;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
@@ -93,7 +92,7 @@ public class FavoriteRecipes {
|
||||
for (int i = 0; i < handler.numRecipes(); i++) {
|
||||
RecipeHandlerRef ref = null;
|
||||
|
||||
for (PositionedStack result : getOutputs(handler, i)) {
|
||||
for (PositionedStack result : handler.getResultStacks(i)) {
|
||||
ItemStack stack = StackInfo.getItemStackWithMinimumDamage(result.items);
|
||||
final FastKey key = new FastKey(stack);
|
||||
|
||||
@@ -128,11 +127,6 @@ public class FavoriteRecipes {
|
||||
updateSubsetVisibility();
|
||||
}
|
||||
|
||||
protected List<PositionedStack> getOutputs(IRecipeHandler handler, int recipeIndex) {
|
||||
final PositionedStack pStackResult = handler.getResultStack(recipeIndex);
|
||||
return pStackResult != null ? Collections.singletonList(pStackResult) : handler.getOtherStacks(recipeIndex);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final String FAVORITE_ITEM = "FavoriteItem";
|
||||
@@ -242,14 +236,7 @@ public class FavoriteRecipes {
|
||||
|
||||
if (hasErrors) {
|
||||
|
||||
try {
|
||||
Files.copy(
|
||||
favoriteFile,
|
||||
new File(favoriteFile.getAbsolutePath() + ".backup-" + System.currentTimeMillis()));
|
||||
NEIClientConfig.logger.info("Backed up invalid favorite file to {}", favoriteFile);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to backup invalid favorite file to {}", favoriteFile, e);
|
||||
}
|
||||
NEIClientUtils.backupFile(favoriteFile);
|
||||
|
||||
save();
|
||||
}
|
||||
@@ -314,6 +301,10 @@ public class FavoriteRecipes {
|
||||
load();
|
||||
}
|
||||
|
||||
public static boolean hasManual() {
|
||||
return manualFavorites.size() > 0;
|
||||
}
|
||||
|
||||
public static boolean containsManual(ItemStack stack) {
|
||||
return getManualFavorite(stack) != null;
|
||||
}
|
||||
@@ -322,6 +313,21 @@ public class FavoriteRecipes {
|
||||
return getFavorite(stack) != null;
|
||||
}
|
||||
|
||||
public static void toggleFavoriteItem(ItemStack stack) {
|
||||
if (stack == null) return;
|
||||
|
||||
if (containsManual(stack)) {
|
||||
setFavorite(stack, null);
|
||||
} else {
|
||||
setFavorite(
|
||||
stack,
|
||||
RecipeId.of(
|
||||
stack,
|
||||
FavoriteRecipes.FAVORITE_ITEM,
|
||||
Arrays.asList(new ItemStack(Blocks.fire, 1), stack)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFavorite(ItemStack stack, RecipeId recipeId) {
|
||||
if (stack == null) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
|
||||
final class GridOverlapScanner {
|
||||
|
||||
private static boolean scanRequested = true;
|
||||
private static boolean scanFrame = true;
|
||||
private static boolean wasShowTooltip = true;
|
||||
private static WeakReference<GuiContainer> lastGui = new WeakReference<>(null);
|
||||
|
||||
private boolean invalidated = true;
|
||||
|
||||
private final Rectangle4i rect = new Rectangle4i();
|
||||
private boolean[] checked = new boolean[0];
|
||||
private int[] queue = new int[0];
|
||||
private int tail;
|
||||
|
||||
private Predicate<Rectangle4i> isHidden;
|
||||
private boolean[] hidden;
|
||||
private int hiddenCount;
|
||||
private int left;
|
||||
private int top;
|
||||
private int slotSize;
|
||||
private int columns;
|
||||
|
||||
public static void requestScan() {
|
||||
scanRequested = true;
|
||||
}
|
||||
|
||||
public static void beginFrame(GuiContainer gui, boolean shouldShowTooltip) {
|
||||
|
||||
if (wasShowTooltip != shouldShowTooltip) {
|
||||
scanRequested = true;
|
||||
}
|
||||
|
||||
wasShowTooltip = shouldShowTooltip;
|
||||
|
||||
if (lastGui.get() != gui) {
|
||||
lastGui = new WeakReference<>(gui);
|
||||
scanRequested = true;
|
||||
}
|
||||
|
||||
scanFrame = scanRequested;
|
||||
scanRequested = false;
|
||||
}
|
||||
|
||||
public static boolean isScanFrame() {
|
||||
return scanFrame;
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.invalidated = true;
|
||||
}
|
||||
|
||||
public boolean shouldRefresh() {
|
||||
final boolean refresh = this.invalidated || scanFrame;
|
||||
this.invalidated = false;
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public int scan(Predicate<Rectangle4i> isHidden, int left, int top, int slotSize, int rows, int columns,
|
||||
boolean seedLeft, boolean seedRight, boolean[] hidden) {
|
||||
final int size = rows * columns;
|
||||
|
||||
if (this.checked.length < size) {
|
||||
this.checked = new boolean[size];
|
||||
this.queue = new int[size];
|
||||
} else {
|
||||
Arrays.fill(this.checked, 0, size, false);
|
||||
}
|
||||
|
||||
this.isHidden = isHidden;
|
||||
this.hidden = hidden;
|
||||
this.hiddenCount = 0;
|
||||
this.tail = 0;
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.slotSize = slotSize;
|
||||
this.columns = columns;
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
if (seedLeft) {
|
||||
probe(r, 0);
|
||||
}
|
||||
if (seedRight) {
|
||||
probe(r, columns - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int head = 0; head < this.tail; head++) {
|
||||
final int row = this.queue[head] / columns;
|
||||
final int column = this.queue[head] % columns;
|
||||
|
||||
for (int r = Math.max(0, row - 1); r <= Math.min(rows - 1, row + 1); r++) {
|
||||
for (int c = Math.max(0, column - 1); c <= Math.min(columns - 1, column + 1); c++) {
|
||||
probe(r, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int c = 0; c < columns; c++) {
|
||||
if (this.checked[r * columns + c]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int c1 = c;
|
||||
while (c1 + 1 < columns && !this.checked[r * columns + c1 + 1]) {
|
||||
c1++;
|
||||
}
|
||||
|
||||
int r1 = r;
|
||||
while (r1 + 1 < rows && isUnchecked(r1 + 1, c, c1)) {
|
||||
r1++;
|
||||
}
|
||||
|
||||
scanArea(r, r1, c, c1);
|
||||
c = c1;
|
||||
}
|
||||
}
|
||||
|
||||
this.isHidden = null;
|
||||
this.hidden = null;
|
||||
|
||||
return this.hiddenCount;
|
||||
}
|
||||
|
||||
private void probe(int row, int column) {
|
||||
final int idx = row * this.columns + column;
|
||||
|
||||
if (!this.checked[idx]) {
|
||||
this.checked[idx] = true;
|
||||
|
||||
if (test(row, row, column, column)) {
|
||||
this.hidden[idx] = true;
|
||||
this.queue[this.tail++] = idx;
|
||||
this.hiddenCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void scanArea(int r0, int r1, int c0, int c1) {
|
||||
|
||||
if (!test(r0, r1, c0, c1)) {
|
||||
for (int r = r0; r <= r1; r++) {
|
||||
Arrays.fill(this.checked, r * this.columns + c0, r * this.columns + c1 + 1, true);
|
||||
}
|
||||
} else if (r0 == r1 && c0 == c1) {
|
||||
this.checked[r0 * this.columns + c0] = true;
|
||||
this.hidden[r0 * this.columns + c0] = true;
|
||||
this.hiddenCount++;
|
||||
} else if (r1 - r0 >= c1 - c0) {
|
||||
final int mid = (r0 + r1) / 2;
|
||||
scanArea(r0, mid, c0, c1);
|
||||
scanArea(mid + 1, r1, c0, c1);
|
||||
} else {
|
||||
final int mid = (c0 + c1) / 2;
|
||||
scanArea(r0, r1, c0, mid);
|
||||
scanArea(r0, r1, mid + 1, c1);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUnchecked(int row, int c0, int c1) {
|
||||
for (int c = c0; c <= c1; c++) {
|
||||
if (this.checked[row * this.columns + c]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean test(int r0, int r1, int c0, int c1) {
|
||||
this.rect.set(
|
||||
this.left + c0 * this.slotSize,
|
||||
this.top + r0 * this.slotSize,
|
||||
(c1 - c0 + 1) * this.slotSize,
|
||||
(r1 - r0 + 1) * this.slotSize);
|
||||
return this.isHidden.test(this.rect);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,40 +7,36 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
|
||||
public class GuiNEIButton extends GuiButton {
|
||||
|
||||
protected static final ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
|
||||
private static final DrawableResource[] BACKGROUNDS = new DrawableResource[3];
|
||||
|
||||
static {
|
||||
for (int state = 0; state < BACKGROUNDS.length; state++) {
|
||||
BACKGROUNDS[state] = new DrawableBuilder(guiTex, 0, 46 + state * 20, 200, 20).setSlices(2, 2, 2, 2).build();
|
||||
}
|
||||
}
|
||||
|
||||
public GuiNEIButton(int i, int j, int k, int l, int i1, String s) {
|
||||
super(i, j, k, l, i1, s);
|
||||
}
|
||||
|
||||
protected DrawableResource getBackground(int mouseX, int mouseY, boolean mouseOver) {
|
||||
return BACKGROUNDS[getHoverState(mouseOver)];
|
||||
}
|
||||
|
||||
public void drawButton(Minecraft minecraft, int x, int y) {
|
||||
if (!visible) return;
|
||||
|
||||
minecraft.renderEngine.bindTexture(guiTex);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
boolean mouseOver = x >= xPosition && y >= yPosition && x < xPosition + width && y < yPosition + height;
|
||||
int k = getHoverState(mouseOver);
|
||||
drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height / 2); // top left
|
||||
drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height / 2); // top
|
||||
// right
|
||||
drawTexturedModalRect(
|
||||
xPosition,
|
||||
yPosition + height / 2,
|
||||
0,
|
||||
46 + k * 20 + 20 - height / 2,
|
||||
width / 2,
|
||||
height / 2); // bottom left
|
||||
drawTexturedModalRect(
|
||||
xPosition + width / 2,
|
||||
yPosition + height / 2,
|
||||
200 - width / 2,
|
||||
46 + k * 20 + 20 - height / 2,
|
||||
width / 2,
|
||||
height / 2); // bottom right
|
||||
mouseDragged(minecraft, x, y);
|
||||
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
getBackground(x, y, mouseOver).draw(xPosition, yPosition, width, height);
|
||||
mouseDragged(minecraft, x, y);
|
||||
drawContent(minecraft, x, y, mouseOver);
|
||||
}
|
||||
|
||||
@@ -55,7 +51,7 @@ public class GuiNEIButton extends GuiButton {
|
||||
return ColorUtils.buttonLabelNormal.getColor();
|
||||
}
|
||||
|
||||
protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) {
|
||||
protected void drawContent(Minecraft minecraft, int x, int y, boolean mouseOver) {
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
int color = getTextColour(mouseOver);
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
@@ -82,6 +84,42 @@ public class ItemCraftablesPanel
|
||||
|
||||
}
|
||||
|
||||
private static class CraftablesSnapshot {
|
||||
|
||||
final GuiContainer guiContainer;
|
||||
final ItemStackAmount inventory;
|
||||
final boolean showOnlyFavorites;
|
||||
final int maxCandidates;
|
||||
|
||||
CraftablesSnapshot(GuiContainer guiContainer, ItemStackAmount inventory, boolean showOnlyFavorites,
|
||||
int maxCandidates) {
|
||||
this.guiContainer = guiContainer;
|
||||
this.inventory = inventory;
|
||||
this.showOnlyFavorites = showOnlyFavorites;
|
||||
this.maxCandidates = maxCandidates;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RecipeCandidate {
|
||||
|
||||
final IRecipeHandler handler;
|
||||
final int recipeIndex;
|
||||
final List<PositionedStack> ingredientStacks;
|
||||
final ItemStack sortKeyItem;
|
||||
|
||||
RecipeCandidate(IRecipeHandler handler, int recipeIndex, List<PositionedStack> ingredientStacks,
|
||||
ItemStack sortKeyItem) {
|
||||
this.handler = handler;
|
||||
this.recipeIndex = recipeIndex;
|
||||
this.ingredientStacks = ingredientStacks;
|
||||
this.sortKeyItem = sortKeyItem;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<ItemStack> ITEM_SORT_COMPARATOR = Comparator
|
||||
.comparing(FavoriteRecipes::containsManual).thenComparing(FavoriteRecipes::contains).reversed()
|
||||
.thenComparing(ItemSorter.instance);
|
||||
|
||||
public static List<String> guiBlacklist = new ArrayList<>();
|
||||
private final int MIN_DELAY = 600;
|
||||
|
||||
@@ -93,6 +131,20 @@ public class ItemCraftablesPanel
|
||||
private long lastPlayerInventorySync = 0;
|
||||
private int lastFavoritesCount = 0;
|
||||
|
||||
private volatile CraftablesSnapshot pendingSnapshot;
|
||||
private final AtomicReference<Map<ItemStack, RecipeId>> pendingResult = new AtomicReference<>();
|
||||
private final RestartableTask task = new RestartableTask("NEI Craftables Panel") {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
final CraftablesSnapshot snapshot = ItemCraftablesPanel.this.pendingSnapshot;
|
||||
|
||||
if (snapshot != null) {
|
||||
pendingResult.set(generateCraftables(snapshot));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ItemCraftablesPanel() {
|
||||
this.grid = new ItemsGrid<>() {
|
||||
|
||||
@@ -114,12 +166,7 @@ public class ItemCraftablesPanel
|
||||
|
||||
if (!ItemCraftablesPanel.this.availableRecipes.isEmpty()) {
|
||||
final List<Map.Entry<ItemStack, RecipeId>> entries = ItemCraftablesPanel.this.availableRecipes
|
||||
.entrySet().stream()
|
||||
.sorted(
|
||||
Map.Entry.comparingByKey(
|
||||
Comparator.comparing(FavoriteRecipes::containsManual)
|
||||
.thenComparing(FavoriteRecipes::contains).reversed()
|
||||
.thenComparing(ItemSorter.instance)))
|
||||
.entrySet().stream().sorted(Map.Entry.comparingByKey(ITEM_SORT_COMPARATOR))
|
||||
.limit(maxSlotIndex).collect(Collectors.toList());
|
||||
int slotIndex = 0;
|
||||
int itemIndex = 0;
|
||||
@@ -195,10 +242,20 @@ public class ItemCraftablesPanel
|
||||
|
||||
public void update() {
|
||||
this.splittingLineColor = NEIClientConfig.getSetting("inventory.craftables.color").getHexValue();
|
||||
applyPendingResult();
|
||||
updateCraftables();
|
||||
super.update();
|
||||
}
|
||||
|
||||
private void applyPendingResult() {
|
||||
final Map<ItemStack, RecipeId> result = this.pendingResult.getAndSet(null);
|
||||
|
||||
if (result != null && NEIClientConfig.showCraftablesPanelWidget()) {
|
||||
this.availableRecipes = result;
|
||||
this.grid.onGridChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCraftables() {
|
||||
|
||||
if (!NEIClientConfig.showCraftablesPanelWidget()) {
|
||||
@@ -219,8 +276,14 @@ public class ItemCraftablesPanel
|
||||
this.lastPlayerInventory = inv;
|
||||
this.lastGuiContainer = firstGui;
|
||||
this.lastFavoritesCount = FavoriteRecipes.size();
|
||||
this.availableRecipes = generateCraftables(firstGui);
|
||||
this.grid.onGridChanged();
|
||||
final int maxRows = NEIClientConfig.getIntSetting("inventory.craftables.useRows") + 2;
|
||||
final int maxCandidates = Math.max(this.grid.columns, 1) * maxRows;
|
||||
this.pendingSnapshot = new CraftablesSnapshot(
|
||||
firstGui,
|
||||
inv,
|
||||
showOnlyFavorites,
|
||||
maxCandidates);
|
||||
this.task.restart();
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -239,22 +302,38 @@ public class ItemCraftablesPanel
|
||||
}
|
||||
}
|
||||
|
||||
public void clearGuiReferences() {
|
||||
this.lastGuiContainer = null;
|
||||
this.pendingSnapshot = null;
|
||||
}
|
||||
|
||||
private GuiContainer getGuiContainer() {
|
||||
final GuiContainer firstGui = NEIClientUtils.getGuiContainer();
|
||||
return (firstGui instanceof GuiRecipe<?>gui) ? gui.firstGui : firstGui;
|
||||
}
|
||||
|
||||
private Map<ItemStack, RecipeId> generateCraftables(GuiContainer firstGui) {
|
||||
final List<IRecipeHandler> availableHandlers = getAvailableHandlers(firstGui);
|
||||
private Map<ItemStack, RecipeId> generateCraftables(CraftablesSnapshot snapshot) {
|
||||
final List<IRecipeHandler> availableHandlers = getAvailableHandlers(snapshot.guiContainer);
|
||||
final Map<ItemStack, RecipeId> availableRecipes = new HashMap<>();
|
||||
|
||||
if (!availableHandlers.isEmpty()) {
|
||||
final List<ItemStack> invStacks = ItemCraftablesPanel.this.lastPlayerInventory.values();
|
||||
final Map<Item, List<ItemStack>> invByItem = indexInventoryByItem(snapshot.inventory.values());
|
||||
|
||||
for (IRecipeHandler handler : availableHandlers) {
|
||||
availableRecipes.putAll(filterHandlerRecipes(handler, firstGui, invStacks));
|
||||
if (snapshot.showOnlyFavorites) {
|
||||
for (IRecipeHandler handler : availableHandlers) {
|
||||
availableRecipes.putAll(filterHandlerRecipes(handler, invByItem, true));
|
||||
}
|
||||
} else {
|
||||
final List<RecipeCandidate> candidates = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
for (IRecipeHandler handler : availableHandlers) {
|
||||
collectHandlerCandidates(handler, invByItem, candidates);
|
||||
}
|
||||
|
||||
candidates.sort(Comparator.comparing(c -> c.sortKeyItem, ITEM_SORT_COMPARATOR));
|
||||
candidates.subList(0, Math.min(candidates.size(), snapshot.maxCandidates)).parallelStream()
|
||||
.forEach(candidate -> buildCandidate(candidate, availableRecipes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return availableRecipes;
|
||||
@@ -270,19 +349,97 @@ public class ItemCraftablesPanel
|
||||
return availableHandlers;
|
||||
}
|
||||
|
||||
private Map<ItemStack, RecipeId> filterHandlerRecipes(IRecipeHandler handler, GuiContainer firstGui,
|
||||
List<ItemStack> invStacks) {
|
||||
private static Map<Item, List<ItemStack>> indexInventoryByItem(List<ItemStack> invStacks) {
|
||||
final Map<Item, List<ItemStack>> index = new HashMap<>();
|
||||
|
||||
for (ItemStack stack : invStacks) {
|
||||
index.computeIfAbsent(stack.getItem(), i -> new ArrayList<>()).add(stack);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private void collectHandlerCandidates(IRecipeHandler handler, Map<Item, List<ItemStack>> invByItem,
|
||||
List<RecipeCandidate> candidates) {
|
||||
IntStream.range(0, handler.numRecipes()).parallel().forEach(recipeIndex -> {
|
||||
final List<PositionedStack> ingredientStacks = handler.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (existsIngredients(ingredientStacks, invByItem)) {
|
||||
final ItemStack sortKeyItem = getCheapResultItem(handler, recipeIndex);
|
||||
|
||||
if (sortKeyItem != null) {
|
||||
candidates.add(new RecipeCandidate(handler, recipeIndex, ingredientStacks, sortKeyItem));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void buildCandidate(RecipeCandidate candidate, Map<ItemStack, RecipeId> availableRecipes) {
|
||||
final ItemStack result = getCheapResult(candidate.handler, candidate.recipeIndex);
|
||||
|
||||
if (result != null) {
|
||||
final RecipeId recipeId = RecipeId.of(candidate.handler, candidate.recipeIndex, candidate.ingredientStacks);
|
||||
|
||||
synchronized (availableRecipes) {
|
||||
availableRecipes.put(result, recipeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack getCheapResultItem(IRecipeHandler handler, int recipeIndex) {
|
||||
final PositionedStack result = Recipe
|
||||
.getMainResult(handler.getResultStacks(recipeIndex), pStack -> pStack.items[0]);
|
||||
return result != null ? result.item : null;
|
||||
}
|
||||
|
||||
private static ItemStack getCheapResult(IRecipeHandler handler, int recipeIndex) {
|
||||
final List<PositionedStack> results = handler.getResultStacks(recipeIndex);
|
||||
|
||||
if (results.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack stack = Recipe.getMainResult(results, pStack -> pStack.items[0]).item;
|
||||
int stackSize = 0;
|
||||
|
||||
for (PositionedStack result : results) {
|
||||
if (containsSameType(result, stack)) {
|
||||
stackSize += StackInfo.getAmount(result.item);
|
||||
}
|
||||
}
|
||||
|
||||
return StackInfo.withAmount(stack, stackSize);
|
||||
}
|
||||
|
||||
private static boolean containsSameType(PositionedStack pStack, ItemStack stack) {
|
||||
final ItemStack normalized = StackInfo.withAmount(stack, 0);
|
||||
|
||||
for (ItemStack permutation : pStack.items) {
|
||||
if (NEIServerUtils.areStacksSameTypeWithNBT(StackInfo.withAmount(permutation, 0), normalized)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Map<ItemStack, RecipeId> filterHandlerRecipes(IRecipeHandler handler, Map<Item, List<ItemStack>> invByItem,
|
||||
boolean showOnlyFavorites) {
|
||||
final Map<ItemStack, RecipeId> availableRecipes = new HashMap<>();
|
||||
final boolean showOnlyFavorites = NEIClientConfig.getBooleanSetting("inventory.craftables.favoritesOnly");
|
||||
|
||||
IntStream.range(0, handler.numRecipes()).parallel().forEach(recipeIndex -> {
|
||||
if (existsIngredients(firstGui, handler.getIngredientStacks(recipeIndex), invStacks)) {
|
||||
final Recipe recipe = Recipe.of(handler, recipeIndex);
|
||||
final List<PositionedStack> ingredientStacks = handler.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (!recipe.getResults().isEmpty()
|
||||
&& (!showOnlyFavorites || FavoriteRecipes.getFavorite(recipe.getRecipeId()) != null)) {
|
||||
synchronized (availableRecipes) {
|
||||
availableRecipes.put(recipe.getResult(), recipe.getRecipeId());
|
||||
if (existsIngredients(ingredientStacks, invByItem)) {
|
||||
final ItemStack result = getCheapResult(handler, recipeIndex);
|
||||
|
||||
if (result != null) {
|
||||
final RecipeId recipeId = RecipeId.of(handler, recipeIndex, ingredientStacks);
|
||||
|
||||
if (!showOnlyFavorites || FavoriteRecipes.getFavorite(recipeId) != null) {
|
||||
synchronized (availableRecipes) {
|
||||
availableRecipes.put(result, recipeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,14 +448,27 @@ public class ItemCraftablesPanel
|
||||
return availableRecipes;
|
||||
}
|
||||
|
||||
private boolean existsIngredients(GuiContainer firstGui, List<PositionedStack> ingredients,
|
||||
List<ItemStack> invStacks) {
|
||||
private boolean existsIngredients(List<PositionedStack> ingredients, Map<Item, List<ItemStack>> invByItem) {
|
||||
final Map<ItemStack, Integer> usedItems = new HashMap<>();
|
||||
|
||||
for (PositionedStack pStack : ingredients) {
|
||||
final ItemStack used = invStacks.stream().filter(
|
||||
is -> usedItems.getOrDefault(is, is.stackSize) >= pStack.item.stackSize && pStack.contains(is))
|
||||
.findAny().orElse(null);
|
||||
ItemStack used = null;
|
||||
|
||||
for (ItemStack permutation : pStack.items) {
|
||||
final List<ItemStack> candidates = invByItem.get(permutation.getItem());
|
||||
|
||||
if (candidates == null) continue;
|
||||
|
||||
for (ItemStack is : candidates) {
|
||||
if (usedItems.getOrDefault(is, is.stackSize) >= pStack.item.stackSize
|
||||
&& NEIServerUtils.areStacksSameTypeCrafting(permutation, is)) {
|
||||
used = is;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (used != null) break;
|
||||
}
|
||||
|
||||
if (used != null) {
|
||||
usedItems.put(used, usedItems.getOrDefault(used, used.stackSize) - pStack.item.stackSize);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
@@ -103,7 +104,7 @@ public class ItemList {
|
||||
}
|
||||
|
||||
for (String alias : ItemInfo.getAliases(item)) {
|
||||
if (this.pattern.matcher(alias).find()) {
|
||||
if (this.pattern.matcher(StatCollector.translateToLocal(alias)).find()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -206,6 +207,33 @@ public class ItemList {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public static ItemStack[] expandPermutations(ItemStack[] items) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
for (ItemStack item : items) {
|
||||
if (item == null || item.getItem() == null) continue;
|
||||
|
||||
if (item.getItemDamage() == Short.MAX_VALUE) {
|
||||
List<ItemStack> permutations = itemMap.get(item.getItem());
|
||||
if (!permutations.isEmpty()) {
|
||||
for (ItemStack stack : permutations) {
|
||||
ItemStack toAdd = stack.copy();
|
||||
toAdd.stackSize = item.stackSize;
|
||||
stacks.add(toAdd);
|
||||
}
|
||||
} else {
|
||||
ItemStack base = new ItemStack(item.getItem(), item.stackSize);
|
||||
base.stackTagCompound = item.stackTagCompound;
|
||||
stacks.add(base);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
stacks.add(item.copy());
|
||||
}
|
||||
|
||||
return stacks.toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
public static ForkJoinPool forkJoinPool;
|
||||
|
||||
static {
|
||||
|
||||
@@ -36,7 +36,6 @@ import cpw.mods.fml.common.FMLLog;
|
||||
public class ItemListLoader {
|
||||
|
||||
private static final HashSet<Item> erroredItems = new HashSet<>();
|
||||
private static final HashSet<String> stackTraces = new HashSet<>();
|
||||
private static Map<ItemStack, Integer> ordering = new HashMap<>();
|
||||
|
||||
private ItemListLoader() {}
|
||||
@@ -60,11 +59,10 @@ public class ItemListLoader {
|
||||
} catch (TimeoutException t) {
|
||||
throw t;
|
||||
} catch (Throwable t) {
|
||||
NEIServerUtils.logOnce(
|
||||
t,
|
||||
stackTraces,
|
||||
NEIClientUtils.errorOnce(
|
||||
"ItemListLoader: " + item.toString(),
|
||||
"Ommiting " + item + ":" + damage + " " + item.getClass().getSimpleName(),
|
||||
item.toString());
|
||||
t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,13 +75,7 @@ public class ItemPanel extends PanelWidget<ItemsPanelGrid> {
|
||||
}
|
||||
|
||||
public static void updateItemList(ArrayList<ItemStack> newItems) {
|
||||
final ItemsPanelGrid grid = ItemPanels.itemPanel.getGrid();
|
||||
|
||||
if (grid.rawItems.size() != newItems.size()) {
|
||||
grid.setPage(0);
|
||||
}
|
||||
|
||||
grid.setItems(newItems);
|
||||
ItemPanels.itemPanel.getGrid().setItems(newItems);
|
||||
ItemPanels.itemPanel.realItems = newItems;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,14 +118,7 @@ public class ItemSorter implements Comparator<ItemStack> {
|
||||
return name1.compareTo(name2);
|
||||
});
|
||||
tag.getTag("inventory.itemsort").setDefaultValue(getSaveString(list));
|
||||
API.addOption(new OptionOpenGui("inventory.itemsort", GuiItemSorter.class) {
|
||||
|
||||
@Override
|
||||
public void useGlobals() {
|
||||
super.useGlobals();
|
||||
list = fromSaveString(activeTag().getValue());
|
||||
}
|
||||
});
|
||||
API.addOption(new OptionOpenGui("inventory.itemsort", GuiItemSorter.class));
|
||||
}
|
||||
|
||||
public static String getSaveString(List<SortEntry> list) {
|
||||
|
||||
@@ -111,8 +111,14 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
|
||||
this.xPosition = (availableAreaWidth - this.scale * SLOT_SIZE) / 2;
|
||||
this.availableAreaWidth = (int) (availableAreaWidth / screenScale);
|
||||
|
||||
if (availableAreaWidth / screenScale >= mouse.x) {
|
||||
this.xPosition += gui.width * screenScale - availableAreaWidth;
|
||||
final float rightSideShift = gui.width * screenScale - availableAreaWidth;
|
||||
final boolean leftSideFree = availableAreaWidth / screenScale < mouse.x;
|
||||
final boolean rightSideFree = mouse.x < gui.width - availableAreaWidth / screenScale;
|
||||
|
||||
final boolean showOnRight = leftSideFree && rightSideFree ? !preferLeftSide() : !leftSideFree;
|
||||
|
||||
if (showOnRight) {
|
||||
this.xPosition += rightSideShift;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -121,13 +127,34 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
|
||||
this.displayName = "Unnamed";
|
||||
}
|
||||
|
||||
this.stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack), 0);
|
||||
// Copying the stack copies its whole NBT, so it is only done when the hovered stack changes
|
||||
final boolean sameStack = this.stack != null && this.stack.isItemEqual(stack)
|
||||
&& ItemStack.areItemStackTagsEqual(this.stack, stack);
|
||||
if (!sameStack) {
|
||||
this.stack = StackInfo.withAmount(stack, 0);
|
||||
}
|
||||
} else {
|
||||
this.stack = null;
|
||||
this.displayName = "";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean preferLeftSide() {
|
||||
switch (NEIClientConfig.getIntSetting("inventory.itemzoom.preferredSide")) {
|
||||
case 1:
|
||||
return true;
|
||||
case 2:
|
||||
return false;
|
||||
}
|
||||
|
||||
final int leftCount = NEIClientConfig.isBookmarkPanelHidden()
|
||||
|| ItemPanels.bookmarkPanel.getGrid().getPerPage() == 0 ? 0 : ItemPanels.bookmarkPanel.getGrid().size();
|
||||
final int rightCount = ItemPanels.itemPanel.getGrid().getPerPage() == 0 ? 0
|
||||
: ItemPanels.itemPanel.getGrid().size();
|
||||
|
||||
return leftCount <= rightCount;
|
||||
}
|
||||
|
||||
private float getPointSize(GuiContainer gui) {
|
||||
final float screenScale = 1.0f / getScreenScale();
|
||||
final float availableAreaWidth = (gui.width - (gui.xSize + gui.width) / 2) * screenScale;
|
||||
@@ -197,6 +224,11 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
|
||||
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed(GuiContainer gui) {
|
||||
|
||||
if (KeyManager.isHashDown("itemzoom.toggle", NEIClientUtils.SHIFT_HASH)) {
|
||||
NEIClientConfig.getSetting("inventory.itemzoom.enabled")
|
||||
|
||||
@@ -282,6 +282,8 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
|
||||
protected boolean[] invalidSlotMap;
|
||||
|
||||
private final GridOverlapScanner overlapScanner = new GridOverlapScanner();
|
||||
|
||||
protected ScreenCapture screenCapture = null;
|
||||
|
||||
public ArrayList<ItemStack> getItems() {
|
||||
@@ -359,12 +361,13 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
width = newWidth;
|
||||
height = newHeight;
|
||||
|
||||
columns = width / SLOT_SIZE;
|
||||
rows = height / SLOT_SIZE;
|
||||
this.columns = newWidth / SLOT_SIZE;
|
||||
this.rows = newHeight / SLOT_SIZE;
|
||||
|
||||
paddingLeft = (width % SLOT_SIZE) / 2;
|
||||
|
||||
if (changed) {
|
||||
this.overlapScanner.invalidate();
|
||||
onGridChanged();
|
||||
}
|
||||
}
|
||||
@@ -405,55 +408,42 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
}
|
||||
|
||||
public void refresh(GuiContainer gui) {
|
||||
final int gridRenderingCacheMode = getGridRenderingCacheMode();
|
||||
if (gridRenderingCacheMode <= 0 || screenCapture == null || screenCapture.needRefresh(gridRenderingCacheMode)) {
|
||||
if (this.overlapScanner.shouldRefresh()) {
|
||||
updateGuiOverlapSlots(gui);
|
||||
}
|
||||
shiftPage(0);
|
||||
}
|
||||
|
||||
protected void updateGuiOverlapSlots(GuiContainer gui) {
|
||||
final boolean[] oldSlotMap = invalidSlotMap;
|
||||
final int oldRows = rows;
|
||||
final int oldColumns = columns;
|
||||
final boolean[] oldSlotMap = this.invalidSlotMap;
|
||||
final int size = this.rows * this.columns;
|
||||
final boolean[] slotMap = new boolean[size];
|
||||
|
||||
invalidSlotMap = new boolean[rows * columns];
|
||||
perPage = columns * rows;
|
||||
this.perPage = size;
|
||||
|
||||
if (gui != null) {
|
||||
if (gui != null && size > 0) {
|
||||
final INEIGuiHandler[] handlers = GuiInfo.getGuiHandlersSnapshot();
|
||||
if (NEIClientConfig.optimizeGuiOverlapComputation()) {
|
||||
checkGuiOverlap(gui, handlers, 0, columns - 2, 1);
|
||||
checkGuiOverlap(gui, handlers, columns - 1, 1, -1);
|
||||
} else {
|
||||
checkGuiOverlap(gui, handlers, 0, columns, 1);
|
||||
}
|
||||
final Rectangle4i origin = getSlotRect(0, 0);
|
||||
|
||||
this.perPage -= this.overlapScanner.scan(
|
||||
rect -> GuiInfo.hideItemPanelSlot(gui, rect, handlers),
|
||||
origin.x,
|
||||
origin.y,
|
||||
SLOT_SIZE,
|
||||
this.rows,
|
||||
this.columns,
|
||||
origin.x + this.columns * SLOT_SIZE > gui.guiLeft,
|
||||
origin.x < gui.guiLeft + gui.xSize,
|
||||
slotMap);
|
||||
}
|
||||
|
||||
if (oldRows != rows || oldColumns != columns || !Arrays.equals(oldSlotMap, invalidSlotMap)) {
|
||||
this.invalidSlotMap = slotMap;
|
||||
|
||||
if (!Arrays.equals(oldSlotMap, slotMap)) {
|
||||
onGridChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkGuiOverlap(GuiContainer gui, INEIGuiHandler[] handlers, int start, int end, int dir) {
|
||||
boolean validColumn = false;
|
||||
|
||||
for (int c = start; c != end && (!NEIClientConfig.optimizeGuiOverlapComputation() || !validColumn); c += dir) {
|
||||
validColumn = true;
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
final int idx = columns * r + c;
|
||||
if (idx >= 0 && idx < invalidSlotMap.length
|
||||
&& !invalidSlotMap[idx]
|
||||
&& GuiInfo.hideItemPanelSlot(gui, getSlotRect(r, c), handlers)) {
|
||||
invalidSlotMap[idx] = true;
|
||||
validColumn = false;
|
||||
perPage--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T getSlotMouseOver(int mousex, int mousey) {
|
||||
if (!contains(mousex, mousey)) {
|
||||
return null;
|
||||
|
||||
@@ -89,6 +89,10 @@ public class ItemsPanelGrid extends ItemsGrid<ItemsPanelGrid.ItemsPanelGridSlot,
|
||||
public void refresh(GuiContainer gui) {
|
||||
|
||||
if (this.newItems != null) {
|
||||
if (this.rawItems.size() != this.newItems.size()) {
|
||||
this.page = 0;
|
||||
}
|
||||
|
||||
this.groupItems.clear();
|
||||
this.itemToGroup.clear();
|
||||
this.forceExpand = false;
|
||||
|
||||
@@ -4,6 +4,7 @@ import static codechicken.lib.gui.GuiDraw.fontRenderer;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -17,56 +18,265 @@ import org.lwjgl.opengl.GL12;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.NEIClientUtils.Alignment;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.util.ReadableNumberConverter;
|
||||
|
||||
public class ItemsTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
protected static final int SLOT_SIZE = 18;
|
||||
protected static final int MAX_COLUMNS = 11;
|
||||
protected static final int MARGIN_TOP = 2;
|
||||
@FunctionalInterface
|
||||
public interface AmountRenderer {
|
||||
|
||||
protected String label;
|
||||
protected EnumChatFormatting labelColor = EnumChatFormatting.GRAY;
|
||||
protected List<ItemStack> items;
|
||||
protected int activeStackIndex = -1;
|
||||
protected Dimension size = new Dimension();
|
||||
protected boolean saveStackSize = false;
|
||||
protected int columns = 0;
|
||||
protected int count = 0;
|
||||
protected int rows = 0;
|
||||
protected int length = 0;
|
||||
|
||||
public ItemsTooltipLineHandler(String label, List<ItemStack> items) {
|
||||
this(label, items, true, 5);
|
||||
void draw(int x, int y, ItemStack stack, long amount);
|
||||
}
|
||||
|
||||
public ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows) {
|
||||
this.label = label;
|
||||
this.items = groupingItemStacks(items);
|
||||
this.saveStackSize = saveStackSize;
|
||||
this.length = this.items.size();
|
||||
public static class NoAmountRenderer implements AmountRenderer {
|
||||
|
||||
if (this.length > 0) {
|
||||
this.columns = Math.min(MAX_COLUMNS, this.length);
|
||||
this.rows = Math.min(maxRows, (int) Math.ceil((float) this.length / this.columns));
|
||||
@Override
|
||||
public void draw(int x, int y, ItemStack stack, long amount) {
|
||||
GuiContainerManager.drawItem(x, y, stack, true, "");
|
||||
}
|
||||
|
||||
this.size.width = Math.max(this.columns * SLOT_SIZE, fontRenderer.getStringWidth(this.label) + 15);
|
||||
this.size.height = this.rows * SLOT_SIZE + fontRenderer.FONT_HEIGHT + 2 + MARGIN_TOP;
|
||||
protected static void drawAmountText(String text, Rectangle4i rect, int color, Alignment alignment) {
|
||||
NEIClientUtils.drawNEIOverlayText(text, rect, 1, color, true, alignment);
|
||||
}
|
||||
}
|
||||
|
||||
this.count = Math.min(
|
||||
this.length,
|
||||
Math.min(
|
||||
this.columns * this.rows,
|
||||
this.length > MAX_COLUMNS * maxRows ? (MAX_COLUMNS * maxRows) : Integer.MAX_VALUE));
|
||||
public static class TotalAmountRenderer extends NoAmountRenderer {
|
||||
|
||||
if (this.items.size() > this.count) {
|
||||
String text = "+" + (this.items.size() - this.count);
|
||||
this.count -= (int) Math.ceil((float) (fontRenderer.getStringWidth(text) - 2) / SLOT_SIZE);
|
||||
private static class AmountText {
|
||||
|
||||
public final String text;
|
||||
public final Alignment alignment;
|
||||
|
||||
public AmountText(String text, Alignment alignment) {
|
||||
this.text = text;
|
||||
this.alignment = alignment;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<ItemStack, AmountText> cache = new IdentityHashMap<>();
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y, ItemStack stack, long amount) {
|
||||
super.draw(x, y, stack, amount);
|
||||
drawAmount(new Rectangle4i(x, y, SLOT_SIZE - 2, SLOT_SIZE - 2), stack, amount);
|
||||
}
|
||||
|
||||
protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) {
|
||||
final AmountText amountText = this.cache.computeIfAbsent(stack, key -> {
|
||||
final boolean isFluidDisplay = StackInfo.isFluidDisplayItem(key);
|
||||
final String text = formatAmount(key, amount);
|
||||
|
||||
return new AmountText(
|
||||
isFluidDisplay && !text.isEmpty() ? text + "L" : text,
|
||||
isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight);
|
||||
});
|
||||
|
||||
if (!amountText.text.isEmpty()) {
|
||||
drawAmountText(amountText.text, rect, 0xFFFFFF, amountText.alignment);
|
||||
}
|
||||
}
|
||||
|
||||
protected String formatAmount(ItemStack stack, long amount) {
|
||||
return amount == 0 ? "" : ReadableNumberConverter.INSTANCE.toWideReadableForm(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static class StacksAmountRenderer extends NoAmountRenderer {
|
||||
|
||||
private static class StacksText {
|
||||
|
||||
public final String stacks;
|
||||
public final String remainder;
|
||||
public final int color;
|
||||
|
||||
public StacksText(String stacks, String remainder, int color) {
|
||||
this.stacks = stacks;
|
||||
this.remainder = remainder;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<ItemStack, StacksText> cache = new IdentityHashMap<>();
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y, ItemStack stack, long amount) {
|
||||
super.draw(x, y, stack, amount);
|
||||
drawAmount(new Rectangle4i(x, y, SLOT_SIZE - 2, SLOT_SIZE - 2), stack, amount);
|
||||
}
|
||||
|
||||
protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) {
|
||||
final StacksText stacksText = this.cache.computeIfAbsent(stack, key -> formatAmount(key, amount));
|
||||
|
||||
if (!stacksText.stacks.isEmpty()) {
|
||||
drawAmountText(stacksText.stacks, rect, stacksText.color, Alignment.TopLeft);
|
||||
}
|
||||
|
||||
if (!stacksText.remainder.isEmpty()) {
|
||||
drawAmountText(stacksText.remainder, rect, stacksText.color, Alignment.BottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
private StacksText formatAmount(ItemStack stack, long amount) {
|
||||
final long stackSize = StackInfo.isFluidDisplayItem(stack) ? FLUID_STACK_SIZE
|
||||
: Math.max(1, stack.getMaxStackSize());
|
||||
final long stacks = amount / stackSize;
|
||||
final long remainder = amount % stackSize;
|
||||
final String prefix = getPrefix(stack);
|
||||
|
||||
return new StacksText(
|
||||
stacks > 0 ? prefix + "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(stacks) : "",
|
||||
remainder > 0
|
||||
? (stacks > 0 ? "+" : prefix)
|
||||
+ ReadableNumberConverter.INSTANCE.toWideReadableForm(remainder)
|
||||
: "",
|
||||
getColor(stack));
|
||||
}
|
||||
|
||||
protected String getPrefix(ItemStack stack) {
|
||||
return "";
|
||||
}
|
||||
|
||||
protected int getColor(ItemStack stack) {
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final int SLOT_SIZE = 18;
|
||||
protected static final int ICON_SIZE = 16;
|
||||
protected static final int ICON_OFFSET = 1;
|
||||
protected static final int MAX_COLUMNS = 11;
|
||||
protected static final int MARGIN_TOP = 2;
|
||||
protected static final int LABEL_MARGIN = 15;
|
||||
protected static final int NAME_MARGIN = 2;
|
||||
protected static final int DEFAULT_MAX_ROWS = 5;
|
||||
protected static final int FLUID_STACK_SIZE = 144;
|
||||
|
||||
protected final List<ItemStack> items;
|
||||
protected final List<Long> amounts = new ArrayList<>();
|
||||
protected final List<String> names = new ArrayList<>();
|
||||
|
||||
protected AmountRenderer amountRenderer;
|
||||
|
||||
protected String label;
|
||||
protected EnumChatFormatting labelColor = EnumChatFormatting.GRAY;
|
||||
|
||||
protected int activeStackIndex = -1;
|
||||
protected Dimension size = new Dimension();
|
||||
|
||||
protected int maxNamedRows = Integer.MAX_VALUE;
|
||||
|
||||
protected int length = 0;
|
||||
protected int rows = 0;
|
||||
protected int nameRows = 0;
|
||||
protected int gridColumns = 0;
|
||||
protected int gridCount = 0;
|
||||
|
||||
public static ItemsTooltipLineHandler of(String label, List<ItemStack> items, int maxRows, int maxNamedRows) {
|
||||
return new ItemsTooltipLineHandler(label, items, true, maxRows, maxNamedRows);
|
||||
}
|
||||
|
||||
public ItemsTooltipLineHandler(String label, List<ItemStack> items) {
|
||||
this(label, items, true, DEFAULT_MAX_ROWS, 0);
|
||||
}
|
||||
|
||||
public ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows) {
|
||||
this(label, items, saveStackSize, maxRows, 0);
|
||||
}
|
||||
|
||||
protected ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows,
|
||||
int maxNamedRows) {
|
||||
this.label = label;
|
||||
this.items = groupingItemStacks(items);
|
||||
this.amountRenderer = saveStackSize ? new TotalAmountRenderer() : new NoAmountRenderer();
|
||||
this.length = this.items.size();
|
||||
this.maxNamedRows = maxNamedRows;
|
||||
|
||||
setMaxRows(maxRows);
|
||||
}
|
||||
|
||||
protected static int headerHeight() {
|
||||
return fontRenderer.FONT_HEIGHT + 2 + MARGIN_TOP;
|
||||
}
|
||||
|
||||
public ItemsTooltipLineHandler setMaxRows(int maxRows) {
|
||||
if (this.length == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.names.clear();
|
||||
this.nameRows = 0;
|
||||
|
||||
if (!layoutWithNames(maxRows)) {
|
||||
layoutAsGrid(maxRows);
|
||||
}
|
||||
|
||||
this.size.height = this.rows * SLOT_SIZE + headerHeight();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getRows() {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
protected boolean layoutWithNames(int maxRows) {
|
||||
final int maxNames = Math.min(this.maxNamedRows, this.length <= maxRows ? this.length : maxRows - 1);
|
||||
final int[] lineWidth = new int[maxNames + 1];
|
||||
lineWidth[0] = labelWidth();
|
||||
|
||||
for (int index = 0; index < maxNames; index++) {
|
||||
final String name = this.items.get(index).getDisplayName();
|
||||
this.names.add(name);
|
||||
lineWidth[index + 1] = Math
|
||||
.max(lineWidth[index], SLOT_SIZE + NAME_MARGIN + fontRenderer.getStringWidth(name));
|
||||
}
|
||||
|
||||
for (int named = maxNames; named >= 0; named--) {
|
||||
final int rest = this.length - named;
|
||||
final int width = Math.max(lineWidth[named], Math.min(rest, MAX_COLUMNS) * SLOT_SIZE);
|
||||
final int columns = Math.max(1, width / SLOT_SIZE);
|
||||
final int restRows = (int) Math.ceil((float) rest / columns);
|
||||
|
||||
if (named + restRows <= maxRows) {
|
||||
this.nameRows = named;
|
||||
this.gridColumns = columns;
|
||||
this.gridCount = rest;
|
||||
this.rows = named + restRows;
|
||||
this.size.width = width;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.names.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void layoutAsGrid(int maxRows) {
|
||||
this.gridColumns = Math.min(MAX_COLUMNS, this.length);
|
||||
this.rows = Math.min(maxRows, (int) Math.ceil((float) this.length / this.gridColumns));
|
||||
this.gridCount = Math.min(this.length, this.gridColumns * this.rows);
|
||||
this.size.width = Math.max(this.gridColumns * SLOT_SIZE, labelWidth());
|
||||
|
||||
if (this.gridCount < this.length) {
|
||||
this.gridCount -= reservedColumns(this.length - this.gridCount);
|
||||
}
|
||||
}
|
||||
|
||||
protected int labelWidth() {
|
||||
return fontRenderer.getStringWidth(this.label) + LABEL_MARGIN;
|
||||
}
|
||||
|
||||
protected int reservedColumns(int hidden) {
|
||||
return (int) Math.ceil((float) (fontRenderer.getStringWidth("+" + hidden) - 2) / SLOT_SIZE);
|
||||
}
|
||||
|
||||
public ItemsTooltipLineHandler setAmountRenderer(AmountRenderer amountRenderer) {
|
||||
this.amountRenderer = amountRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setActiveStack(ItemStack activeStack) {
|
||||
@@ -98,7 +308,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
this.size.width = Math.max(this.columns * SLOT_SIZE, fontRenderer.getStringWidth(this.label) + 15);
|
||||
this.size.width = Math.max(this.size.width, labelWidth());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,63 +329,79 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
|
||||
final int zTranslation = GuiContainerManager.TOOLTIP_Z_OFFSET;
|
||||
GL11.glTranslatef(xTranslation, yTranslation, zTranslation);
|
||||
|
||||
int indexShift = 0;
|
||||
final int gridShift = gridIndexShift();
|
||||
|
||||
if (this.activeStackIndex != -1) {
|
||||
indexShift = Math.max(0, Math.min(this.items.size() - this.count, this.activeStackIndex - this.count + 2));
|
||||
for (int index = 0; index < this.nameRows; index++) {
|
||||
drawSlot(0, index * SLOT_SIZE, index);
|
||||
}
|
||||
|
||||
for (int index = 0; index < this.count && index + indexShift < this.items.size(); index++) {
|
||||
ItemStack drawStack = this.items.get(index + indexShift);
|
||||
int col = index % this.columns;
|
||||
int row = index / this.columns;
|
||||
for (int index = 0; index < this.gridCount; index++) {
|
||||
drawSlot(
|
||||
(index % this.gridColumns) * SLOT_SIZE,
|
||||
(this.nameRows + index / this.gridColumns) * SLOT_SIZE,
|
||||
this.nameRows + gridShift + index);
|
||||
}
|
||||
|
||||
String stackSize = !this.saveStackSize || drawStack.stackSize == 0 ? ""
|
||||
: ReadableNumberConverter.INSTANCE.toWideReadableForm(drawStack.stackSize);
|
||||
NEIClientUtils.gl2DRenderContext(() -> {
|
||||
final int textShift = ICON_OFFSET + Math.round((ICON_SIZE - fontRenderer.FONT_HEIGHT) / 2f);
|
||||
|
||||
if (this.activeStackIndex == index + indexShift) {
|
||||
NEIClientUtils.gl2DRenderContext(
|
||||
() -> GuiDraw.drawRect(col * SLOT_SIZE - 1, row * SLOT_SIZE - 1, 18, 18, 0x66555555));
|
||||
for (int index = 0; index < this.nameRows; index++) {
|
||||
fontRenderer.drawStringWithShadow(
|
||||
EnumChatFormatting.GRAY + this.names.get(index),
|
||||
SLOT_SIZE + NAME_MARGIN,
|
||||
index * SLOT_SIZE + textShift,
|
||||
0xFFFFFF);
|
||||
}
|
||||
|
||||
drawItem(col * SLOT_SIZE, row * SLOT_SIZE, drawStack, stackSize);
|
||||
}
|
||||
final int hidden = this.length - this.nameRows - this.gridCount;
|
||||
|
||||
if (this.count < this.items.size()) {
|
||||
final String text = "+" + (this.items.size() - this.count);
|
||||
|
||||
NEIClientUtils.gl2DRenderContext(() -> {
|
||||
if (hidden > 0) {
|
||||
final String text = "+" + hidden;
|
||||
fontRenderer.drawStringWithShadow(
|
||||
text,
|
||||
MAX_COLUMNS * SLOT_SIZE - fontRenderer.getStringWidth(text) - 2,
|
||||
(this.rows - 1) * SLOT_SIZE + (SLOT_SIZE - fontRenderer.FONT_HEIGHT) / 2,
|
||||
0xee555555);
|
||||
});
|
||||
}
|
||||
EnumChatFormatting.GRAY + text,
|
||||
this.size.width - fontRenderer.getStringWidth(text) - 2,
|
||||
(this.rows - 1) * SLOT_SIZE + textShift,
|
||||
0xFFFFFF);
|
||||
}
|
||||
});
|
||||
|
||||
GL11.glTranslatef(-xTranslation, -yTranslation, -zTranslation);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
protected void drawItem(int x, int y, ItemStack drawStack, String stackSize) {
|
||||
GuiContainerManager.drawItem(x, y, drawStack, true, stackSize);
|
||||
protected int gridIndexShift() {
|
||||
if (this.nameRows > 0 || this.activeStackIndex == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.max(0, Math.min(this.length - this.gridCount, this.activeStackIndex - this.gridCount + 2));
|
||||
}
|
||||
|
||||
protected void drawSlot(int x, int y, int index) {
|
||||
if (this.activeStackIndex == index) {
|
||||
NEIClientUtils.gl2DRenderContext(() -> GuiDraw.drawRect(x, y, SLOT_SIZE, SLOT_SIZE, 0x66555555));
|
||||
}
|
||||
|
||||
drawStackWithAmount(x, y, index);
|
||||
}
|
||||
|
||||
protected void drawStackWithAmount(int x, int y, int index) {
|
||||
this.amountRenderer.draw(x + ICON_OFFSET, y + ICON_OFFSET, this.items.get(index), this.amounts.get(index));
|
||||
}
|
||||
|
||||
private List<ItemStack> groupingItemStacks(List<ItemStack> items) {
|
||||
final List<ItemStack> result = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<NBTTagCompound, Long> entry : ItemStackAmount.of(items).entrySet()) {
|
||||
final ItemStack stack = StackInfo.loadFromNBT(entry.getKey(), Math.max(0, entry.getValue()));
|
||||
|
||||
if (stack != null && StackInfo.isFluidDisplayItem(stack)) {
|
||||
stack.stackSize = 0;
|
||||
}
|
||||
|
||||
result.add(stack);
|
||||
result.add(StackInfo.loadFromNBT(entry.getKey(), 0));
|
||||
this.amounts.add(Math.max(0, entry.getValue()));
|
||||
}
|
||||
|
||||
if (result.isEmpty()) {
|
||||
result.addAll(items);
|
||||
for (ItemStack stack : items) {
|
||||
result.add(stack);
|
||||
this.amounts.add(0L);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
@@ -29,6 +30,7 @@ public class KeyManager {
|
||||
private static final Map<String, KeyBinding> keyBindings = new HashMap<>();
|
||||
private static final Map<String, String> keyAliases = new HashMap<>();
|
||||
private static volatile boolean pendingOptionsReload = false;
|
||||
private static int clickedButton = -1;
|
||||
|
||||
static {
|
||||
// Aliases for legacy keybinds
|
||||
@@ -73,7 +75,8 @@ public class KeyManager {
|
||||
final int keyCode = binding.getKeyCode();
|
||||
|
||||
if (keyCode < 0) {
|
||||
return Mouse.isButtonDown(keyCode + 100);
|
||||
final int button = keyCode + 100;
|
||||
return Mouse.isButtonDown(button) || button == clickedButton;
|
||||
} else if (keyCode > Keyboard.KEY_NONE && keyCode < Keyboard.KEYBOARD_SIZE) {
|
||||
return Keyboard.isKeyDown(keyCode);
|
||||
}
|
||||
@@ -82,6 +85,40 @@ public class KeyManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any NEI key binding is assigned to the given mouse button.
|
||||
*/
|
||||
public static boolean isMouseBound(int button) {
|
||||
for (KeyBinding binding : keyBindings.values()) {
|
||||
if (binding.getKeyCode() == button - 100) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a hotkey handler for a click of the given mouse button if the button is bound to any NEI key binding. The
|
||||
* button is reported as down by {@link #isKeyDown} for the duration of the call, because the LWJGL button state can
|
||||
* already be released when a quick click is processed.
|
||||
*
|
||||
* @return true if the click was consumed by the handler
|
||||
*/
|
||||
public static boolean handleMouseHotkey(int button, BooleanSupplier handler) {
|
||||
if (!isMouseBound(button)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int previous = clickedButton;
|
||||
clickedButton = button;
|
||||
|
||||
try {
|
||||
return handler.getAsBoolean();
|
||||
} finally {
|
||||
clickedButton = previous;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHashDown(String ident) {
|
||||
return isHashDown(ident, 0);
|
||||
}
|
||||
@@ -107,18 +144,23 @@ public class KeyManager {
|
||||
|
||||
public static String getKeyName(String ident, int meta) {
|
||||
final int keyCode = getKeyCode(ident);
|
||||
return keyCode == Keyboard.KEY_NONE ? null : NEIKeyboardUtils.getKeyName(keyCode + meta);
|
||||
return keyCode == Keyboard.KEY_NONE ? null : NEIKeyboardUtils.getKeyName(keyCode, meta);
|
||||
}
|
||||
|
||||
public static String getKeyName(String ident, int meta, int mouseBind) {
|
||||
final int keyCode = getKeyCode(ident);
|
||||
return keyCode == Keyboard.KEY_NONE && mouseBind == NEIMouseUtils.MOUSE_BTN_NONE ? null
|
||||
: getKeyName(keyCode + meta, mouseBind);
|
||||
: getKeyName(keyCode, meta, mouseBind);
|
||||
}
|
||||
|
||||
public static String getKeyName(int keyBind, int mouseBind) {
|
||||
final int keyCode = NEIKeyboardUtils.unhash(keyBind);
|
||||
return getKeyName(keyCode, keyBind - keyCode, mouseBind);
|
||||
}
|
||||
|
||||
private static String getKeyName(int keyCode, int hash, int mouseBind) {
|
||||
StringJoiner keyText = new StringJoiner(" + ");
|
||||
String keyHash = keyBind == Keyboard.KEY_NONE ? "" : NEIKeyboardUtils.getKeyName(keyBind);
|
||||
String keyHash = keyCode == Keyboard.KEY_NONE && hash == 0 ? "" : NEIKeyboardUtils.getKeyName(keyCode, hash);
|
||||
String mouseHash = mouseBind == NEIMouseUtils.MOUSE_BTN_NONE ? "" : NEIMouseUtils.getKeyName(mouseBind);
|
||||
|
||||
if (!keyHash.isEmpty()) {
|
||||
|
||||
@@ -220,6 +220,20 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
|
||||
if (isEnabled() && !isHidden()) {
|
||||
for (Widget widget : controlWidgets) {
|
||||
if (inputFocused == null) {
|
||||
widget.lastKeyTyped(keyID, keyChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed(GuiContainer gui) {
|
||||
|
||||
if (KeyManager.isKeyDown("gui.hide")) {
|
||||
toggleBooleanSetting("inventory.hidden");
|
||||
return true;
|
||||
@@ -234,8 +248,12 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isEnabled() && !isHidden()) {
|
||||
for (Widget widget : controlWidgets) if (inputFocused == null) widget.lastKeyTyped(keyID, keyChar);
|
||||
if (isEnabled() && !isHidden() && inputFocused == null) {
|
||||
for (Widget widget : controlWidgets) {
|
||||
if (widget.onHotkeyPressed()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -370,6 +388,8 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
}
|
||||
|
||||
public static void layout(GuiContainer gui) {
|
||||
GridOverlapScanner.beginFrame(gui, GuiContainerManager.shouldShowTooltip(gui));
|
||||
|
||||
VisiblityData visiblity = new VisiblityData();
|
||||
visiblity.showNEI = !isHidden();
|
||||
visiblity.showBookmarkPanel = !isBookmarkPanelHidden();
|
||||
@@ -427,14 +447,14 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
if (!rightclick) {
|
||||
if (Keyboard.getEventKeyState() && getIsAccessibleControlEventKey()
|
||||
&& NEIClientConfig.canChangeCheatMode()) {
|
||||
NEIClientConfig.cycleSetting("inventory.cheatmode", 3);
|
||||
NEIClientConfig.setCheatMode((NEIClientConfig.getCheatMode() + 1) % 3);
|
||||
} else {
|
||||
if (Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LSHIFT
|
||||
|| Keyboard.getEventKey() == Keyboard.KEY_RSHIFT)) {
|
||||
GuiRecipeTab.loadHandlerInfo();
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
}
|
||||
getOptionList().openGui(getGuiContainer(), false);
|
||||
getOptionList().openGui(getGuiContainer());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -803,6 +823,9 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
if (!isEnabled()) return;
|
||||
|
||||
GridOverlapScanner.requestScan();
|
||||
AutoFocusWidget.instance.guiTick();
|
||||
|
||||
for (Widget widget : drawWidgets) widget.update();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ public class NEICPH implements IClientPacketHandler {
|
||||
case S2C.CACHE_BOOKMARK_DATA:
|
||||
handleCacheBookmarkData(packet);
|
||||
break;
|
||||
case S2C.SYNC:
|
||||
ServerSync.onReply(packet.readInt());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.storage.SaveFormatComparator;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -37,7 +37,6 @@ import codechicken.lib.config.ConfigTag;
|
||||
import codechicken.lib.config.ConfigTagParent;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.GuiInfo;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.api.NEIInfo;
|
||||
import codechicken.nei.config.ConfigSet;
|
||||
@@ -45,7 +44,9 @@ import codechicken.nei.config.GuiHighlightTips;
|
||||
import codechicken.nei.config.GuiNEIOptionList;
|
||||
import codechicken.nei.config.GuiOptionList;
|
||||
import codechicken.nei.config.GuiPanelSettings;
|
||||
import codechicken.nei.config.OptionButton;
|
||||
import codechicken.nei.config.OptionCycled;
|
||||
import codechicken.nei.config.OptionExportConfig;
|
||||
import codechicken.nei.config.OptionGamemodes;
|
||||
import codechicken.nei.config.OptionIntegerField;
|
||||
import codechicken.nei.config.OptionList;
|
||||
@@ -56,7 +57,6 @@ import codechicken.nei.config.OptionToggleButtonBoubs;
|
||||
import codechicken.nei.config.OptionUtilities;
|
||||
import codechicken.nei.config.preset.GuiPresetList;
|
||||
import codechicken.nei.event.NEIConfigsLoadedEvent;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.InformationHandler;
|
||||
import codechicken.nei.recipe.RecipeCatalysts;
|
||||
@@ -69,6 +69,7 @@ public class NEIClientConfig {
|
||||
private static boolean pluginNEIConfigLoaded;
|
||||
private static boolean enabledOverride;
|
||||
private static String worldPath;
|
||||
private static final String CHEAT_MODE_KEY = "cheatmode";
|
||||
|
||||
public static Logger logger = LogManager.getLogger("NotEnoughItems");
|
||||
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
|
||||
@@ -157,6 +158,16 @@ public class NEIClientConfig {
|
||||
.getIntValue(-1);
|
||||
API.addOption(new OptionCycled("inventory.cheatmode", 3) {
|
||||
|
||||
@Override
|
||||
public int value() {
|
||||
return getCheatMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
setCheatMode(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean optionValid(int index) {
|
||||
return getLockedMode() == -1 || getLockedMode() == index && NEIInfo.isValidMode(index);
|
||||
@@ -200,6 +211,11 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.bookmarks.showRecipeMarkerMode").setComment("Show Recipe Marker").getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.bookmarks.showRecipeMarkerMode", 3, true));
|
||||
|
||||
tag.getTag("inventory.bookmarks.maxVerticalTooltipRows")
|
||||
.setComment("Max rows in vertical crafting chain tooltip lists (0 - disable, always use grid)")
|
||||
.getIntValue(12);
|
||||
API.addOption(new OptionIntegerField("inventory.bookmarks.maxVerticalTooltipRows", 0, 50));
|
||||
|
||||
tag.getTag("inventory.bookmarks.recipeMarkerColor").setComment("Color of the icon marker")
|
||||
.getHexValue(0xADADAD);
|
||||
API.addOption(
|
||||
@@ -212,9 +228,6 @@ public class NEIClientConfig {
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarks.showRecipeHandlerIcon", true));
|
||||
|
||||
tag.getTag("inventory.bookmarks.recipeChainDir").getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.bookmarks.recipeChainDir", 2, true));
|
||||
|
||||
tag.getTag("inventory.bookmarks.ignorePotionOverlap").setComment("Ignore overlap with potion effect HUD")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarks.ignorePotionOverlap", true));
|
||||
@@ -227,6 +240,10 @@ public class NEIClientConfig {
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarks.bookmarkRecipeWithCount", true));
|
||||
|
||||
tag.getTag("inventory.bookmarks.craftingTreeZoomWithoutModifier")
|
||||
.setComment("Zoom Crafting Tree with mouse wheel without holding Ctrl").getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarks.craftingTreeZoomWithoutModifier", true));
|
||||
|
||||
tag.getTag("inventory.guirecipe.jeiStyleTabs").setComment("Enable/disable JEI Style Tabs")
|
||||
.getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButtonBoubs("inventory.guirecipe.jeiStyleTabs", true));
|
||||
@@ -239,10 +256,6 @@ public class NEIClientConfig {
|
||||
.getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.guirecipe.cycledIngredientsTooltip", true));
|
||||
|
||||
tag.getTag("inventory.guirecipe.creativeTabStyle").setComment("Creative or JEI style tabs")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.guirecipe.creativeTabStyle", true));
|
||||
|
||||
tag.getTag("inventory.guirecipe.itemPresenceOverlay").setComment("Item presence overlay on ?-hover")
|
||||
.getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.guirecipe.itemPresenceOverlay", 3, true));
|
||||
@@ -266,6 +279,11 @@ public class NEIClientConfig {
|
||||
.getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.guirecipe.scrollPages", true));
|
||||
|
||||
tag.getTag("inventory.guirecipe.freezeCycleOnHover")
|
||||
.setComment("Stop cycling the recipe while hovering over an ingredient or a button")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.guirecipe.freezeCycleOnHover", true));
|
||||
|
||||
tag.getTag("inventory.guirecipe.profile").getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.guirecipe.profile", true));
|
||||
|
||||
@@ -371,6 +389,11 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.itemzoom.onlySolid").getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.itemzoom.onlySolid", true));
|
||||
|
||||
tag.getTag("inventory.itemzoom.preferredSide")
|
||||
.setComment("Which side to prefer showing the zoomed item on, when both sides are free.")
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.itemzoom.preferredSide", 3, true));
|
||||
|
||||
tag.getTag("inventory.itemzoom.helpText")
|
||||
.setComment("Display name \"Item Zoom\" and the hotkey to toggle this mod below the zoomed item.")
|
||||
.getBooleanValue(true);
|
||||
@@ -475,10 +498,6 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.showItemQuantityWidget").setComment("Show Item Quantity Widget").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.showItemQuantityWidget", true));
|
||||
|
||||
tag.getTag("inventory.optimize_gui_overlap_computation").setComment("Optimize computation for GUI overlap")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.optimize_gui_overlap_computation", true));
|
||||
|
||||
tag.getTag("inventory.autocrafting").setComment("Autocrafting").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.autocrafting", true));
|
||||
|
||||
@@ -500,29 +519,32 @@ public class NEIClientConfig {
|
||||
|
||||
});
|
||||
|
||||
tag.getTag("tools.handler_load_from_config").setComment("ADVANCED: Load handlers from config")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("tools.handler_load_from_config", true) {
|
||||
API.addOption(
|
||||
new OptionButton(
|
||||
"tools.export_configs.all",
|
||||
"tools.export_configs.all",
|
||||
null,
|
||||
"tools.export_configs.all.tip") {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
super.onClick(button);
|
||||
GuiRecipeTab.loadHandlerInfo();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN("tools.export_configs.button");
|
||||
}
|
||||
|
||||
tag.getTag("tools.catalyst_load_from_config").setComment("ADVANCED: Load catalysts from config")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("tools.catalyst_load_from_config", true) {
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
int exported = 0;
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
super.onClick(button);
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
for (String resource : ClientHandler.DEFAULT_CONFIGS) {
|
||||
if (ClientHandler.exportDefaultConfig(resource)) exported++;
|
||||
}
|
||||
|
||||
NEIClientUtils.printChatMessage(
|
||||
new ChatComponentTranslation("nei.options.tools.export_configs.all.done", exported));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
ClientHandler.DEFAULT_CONFIGS.forEach(fileName -> API.addOption(new OptionExportConfig(fileName)));
|
||||
|
||||
setDefaultKeyBindings();
|
||||
}
|
||||
@@ -531,23 +553,18 @@ public class NEIClientConfig {
|
||||
OptionList.setOptionList(new OptionList("nei.options") {
|
||||
|
||||
@Override
|
||||
public ConfigSet globalConfigSet() {
|
||||
public ConfigSet configSet() {
|
||||
return global;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSet worldConfigSet() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionList configBase() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
|
||||
return new GuiNEIOptionList(parent, list, world);
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list) {
|
||||
return new GuiNEIOptionList(parent, list);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -914,15 +931,15 @@ public class NEIClientConfig {
|
||||
specificDir.mkdirs();
|
||||
}
|
||||
|
||||
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
|
||||
world = new ConfigSet(new File(specificDir, "NEI.dat"));
|
||||
|
||||
if (newWorld && Minecraft.getMinecraft().isSingleplayer() && getLockedMode() == -1) {
|
||||
final int globalMode = global.config.getTag("inventory.cheatmode").getIntValue();
|
||||
final int globalMode = getCheatMode();
|
||||
final int worldMode = Math
|
||||
.min(globalMode, NEIClientUtils.mc().playerController.isInCreativeMode() ? 2 : 0);
|
||||
|
||||
if (worldMode != globalMode) {
|
||||
world.config.getTag("inventory.cheatmode").setIntValue(worldMode);
|
||||
setCheatMode(worldMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,9 +953,6 @@ public class NEIClientConfig {
|
||||
}
|
||||
|
||||
private static void onWorldLoad() {
|
||||
world.config.setComment(
|
||||
"World based configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");
|
||||
|
||||
setWorldDefaults();
|
||||
creativeInv = new ItemStack[54];
|
||||
LayoutManager.searchField.setText(getSearchExpression());
|
||||
@@ -1010,20 +1024,11 @@ public class NEIClientConfig {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Stream<Class<?>> stream = NEIClientConfig.getBooleanSetting("loadPluginsInParallel")
|
||||
? NEIClientConfig.pluginsList.parallelStream()
|
||||
: NEIClientConfig.pluginsList.stream();
|
||||
|
||||
stream.forEach(clazz -> {
|
||||
try {
|
||||
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
|
||||
config.loadConfig();
|
||||
NEIModContainer.plugins.add(config);
|
||||
logger.debug("Loaded {}", clazz.getName());
|
||||
} catch (Throwable e) {
|
||||
logger.error("Failed to Load {}", clazz.getName(), e);
|
||||
}
|
||||
});
|
||||
PluginLoader.load(
|
||||
NEIClientConfig.pluginsList,
|
||||
NEIClientConfig.getBooleanSetting("loadPluginsInParallel"),
|
||||
NEIModContainer.plugins,
|
||||
logger);
|
||||
|
||||
KeyManager.requestOptionsReload();
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
@@ -1053,14 +1058,8 @@ public class NEIClientConfig {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isWorldSpecific(String setting) {
|
||||
if (world == null) return false;
|
||||
ConfigTag tag = world.config.getTag(setting, false);
|
||||
return tag != null && tag.value != null;
|
||||
}
|
||||
|
||||
public static ConfigTag getSetting(String s) {
|
||||
return isWorldSpecific(s) ? world.config.getTag(s) : global.config.getTag(s);
|
||||
return global.config.getTag(s);
|
||||
}
|
||||
|
||||
public static boolean getBooleanSetting(String s) {
|
||||
@@ -1105,6 +1104,10 @@ public class NEIClientConfig {
|
||||
return getIntSetting("inventory.bookmarks.showRecipeMarkerMode");
|
||||
}
|
||||
|
||||
public static int getMaxVerticalTooltipRows() {
|
||||
return getIntSetting("inventory.bookmarks.maxVerticalTooltipRows");
|
||||
}
|
||||
|
||||
public static boolean showItemQuantityWidget() {
|
||||
return getBooleanSetting("inventory.showItemQuantityWidget");
|
||||
}
|
||||
@@ -1145,26 +1148,22 @@ public class NEIClientConfig {
|
||||
return getIntSetting("inventory.guirecipe.jeiStyleRecipeCatalyst");
|
||||
}
|
||||
|
||||
public static boolean useCreativeTabStyle() {
|
||||
return getBooleanSetting("inventory.guirecipe.creativeTabStyle");
|
||||
}
|
||||
|
||||
public static boolean ignorePotionOverlap() {
|
||||
return getBooleanSetting("inventory.bookmarks.ignorePotionOverlap");
|
||||
}
|
||||
|
||||
public static int recipeChainDir() {
|
||||
return getIntSetting("inventory.bookmarks.recipeChainDir");
|
||||
}
|
||||
|
||||
public static boolean optimizeGuiOverlapComputation() {
|
||||
return getBooleanSetting("inventory.optimize_gui_overlap_computation");
|
||||
public static boolean craftingTreeZoomWithoutModifier() {
|
||||
return getBooleanSetting("inventory.bookmarks.craftingTreeZoomWithoutModifier");
|
||||
}
|
||||
|
||||
public static boolean showCycledIngredientsTooltip() {
|
||||
return getBooleanSetting("inventory.guirecipe.cycledIngredientsTooltip");
|
||||
}
|
||||
|
||||
public static boolean freezeCycleOnHover() {
|
||||
return getBooleanSetting("inventory.guirecipe.freezeCycleOnHover");
|
||||
}
|
||||
|
||||
public static boolean requireShiftForOverlayRecipe() {
|
||||
return getBooleanSetting("inventory.guirecipe.shiftOverlayRecipe");
|
||||
}
|
||||
@@ -1177,14 +1176,6 @@ public class NEIClientConfig {
|
||||
return mainNEIConfigLoaded && pluginNEIConfigLoaded;
|
||||
}
|
||||
|
||||
public static boolean loadHandlersFromJar() {
|
||||
return !getBooleanSetting("tools.handler_load_from_config");
|
||||
}
|
||||
|
||||
public static boolean loadCatalystsFromJar() {
|
||||
return !getBooleanSetting("tools.catalyst_load_from_config");
|
||||
}
|
||||
|
||||
public static boolean isProfileRecipeEnabled() {
|
||||
return NEIClientConfig.getBooleanSetting("inventory.guirecipe.profile");
|
||||
}
|
||||
@@ -1198,12 +1189,18 @@ public class NEIClientConfig {
|
||||
}
|
||||
|
||||
public static int getCheatMode() {
|
||||
if (world != null && world.nbt.hasKey(CHEAT_MODE_KEY)) return world.nbt.getInteger(CHEAT_MODE_KEY);
|
||||
return getIntSetting("inventory.cheatmode");
|
||||
}
|
||||
|
||||
public static void setCheatMode(int mode) {
|
||||
if (world != null) world.nbt.setInteger(CHEAT_MODE_KEY, mode);
|
||||
else setIntSetting("inventory.cheatmode", mode);
|
||||
}
|
||||
|
||||
public static boolean canChangeCheatMode() {
|
||||
if (getLockedMode() != -1) {
|
||||
setIntSetting("inventory.cheatmode", getLockedMode());
|
||||
setCheatMode(getLockedMode());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@ import static codechicken.nei.NEIClientConfig.invCreativeMode;
|
||||
import static codechicken.nei.NEIClientConfig.world;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.file.Files;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.MessageFormat;
|
||||
@@ -26,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -64,6 +68,8 @@ import codechicken.nei.util.NEIKeyboardUtils;
|
||||
|
||||
public class NEIClientUtils extends NEIServerUtils {
|
||||
|
||||
private static final Set<String> REPORTED = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public static class Alignment {
|
||||
|
||||
public final int x, y;
|
||||
@@ -639,4 +645,29 @@ public class NEIClientUtils extends NEIServerUtils {
|
||||
if (!isAlphaTest) GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
public static void errorOnce(String key, String message, Throwable error) {
|
||||
if (REPORTED.add(key)) {
|
||||
NEIClientConfig.logger.error(message, error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warnOnce(String key, String message) {
|
||||
if (REPORTED.add(key)) {
|
||||
NEIClientConfig.logger.warn(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean backupFile(File file) {
|
||||
final File backup = new File(file.getAbsolutePath() + ".backup-" + System.currentTimeMillis());
|
||||
|
||||
try {
|
||||
Files.copy(file.toPath(), backup.toPath());
|
||||
NEIClientConfig.logger.info("Backed up file {} to {}", file, backup);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to backup file {} to {}", file, backup, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
|
||||
|
||||
if (GuiInfo.hasCustomSlots(gui)) return false;
|
||||
|
||||
if (NEIClientUtils.shiftKey()) {
|
||||
if (NEIClientUtils.shiftKey() && button != 2) { // MMB is used by other mods when an itemstack is picked.
|
||||
// fix small mouse movement while clicking causing slotIndex to be -999
|
||||
if (slotIndex == -999) {
|
||||
final Point mouse = GuiDraw.getMousePosition();
|
||||
|
||||
@@ -92,9 +92,17 @@ public class NEISPH implements IServerPacketHandler {
|
||||
case C2S.SEND_CHAT_ITEM_LINK:
|
||||
handleSendChatItemLink(sender, packet);
|
||||
break;
|
||||
case C2S.SYNC:
|
||||
handleSync(sender, packet.readInt());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSync(EntityPlayerMP sender, int id) {
|
||||
sender.sendContainerAndContentsToPlayer(sender.openContainer, sender.openContainer.getInventory());
|
||||
new PacketCustom(channel, S2C.SYNC).writeInt(id).sendToPlayer(sender);
|
||||
}
|
||||
|
||||
private void handleSendChatItemLink(EntityPlayerMP sender, PacketCustom packet) {
|
||||
final NBTTagCompound payloadTag = packet.readNBTTagCompound();
|
||||
NEIServerUtils.sendChatItemLink(sender, payloadTag);
|
||||
|
||||
@@ -4,12 +4,9 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
@@ -509,20 +506,6 @@ public class NEIServerUtils {
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static void logOnce(Throwable t, Set<String> stackTraces, String message) {
|
||||
logOnce(t, stackTraces, message, "");
|
||||
}
|
||||
|
||||
public static void logOnce(Throwable t, Set<String> stackTraces, String message, String identifier) {
|
||||
StringWriter sw = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
String stackTrace = identifier + sw.toString();
|
||||
if (!stackTraces.contains(stackTrace)) {
|
||||
NEIServerConfig.logger.error(message, t);
|
||||
stackTraces.add(stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getModdedItem(String itemId, String nbtString) {
|
||||
int meta = -1;
|
||||
ItemStack itemStack;
|
||||
|
||||
@@ -24,6 +24,7 @@ public final class PacketIDs {
|
||||
public static final int REQUEST_POTION_GUI = 24;
|
||||
public static final int SET_DUMMY_SLOT = 25;
|
||||
public static final int SEND_CHAT_ITEM_LINK = 26;
|
||||
public static final int SYNC = 27;
|
||||
}
|
||||
|
||||
public static final class S2C {
|
||||
@@ -38,5 +39,6 @@ public final class PacketIDs {
|
||||
public static final int SET_CREATIVE_PLUS_MODE = 23;
|
||||
public static final int OPEN_POTION_GUI = 24;
|
||||
public static final int CACHE_BOOKMARK_DATA = 25;
|
||||
public static final int SYNC = 26;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ public abstract class PanelWidget<T extends ItemsGrid<? extends ItemsGridSlot, ?
|
||||
|
||||
protected T grid;
|
||||
|
||||
private int headerPaddingLeft;
|
||||
private int headerPaddingRight;
|
||||
|
||||
public ArrayList<ItemStack> getItems() {
|
||||
return this.grid.getItems();
|
||||
}
|
||||
@@ -105,26 +108,15 @@ public abstract class PanelWidget<T extends ItemsGrid<? extends ItemsGridSlot, ?
|
||||
|
||||
protected int resizeHeader(GuiContainer gui) {
|
||||
final int BUTTON_SIZE = 16;
|
||||
int paddingLeft = 0;
|
||||
int paddingRight = 0;
|
||||
|
||||
while (paddingLeft < w && GuiInfo.hideItemPanelSlot(
|
||||
gui,
|
||||
new Rectangle4i(x + paddingLeft, y, ItemsGrid.SLOT_SIZE, ItemsGrid.SLOT_SIZE))) {
|
||||
paddingLeft += ItemsGrid.SLOT_SIZE;
|
||||
if (GridOverlapScanner.isScanFrame()) {
|
||||
updateHeaderPadding(gui);
|
||||
}
|
||||
|
||||
while (paddingRight < w && GuiInfo.hideItemPanelSlot(
|
||||
gui,
|
||||
new Rectangle4i(
|
||||
x + w - paddingRight - ItemsGrid.SLOT_SIZE,
|
||||
y,
|
||||
ItemsGrid.SLOT_SIZE,
|
||||
ItemsGrid.SLOT_SIZE))) {
|
||||
paddingRight += ItemsGrid.SLOT_SIZE;
|
||||
}
|
||||
final int paddingLeft = this.headerPaddingLeft;
|
||||
final int paddingRight = this.headerPaddingRight;
|
||||
|
||||
if (paddingLeft + paddingRight >= w) {
|
||||
if (paddingLeft + paddingRight >= this.w) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -132,16 +124,35 @@ public abstract class PanelWidget<T extends ItemsGrid<? extends ItemsGridSlot, ?
|
||||
pagePrev.h = pageNext.h = BUTTON_SIZE;
|
||||
pagePrev.y = pageNext.y = y;
|
||||
|
||||
pagePrev.x = x + paddingLeft;
|
||||
pageNext.x = x + w - pageNext.w - paddingRight;
|
||||
pagePrev.x = this.x + paddingLeft;
|
||||
pageNext.x = this.x + this.w - pageNext.w - paddingRight;
|
||||
|
||||
pageLabel.x = x + paddingLeft + (w - paddingLeft - paddingRight) / 2;
|
||||
pageLabel.y = y + 5;
|
||||
pageLabel.x = this.x + paddingLeft + (this.w - paddingLeft - paddingRight) / 2;
|
||||
pageLabel.y = this.y + 5;
|
||||
pageLabel.text = getLabelText();
|
||||
|
||||
return BUTTON_SIZE + 2;
|
||||
}
|
||||
|
||||
private void updateHeaderPadding(GuiContainer gui) {
|
||||
final INEIGuiHandler[] handlers = GuiInfo.getGuiHandlersSnapshot();
|
||||
final Rectangle4i slot = new Rectangle4i(this.x, this.y, ItemsGrid.SLOT_SIZE, ItemsGrid.SLOT_SIZE);
|
||||
this.headerPaddingLeft = 0;
|
||||
this.headerPaddingRight = 0;
|
||||
|
||||
while (this.headerPaddingLeft < this.w && GuiInfo.hideItemPanelSlot(gui, slot, handlers)) {
|
||||
this.headerPaddingLeft += ItemsGrid.SLOT_SIZE;
|
||||
slot.x += ItemsGrid.SLOT_SIZE;
|
||||
}
|
||||
|
||||
slot.x = this.x + this.w - ItemsGrid.SLOT_SIZE;
|
||||
|
||||
while (this.headerPaddingRight < this.w && GuiInfo.hideItemPanelSlot(gui, slot, handlers)) {
|
||||
this.headerPaddingRight += ItemsGrid.SLOT_SIZE;
|
||||
slot.x -= ItemsGrid.SLOT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int resizeFooter(GuiContainer gui);
|
||||
|
||||
public void setVisible() {
|
||||
@@ -305,7 +316,7 @@ public abstract class PanelWidget<T extends ItemsGrid<? extends ItemsGridSlot, ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleKeyPress(int keyID, char keyChar) {
|
||||
public boolean onHotkeyPressed() {
|
||||
final Point mouse = GuiDraw.getMousePosition();
|
||||
if (!contains(mouse.x, mouse.y)) return false;
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
|
||||
final class PluginLoader {
|
||||
|
||||
private PluginLoader() {}
|
||||
|
||||
static void load(Collection<Class<?>> plugins, boolean parallel, Collection<IConfigureNEI> loadedPlugins,
|
||||
Logger logger) {
|
||||
if (parallel && canSetContextClassLoader()) {
|
||||
// Common pool workers use the system loader, which cannot see FML-only classes (old Log4j then throws
|
||||
// while logging a plugin's stack frames), and under a SecurityManager they forbid changing it.
|
||||
final ClassLoader classLoader = IConfigureNEI.class.getClassLoader();
|
||||
final ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), owner -> {
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(owner);
|
||||
worker.setContextClassLoader(classLoader);
|
||||
return worker;
|
||||
}, null, false);
|
||||
|
||||
try {
|
||||
pool.submit(() -> plugins.parallelStream().forEach(clazz -> load(clazz, loadedPlugins, logger))).join();
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
}
|
||||
} else {
|
||||
if (parallel) {
|
||||
logger.warn("Context class loader cannot be changed, loading plugins sequentially");
|
||||
}
|
||||
|
||||
plugins.forEach(clazz -> load(clazz, loadedPlugins, logger));
|
||||
}
|
||||
}
|
||||
|
||||
private static void load(Class<?> clazz, Collection<IConfigureNEI> loadedPlugins, Logger logger) {
|
||||
try {
|
||||
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
|
||||
config.loadConfig();
|
||||
loadedPlugins.add(config);
|
||||
logger.debug("Loaded {}", clazz.getName());
|
||||
} catch (Throwable e) {
|
||||
logger.error("Failed to Load {}", clazz.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canSetContextClassLoader() {
|
||||
final SecurityManager securityManager = System.getSecurityManager();
|
||||
|
||||
if (securityManager == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
securityManager.checkPermission(new RuntimePermission("setContextClassLoader"));
|
||||
return true;
|
||||
} catch (SecurityException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,11 @@ public class PopupInputHandler implements IContainerInputHandler {
|
||||
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed(GuiContainer gui) {
|
||||
|
||||
if (KeyManager.isHashDown("gui.enchant") && canPerformAction("enchant")) {
|
||||
NEICPH.sendOpenEnchantmentWindow();
|
||||
|
||||
@@ -4,24 +4,21 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.item.FluidDrawer;
|
||||
import codechicken.nei.item.FluidDrawer.FillDirection;
|
||||
import codechicken.nei.recipe.Badge;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
@@ -46,7 +43,8 @@ public class PositionedStack implements Cloneable {
|
||||
protected boolean permutated = false;
|
||||
|
||||
protected String acceptsLabel;
|
||||
protected List<String> tooltip;
|
||||
|
||||
protected Function<ItemStack, List<String>> tooltip;
|
||||
protected List<Badge> badges;
|
||||
|
||||
public PositionedStack(Object object, int x, int y, boolean genPerms) {
|
||||
@@ -68,31 +66,11 @@ public class PositionedStack implements Cloneable {
|
||||
public void generatePermutations() {
|
||||
if (permutated) return;
|
||||
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
for (ItemStack item : items) {
|
||||
if (item == null || item.getItem() == null) continue;
|
||||
items = ItemList.expandPermutations(items);
|
||||
|
||||
if (item.getItemDamage() == Short.MAX_VALUE) {
|
||||
List<ItemStack> permutations = ItemList.itemMap.get(item.getItem());
|
||||
if (!permutations.isEmpty()) {
|
||||
for (ItemStack stack : permutations) {
|
||||
ItemStack toAdd = stack.copy();
|
||||
toAdd.stackSize = item.stackSize;
|
||||
stacks.add(toAdd);
|
||||
}
|
||||
} else {
|
||||
ItemStack base = new ItemStack(item.getItem(), item.stackSize);
|
||||
base.stackTagCompound = item.stackTagCompound;
|
||||
stacks.add(base);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
stacks.add(item.copy());
|
||||
if (items.length == 0) {
|
||||
items = new ItemStack[] { new ItemStack(Blocks.fire) };
|
||||
}
|
||||
items = stacks.toArray(new ItemStack[0]);
|
||||
|
||||
if (items.length == 0) items = new ItemStack[] { new ItemStack(Blocks.fire) };
|
||||
|
||||
permutated = true;
|
||||
setPermutationToRender(0);
|
||||
@@ -119,11 +97,15 @@ public class PositionedStack implements Cloneable {
|
||||
}
|
||||
|
||||
public void setTooltip(List<String> tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
this.tooltip = tooltip == null ? null : item -> tooltip;
|
||||
}
|
||||
|
||||
public void setTooltipProvider(Function<ItemStack, List<String>> provider) {
|
||||
this.tooltip = provider;
|
||||
}
|
||||
|
||||
public List<String> getTooltip() {
|
||||
return this.tooltip;
|
||||
return this.tooltip == null ? null : this.tooltip.apply(this.item);
|
||||
}
|
||||
|
||||
public int getChance() {
|
||||
@@ -139,7 +121,6 @@ public class PositionedStack implements Cloneable {
|
||||
PositionedStack pStack = (PositionedStack) super.clone();
|
||||
pStack.items = Arrays.stream(this.items).map(ItemStack::copy).toArray(ItemStack[]::new);
|
||||
pStack.item = this.item == null ? null : this.item.copy();
|
||||
pStack.tooltip = this.tooltip == null ? null : new ArrayList<>(this.tooltip);
|
||||
pStack.badges = this.badges == null ? null : new ArrayList<>(this.badges);
|
||||
return pStack;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
@@ -158,7 +139,7 @@ public class PositionedStack implements Cloneable {
|
||||
}
|
||||
|
||||
public List<ItemStack> getFilteredPermutations(ItemFilter additionalFilter) {
|
||||
List<ItemStack> items = Arrays.asList(this.items);
|
||||
List<ItemStack> items = new ArrayList<>(Arrays.asList(this.items));
|
||||
|
||||
items = filteringPermutations(items, item -> !ItemInfo.isHidden(item));
|
||||
items = filteringPermutations(items, PresetsList.getItemFilter());
|
||||
@@ -252,27 +233,56 @@ public class PositionedStack implements Cloneable {
|
||||
public void draw(int mousex, int mousey) {}
|
||||
}
|
||||
|
||||
public static class Fluid extends PositionedStack {
|
||||
public static class Tank extends PositionedStack {
|
||||
|
||||
/** The tank size the fill level is measured against, in mB. 0 means "always render full". */
|
||||
public int capacity = 0;
|
||||
protected int capacity = 0;
|
||||
protected boolean flowingTexture = false;
|
||||
protected FillDirection fillDirection = FillDirection.AUTO;
|
||||
|
||||
private ItemStack cachedFluidItem;
|
||||
private FluidStack cachedFluidStack;
|
||||
|
||||
public Fluid(Object object, int x, int y, boolean genPerms) {
|
||||
public Tank(Object object, int x, int y, boolean genPerms) {
|
||||
super(object, x, y, genPerms);
|
||||
}
|
||||
|
||||
public Fluid(Object object, int x, int y) {
|
||||
public Tank(Object object, int x, int y) {
|
||||
this(object, x, y, true);
|
||||
}
|
||||
|
||||
public Fluid(Object object, int x, int y, int width, int height, int capacity) {
|
||||
public Tank(Object object, int x, int y, int width, int height, int capacity) {
|
||||
super(object, x, y, false);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.capacity = capacity;
|
||||
setCapacity(capacity);
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public Tank setCapacity(int capacity) {
|
||||
this.capacity = Math.max(capacity, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasFlowingTexture() {
|
||||
return this.flowingTexture;
|
||||
}
|
||||
|
||||
public Tank setFlowingTexture(boolean flowingTexture) {
|
||||
this.flowingTexture = flowingTexture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FillDirection getFillDirection() {
|
||||
return this.fillDirection;
|
||||
}
|
||||
|
||||
public Tank setFillDirection(FillDirection fillDirection) {
|
||||
this.fillDirection = fillDirection == null ? FillDirection.AUTO : fillDirection;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected FluidStack getFluidStack() {
|
||||
@@ -291,7 +301,7 @@ public class PositionedStack implements Cloneable {
|
||||
final List<String> customTooltip = super.getTooltip();
|
||||
final FluidStack fluidStack = getFluidStack();
|
||||
|
||||
if (fluidStack != null) {
|
||||
if (fluidStack != null && this.capacity > 0) {
|
||||
tooltip.add(
|
||||
EnumChatFormatting.GRAY + NEIClientUtils
|
||||
.translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount)));
|
||||
@@ -313,62 +323,15 @@ public class PositionedStack implements Cloneable {
|
||||
return;
|
||||
}
|
||||
|
||||
final int tankCapacity = this.capacity > 0 ? this.capacity : fluidStack.amount;
|
||||
int fillHeight = tankCapacity > 0
|
||||
? (int) ((long) this.height * Math.min(fluidStack.amount, tankCapacity) / tankCapacity)
|
||||
: 0;
|
||||
|
||||
if (fluidStack.amount > 0 && fillHeight <= 0) {
|
||||
fillHeight = 1;
|
||||
}
|
||||
|
||||
if (fillHeight > 0) {
|
||||
drawFluid(this.relx, this.rely, this.width, this.height, fillHeight, fluidStack);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawFluid(int x, int y, int width, int height, int fillHeight, FluidStack fluidStack) {
|
||||
final IIcon icon = fluidStack.getFluid().getIcon(fluidStack);
|
||||
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int color = fluidStack.getFluid().getColor(fluidStack);
|
||||
final float red = (color >> 16 & 0xFF) / 255F;
|
||||
final float green = (color >> 8 & 0xFF) / 255F;
|
||||
final float blue = (color & 0xFF) / 255F;
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
||||
GL11.glColor4f(red, green, blue, 1F);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
for (int tx = 0; tx < width; tx += 16) {
|
||||
final int tileWidth = Math.min(16, width - tx);
|
||||
final double u2 = icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * tileWidth / 16D;
|
||||
|
||||
for (int ty = 0; ty < fillHeight; ty += 16) {
|
||||
final int tileHeight = Math.min(16, fillHeight - ty);
|
||||
final double v2 = icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * tileHeight / 16D;
|
||||
final int bottomY = y + height - ty;
|
||||
final int topY = bottomY - tileHeight;
|
||||
|
||||
tessellator.addVertexWithUV(x + tx, bottomY, 0, icon.getMinU(), v2);
|
||||
tessellator.addVertexWithUV(x + tx + tileWidth, bottomY, 0, u2, v2);
|
||||
tessellator.addVertexWithUV(x + tx + tileWidth, topY, 0, u2, icon.getMinV());
|
||||
tessellator.addVertexWithUV(x + tx, topY, 0, icon.getMinU(), icon.getMinV());
|
||||
}
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
FluidDrawer.drawTank(
|
||||
this.relx,
|
||||
this.rely,
|
||||
this.width,
|
||||
this.height,
|
||||
this.capacity,
|
||||
fluidStack,
|
||||
this.flowingTexture,
|
||||
this.fillDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,19 +89,19 @@ public class PresetsList {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PositionedStack result = handler.getResultStack(recipeIndex);
|
||||
final List<PositionedStack> outputs = handler.getResultStacks(recipeIndex);
|
||||
|
||||
if (result != null && matchPositionedStack(result)) {
|
||||
if (matchPositionedStack(outputs, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final List<PositionedStack> others = handler.getOtherStacks(recipeIndex);
|
||||
final List<PositionedStack> auxiliaries = handler.getAuxiliaryStacks(recipeIndex);
|
||||
|
||||
if (!others.isEmpty() && matchPositionedStack(others, true)) {
|
||||
if (matchPositionedStack(auxiliaries, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return result == null && others.isEmpty();
|
||||
return outputs.isEmpty() && auxiliaries.isEmpty();
|
||||
}
|
||||
|
||||
private boolean matchPositionedStack(List<PositionedStack> items, boolean dir) {
|
||||
|
||||
@@ -24,7 +24,13 @@ public abstract class RecipeSearchField extends TextField implements ItemFilterP
|
||||
field.setMaxStringLength(maxSearchLength);
|
||||
field.setCursorPositionZero();
|
||||
field.setSkipRecipeTokens(true);
|
||||
((SearchTextFormatter) field.getFormatter()).setContextToken("<>");
|
||||
field.setFormatter(new SearchTextFormatter(SearchField.searchParser) {
|
||||
|
||||
@Override
|
||||
protected String getContextToken() {
|
||||
return this.searchParser.getRecipeContextTokens();
|
||||
}
|
||||
});
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@@ -48,15 +54,19 @@ public abstract class RecipeSearchField extends TextField implements ItemFilterP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastKeyTyped(int keyID, char keyChar) {
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getprevioussearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.PREVIOUS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getnextsearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.NEXT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -227,18 +227,24 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastKeyTyped(int keyID, char keyChar) {
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
if (isVisible() && KeyManager.isHashDown("gui.search")) {
|
||||
setFocus(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getprevioussearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.PREVIOUS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getnextsearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.NEXT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,10 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
this.contextToken = contextToken;
|
||||
}
|
||||
|
||||
protected String getContextToken() {
|
||||
return this.contextToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String text) {
|
||||
final int patternMode = NEIClientConfig.getIntSetting("inventory.search.patternMode");
|
||||
@@ -32,13 +36,14 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
return SearchExpressionUtils.visitRecipeSearchExpression(text, visitor);
|
||||
} else {
|
||||
final StringBuilder formattedText = new StringBuilder();
|
||||
final String contextToken = getContextToken();
|
||||
|
||||
for (String[] orQuery : searchParser.splitByDelimiters(text, "|", false)) {
|
||||
final String filterText = orQuery[1];
|
||||
|
||||
formattedText.append(SearchExpressionUtils.HIGHLIGHTS.OR + orQuery[0]);
|
||||
|
||||
for (String[] contextPart : searchParser.splitByDelimiters(filterText, this.contextToken, false)) {
|
||||
for (String[] contextPart : searchParser.splitByDelimiters(filterText, contextToken, false)) {
|
||||
|
||||
if (!contextPart[0].isEmpty()) {
|
||||
formattedText.append(
|
||||
@@ -74,7 +79,11 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
formattedText.append(SearchExpressionUtils.HIGHLIGHTS.QUOTED + "\"");
|
||||
}
|
||||
|
||||
if (!token.rawText.isEmpty()) {
|
||||
if (patternMode == 1 && !token.quotes && isRegexToken(token.rawText)) {
|
||||
formattedText.append(SearchExpressionUtils.HIGHLIGHTS.REGEX + token.rawText.substring(0, 2))
|
||||
.append(tokenColor + token.rawText.substring(2, token.rawText.length() - 1))
|
||||
.append(SearchExpressionUtils.HIGHLIGHTS.REGEX + "/");
|
||||
} else if (!token.rawText.isEmpty()) {
|
||||
formattedText.append(tokenColor + token.rawText);
|
||||
}
|
||||
|
||||
@@ -93,4 +102,8 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
return formattedText.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRegexToken(String search) {
|
||||
return search.length() >= 3 && search.regionMatches(true, 0, "r/", 0, 2) && search.endsWith("/");
|
||||
}
|
||||
}
|
||||
@@ -194,6 +194,7 @@ public class SearchTokenParser {
|
||||
if (patternMode != 3) {
|
||||
return this.filtersCache.computeIfAbsent(skipRecipeTokens + ":" + filterText, _t -> {
|
||||
final List<ItemFilter> searchTokens = new ArrayList<>();
|
||||
final String contextTokens = skipRecipeTokens ? getRecipeContextTokens() : "";
|
||||
|
||||
for (String[] subQuery : splitByDelimiters(filterText, "|", false)) {
|
||||
|
||||
@@ -203,9 +204,10 @@ public class SearchTokenParser {
|
||||
|
||||
final List<ItemFilter> tokens = new ArrayList<>();
|
||||
|
||||
for (String[] contextQuery : splitByDelimiters(subQuery[1], skipRecipeTokens ? "<>" : "", false)) {
|
||||
for (String[] contextQuery : splitByDelimiters(subQuery[1], contextTokens, false)) {
|
||||
|
||||
if (contextQuery[1].isEmpty() || contextQuery[0].startsWith(">")) {
|
||||
if (contextQuery[1].isEmpty() || contextQuery[0].startsWith(">")
|
||||
|| contextQuery[0].startsWith("^")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -277,7 +279,7 @@ public class SearchTokenParser {
|
||||
|
||||
final List<IRecipeFilter> contextList = new ArrayList<>();
|
||||
|
||||
for (String[] contextQuery : splitByDelimiters(orQueryPart[1], "<>", false)) {
|
||||
for (String[] contextQuery : splitByDelimiters(orQueryPart[1], getRecipeContextTokens(), false)) {
|
||||
|
||||
if (contextQuery[1].isEmpty()) {
|
||||
continue;
|
||||
@@ -436,7 +438,9 @@ public class SearchTokenParser {
|
||||
|
||||
final List<String[]> tokens = new ArrayList<>();
|
||||
final int length = input.length();
|
||||
final boolean regexTokens = NEIClientConfig.getIntSetting("inventory.search.patternMode") == 1;
|
||||
boolean insideQuotes = false;
|
||||
boolean insideRegex = false;
|
||||
String token = "";
|
||||
int lastEnd = 0;
|
||||
int index = 0;
|
||||
@@ -444,8 +448,17 @@ public class SearchTokenParser {
|
||||
while (index < length) {
|
||||
final char ch = input.charAt(index);
|
||||
|
||||
if (insideRegex) {
|
||||
if (ch == '/' && input.charAt(index - 1) != '\\') {
|
||||
insideRegex = false;
|
||||
}
|
||||
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!insideQuotes && delimiters.indexOf(ch) >= 0
|
||||
&& (!space || index == 0 || input.charAt(index - 1) == ' ')) {
|
||||
&& (!space || index == 0 || input.charAt(index - 1) == ' ' || lastEnd == index)) {
|
||||
|
||||
if (lastEnd == index) {
|
||||
token += String.valueOf(ch);
|
||||
@@ -464,6 +477,9 @@ public class SearchTokenParser {
|
||||
|
||||
if (ch == '"' && (index == 0 || input.charAt(index - 1) != '\\')) {
|
||||
insideQuotes = !insideQuotes;
|
||||
} else if (regexTokens && !insideQuotes && isRegexStart(input, index)) {
|
||||
insideRegex = true;
|
||||
index++;
|
||||
}
|
||||
|
||||
index++;
|
||||
@@ -474,6 +490,12 @@ public class SearchTokenParser {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private static boolean isRegexStart(String input, int index) {
|
||||
return Character.toLowerCase(input.charAt(index)) == 'r' && index + 1 < input.length()
|
||||
&& input.charAt(index + 1) == '/'
|
||||
&& (index == 0 || !Character.isLetterOrDigit(input.charAt(index - 1)));
|
||||
}
|
||||
|
||||
public String getPrefixes() {
|
||||
if (this.prefixes == null) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
@@ -490,6 +512,11 @@ public class SearchTokenParser {
|
||||
return this.prefixes;
|
||||
}
|
||||
|
||||
public String getRecipeContextTokens() {
|
||||
// '^' is the start anchor and the negated class in regex mode
|
||||
return NEIClientConfig.getIntSetting("inventory.search.patternMode") == 2 ? "<>" : "<>^";
|
||||
}
|
||||
|
||||
public char getRedefinedPrefix(char prefix) {
|
||||
return this.prefixRedefinitions.getOrDefault(prefix, prefix);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.nei.PacketIDs.C2S;
|
||||
|
||||
/**
|
||||
* Waits until the server has processed everything the client sent before. The server handles slot clicks and NEI
|
||||
* packets in the order they came and answers after it has sent the slot updates, so once the answer is here the client
|
||||
* container holds what the server computed.
|
||||
*/
|
||||
public final class ServerSync {
|
||||
|
||||
private static int lastId;
|
||||
private static volatile int awaiting;
|
||||
|
||||
private ServerSync() {}
|
||||
|
||||
public static void request() {
|
||||
|
||||
if (!NEIClientConfig.hasSMPCounterPart()) {
|
||||
awaiting = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
awaiting = ++lastId;
|
||||
new PacketCustom(NEICPH.channel, C2S.SYNC).writeInt(awaiting).sendToServer();
|
||||
}
|
||||
|
||||
public static boolean pending() {
|
||||
return awaiting != 0;
|
||||
}
|
||||
|
||||
static void onReply(int id) {
|
||||
if (id == awaiting) awaiting = 0;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
|
||||
// 1 - partitial hidden
|
||||
// 2 - enabled
|
||||
public int state = 2;
|
||||
public int calculatedWidth;
|
||||
public volatile int calculatedWidth = -1;
|
||||
public final List<ItemStack> items;
|
||||
public final List<SubsetTag> children = new ArrayList<>();
|
||||
protected final SubsetSlot slot = new SubsetSlot();
|
||||
@@ -206,7 +206,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
|
||||
this.state = 2;
|
||||
this.items.clear();
|
||||
this.children.clear();
|
||||
this.calculatedWidth = 0;
|
||||
this.calculatedWidth = -1;
|
||||
}
|
||||
|
||||
public void updateVisiblity(int mx, int my) {
|
||||
@@ -261,6 +261,10 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
public void resize(Rectangle4i screen, Rectangle4i parent, boolean dropRight) {
|
||||
if (calculatedWidth < 0) {
|
||||
calculatedWidth = this.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
|
||||
}
|
||||
|
||||
int height = Math.min(slot.contentHeight(), screen.h);
|
||||
int width = Math.max(calculatedWidth + 2, this.items.isEmpty() ? 0 : 16 + MARGIN * 2);
|
||||
int scrollbarWidth = slot.scrollbarDim().width;
|
||||
@@ -686,12 +690,12 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
|
||||
|
||||
for (SubsetTag tag : list) {
|
||||
tag.children.sort(Comparator.comparing(SubsetTag::displayName));
|
||||
tag.calculatedWidth = tag.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
|
||||
tag.calculatedWidth = -1;
|
||||
}
|
||||
|
||||
root.children.removeIf(child -> child.children.isEmpty() && child.items.isEmpty());
|
||||
root.children.sort(Comparator.comparing(SubsetTag::displayName));
|
||||
root.calculatedWidth = root.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
|
||||
root.calculatedWidth = -1;
|
||||
|
||||
calculateVisibility(root);
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -29,6 +29,10 @@ public abstract class Widget {
|
||||
|
||||
public void lastKeyTyped(int keyID, char keyChar) {}
|
||||
|
||||
public boolean onHotkeyPressed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleClickExt(int mx, int my, int button) {
|
||||
return false;
|
||||
}
|
||||
@@ -51,6 +55,10 @@ public abstract class Widget {
|
||||
return bounds().contains(px, py);
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack getStackMouseOver(int mx, int my) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class WidgetContainer extends Widget {
|
||||
final Rectangle4i bounds = bounds();
|
||||
|
||||
for (Widget widget : this.widgets) {
|
||||
if (widget.bounds().intersects(bounds)) {
|
||||
if (widget.isVisible() && widget.bounds().intersects(bounds)) {
|
||||
widget.draw(mousex, mousey);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
if (widget.contains(mousex, mousey)) {
|
||||
if (widget.isVisible() && widget.contains(mousex, mousey)) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,8 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
if (!widget.contains(mousex, mousey) && widget.handleClickExt(mousex, mousey, button)) {
|
||||
if (widget.isVisible() && !widget.contains(mousex, mousey)
|
||||
&& widget.handleClickExt(mousex, mousey, button)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -126,7 +127,7 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
widget.mouseDragged(mousex, mousey, button, heldTime);
|
||||
if (widget.isVisible()) widget.mouseDragged(mousex, mousey, button, heldTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
widget.mouseUp(mousex, mousey, button);
|
||||
if (widget.isVisible()) widget.mouseUp(mousex, mousey, button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
if (widget.handleKeyPress(keyCode, keyChar)) {
|
||||
if (widget.isVisible() && widget.handleKeyPress(keyCode, keyChar)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -157,11 +158,24 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
widget.lastKeyTyped(keyID, keyChar);
|
||||
if (widget.isVisible()) widget.lastKeyTyped(keyID, keyChar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
if (widget.onHotkeyPressed()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFocused() {
|
||||
return this.isFocused;
|
||||
@@ -214,7 +228,7 @@ public class WidgetContainer extends Widget {
|
||||
public void postDraw(int mousex, int mousey) {
|
||||
|
||||
for (Widget widget : this.widgets) {
|
||||
widget.postDraw(mousex, mousey);
|
||||
if (widget.isVisible()) widget.postDraw(mousex, mousey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -224,7 +238,7 @@ public class WidgetContainer extends Widget {
|
||||
|
||||
for (int index = this.widgets.size() - 1; index >= 0; index--) {
|
||||
final Widget widget = this.widgets.get(index);
|
||||
widget.onGuiClick(mousex, mousey);
|
||||
if (widget.isVisible()) widget.onGuiClick(mousex, mousey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -240,6 +254,17 @@ public class WidgetContainer extends Widget {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(ItemStack itemstack, int mousex, int mousey, List<String> tooltip) {
|
||||
final Widget widget = getWidgetUnderMouse(mousex, mousey);
|
||||
|
||||
if (widget != null) {
|
||||
return widget.handleItemTooltip(itemstack, mousex, mousey, tooltip);
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> handleHotkeys(int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
final Widget widget = getWidgetUnderMouse(mousex, mousey);
|
||||
|
||||
@@ -12,12 +12,14 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import codechicken.nei.BookmarkContainerInfo;
|
||||
import codechicken.nei.CollapsibleItems;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemSorter;
|
||||
import codechicken.nei.ItemStackSet;
|
||||
@@ -33,6 +35,7 @@ import codechicken.nei.SubsetWidget.SubsetTag;
|
||||
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
import codechicken.nei.config.Option;
|
||||
import codechicken.nei.item.FluidDrawer;
|
||||
import codechicken.nei.recipe.CatalystInfo;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
@@ -178,6 +181,8 @@ public class API {
|
||||
|
||||
/**
|
||||
* Add an alias name that this item can be found by in the search field, in addition to its display name.
|
||||
*
|
||||
* @param aliases translation keys, localized at search time
|
||||
*/
|
||||
public static void setAliases(ItemStack item, String... aliases) {
|
||||
final List<String> list = Arrays.asList(aliases).stream().filter(Objects::nonNull).map(String::trim)
|
||||
@@ -337,6 +342,30 @@ public class API {
|
||||
SubsetWidget.addTag(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a group of items that is collapsed into a single entry in the item panel. Groups registered here have
|
||||
* the lowest priority: an item that matches a preset or a collapsibleitems.cfg group stays there. They are active
|
||||
* only while the Collapsible Items option is enabled. Must be called while plugins are loading.
|
||||
*
|
||||
* @param filter A search string for matching items that belong to this group. Also identifies the group when its
|
||||
* expanded state is saved, so changing it resets the saved state.
|
||||
* @return A handle to optionally set the name shown for the group
|
||||
*/
|
||||
public static CollapsibleItems.ApiGroup addCollapsibleGroup(String filter) {
|
||||
return CollapsibleItems.registerGroup(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #addCollapsibleGroup(String)}, but the group is given as a list of item stacks. The stacks
|
||||
* identify the group when its expanded state is saved, so changing them resets the saved state.
|
||||
*
|
||||
* @param items Item stacks that belong to this group
|
||||
* @return A handle to optionally set the name shown for the group
|
||||
*/
|
||||
public static CollapsibleItems.ApiGroup addCollapsibleGroup(Iterable<ItemStack> items) {
|
||||
return CollapsibleItems.registerGroup(items);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addSearchProvider(ISearchProvider provider) {}
|
||||
|
||||
@@ -375,6 +404,16 @@ public class API {
|
||||
StackInfo.stackStringifyHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the default rendering of a fluid in NEI fluid display slots and fluid tanks.
|
||||
*
|
||||
* @param fluid the fluid to render
|
||||
* @param renderer the renderer, or null to restore the default rendering
|
||||
*/
|
||||
public static void registerFluidRenderer(Fluid fluid, IFluidRenderer renderer) {
|
||||
FluidDrawer.registerFluidRenderer(fluid, renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel
|
||||
* Recipes) Allows players to see what ingredient they need to craft in order to make recipes from a recipe
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package codechicken.nei.api;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
/**
|
||||
* Custom renderer for a fluid, used by NEI fluid display slots and fluid tanks in recipes.
|
||||
* <p>
|
||||
* Register with {@link API#registerFluidRenderer(Fluid, IFluidRenderer)}.
|
||||
*/
|
||||
public interface IFluidRenderer {
|
||||
|
||||
/**
|
||||
* Renders one 16x16 tile of the fluid. Partial tiles of a tank are clipped by NEI. The amount overlay is drawn by
|
||||
* NEI.
|
||||
*/
|
||||
void renderFluid(Fluid fluid, int x, int y);
|
||||
}
|
||||
@@ -59,6 +59,7 @@ import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.config.ArrayDumper;
|
||||
import codechicken.nei.config.HandlerDumper;
|
||||
import codechicken.nei.config.ItemPanelDumper;
|
||||
import codechicken.nei.config.RecipeDumper;
|
||||
import codechicken.nei.config.RegistryDumper;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.item.FluidDisplayRenderer;
|
||||
@@ -284,6 +285,7 @@ public class ItemInfo {
|
||||
});
|
||||
API.addOption(new ItemPanelDumper("tools.dump.itempanel"));
|
||||
API.addOption(new HandlerDumper("tools.dump.handlers"));
|
||||
API.addOption(new RecipeDumper("tools.dump.recipes"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -333,12 +335,6 @@ public class ItemInfo {
|
||||
}
|
||||
|
||||
private static void addVanillaBlockProperties() {
|
||||
API.setOverrideName(new ItemStack(Blocks.flowing_water), "Water Source");
|
||||
API.setOverrideName(new ItemStack(Blocks.water), "Water Still");
|
||||
API.setOverrideName(new ItemStack(Blocks.flowing_lava), "Lava Source");
|
||||
API.setOverrideName(new ItemStack(Blocks.lava), "Lava Still");
|
||||
API.setOverrideName(new ItemStack(Blocks.end_portal), "End Portal");
|
||||
API.setOverrideName(new ItemStack(Blocks.end_portal_frame), "End Portal Frame");
|
||||
API.hideItem(new ItemStack(Blocks.double_stone_slab, 1, OreDictionary.WILDCARD_VALUE));
|
||||
API.hideItem(new ItemStack(Blocks.double_wooden_slab, 1, OreDictionary.WILDCARD_VALUE));
|
||||
API.hideItem(new ItemStack(Blocks.carrots));
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.LinkedList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.config.GuiOptionList;
|
||||
import codechicken.nei.config.OptionCycled;
|
||||
|
||||
public class NEIInfo {
|
||||
@@ -14,11 +13,7 @@ public class NEIInfo {
|
||||
|
||||
public static void load(World world) {
|
||||
OptionCycled modeOption = (OptionCycled) NEIClientConfig.getOptionList().getOption("inventory.cheatmode");
|
||||
final boolean worldConfig = NEIClientConfig.isWorldSpecific("inventory.cheatmode");
|
||||
// kept alive so the WeakReference in Option.slotRef isn't GC'd before copyGlobals/cycle use it
|
||||
GuiOptionList env = modeOption.parent.synthesizeEnvironment(worldConfig);
|
||||
if (!modeOption.optionValid(modeOption.value())) {
|
||||
modeOption.copyGlobals();
|
||||
modeOption.cycle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import codechicken.nei.BookmarkContainerInfo;
|
||||
import codechicken.nei.FavoriteRecipes;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.ItemQuantityField;
|
||||
import codechicken.nei.ItemsGrid.ItemsGridSlot;
|
||||
import codechicken.nei.KeyManager;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -38,6 +37,7 @@ import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiFavoriteButton;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiUsageRecipe;
|
||||
import codechicken.nei.recipe.HoveredRecipe;
|
||||
import codechicken.nei.recipe.Recipe;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.RecipeHandlerRef;
|
||||
@@ -343,7 +343,6 @@ public abstract class ShortcutInputHandler {
|
||||
if (handlerRef != null) {
|
||||
final GuiFavoriteButton button = new GuiFavoriteButton(handlerRef, 0, 0);
|
||||
button.saveRecipeInBookmark();
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -415,41 +414,37 @@ public abstract class ShortcutInputHandler {
|
||||
|
||||
private static Recipe getFocusedRecipe(ItemStack stackover, int mousex, int mousey, boolean useFavorites) {
|
||||
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
||||
Recipe recipe = null;
|
||||
|
||||
if (useFavorites) {
|
||||
ItemsGridSlot itemSlot = ItemPanels.itemPanel.getSlotMouseOver(mousex, mousey);
|
||||
|
||||
if (itemSlot == null) {
|
||||
itemSlot = ItemPanels.itemPanel.historyPanel.getSlotMouseOver(mousex, mousey);
|
||||
}
|
||||
|
||||
if (itemSlot == null) {
|
||||
itemSlot = ItemPanels.itemPanel.craftablesPanel.getSlotMouseOver(mousex, mousey);
|
||||
}
|
||||
|
||||
if (itemSlot != null) {
|
||||
final RecipeId recipeId = itemSlot.getRecipeId();
|
||||
|
||||
if (recipeId != null && (recipe = Recipe.of(recipeId)) != null) {
|
||||
|
||||
recipe.getIngredients().stream().forEach(ingr -> {
|
||||
final List<ItemStack> permutations = ingr.getPermutations();
|
||||
for (int index = 0; index < permutations.size(); index++) {
|
||||
if (FavoriteRecipes.contains(permutations.get(index))) {
|
||||
ingr.setActiveIndex(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if (gui instanceof GuiRecipe<?>guiRecipe) {
|
||||
final Recipe focusedRecipe = guiRecipe.getFocusedRecipe();
|
||||
|
||||
if (focusedRecipe != null) {
|
||||
return focusedRecipe;
|
||||
}
|
||||
}
|
||||
|
||||
if (gui instanceof GuiRecipe<?>guiRecipe) {
|
||||
recipe = guiRecipe.getFocusedRecipe();
|
||||
if (!useFavorites) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final HoveredRecipe hovered = HoveredRecipe.of(gui, stackover);
|
||||
|
||||
if (hovered == null || hovered.source != HoveredRecipe.Source.ITEM_PANEL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Recipe recipe = Recipe.of(hovered.recipeId);
|
||||
|
||||
if (recipe != null) {
|
||||
recipe.getIngredients().stream().forEach(ingr -> {
|
||||
final List<ItemStack> permutations = ingr.getPermutations();
|
||||
for (int index = 0; index < permutations.size(); index++) {
|
||||
if (FavoriteRecipes.contains(permutations.get(index))) {
|
||||
ingr.setActiveIndex(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return recipe;
|
||||
@@ -529,7 +524,9 @@ public abstract class ShortcutInputHandler {
|
||||
}
|
||||
|
||||
final BookmarksGridSlot slot = ItemPanels.bookmarkPanel.getSlotMouseOver(mousex, mousey);
|
||||
final RecipeId recipeId = getHotkeyRecipeId(gui, mousex, mousey, stack, slot);
|
||||
final HoveredRecipe hovered = HoveredRecipe.of(gui, stack);
|
||||
final RecipeId recipeId = hovered == null || hovered.source == HoveredRecipe.Source.OTHER
|
||||
|| hovered.source == HoveredRecipe.Source.BOOKMARK && hovered.favorite ? null : hovered.recipeId;
|
||||
|
||||
if (slot != null) {
|
||||
final BookmarkGroup group = slot.getGroup();
|
||||
@@ -729,36 +726,4 @@ public abstract class ShortcutInputHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static RecipeId getHotkeyRecipeId(GuiContainer gui, int mousex, int mousey, ItemStack stack,
|
||||
BookmarksGridSlot slot) {
|
||||
|
||||
if (slot != null) {
|
||||
return slot.getType() == BookmarkItemType.INGREDIENT ? null : slot.getRecipeId();
|
||||
}
|
||||
|
||||
ItemsGridSlot itemSlot = ItemPanels.itemPanel.getSlotMouseOver(mousex, mousey);
|
||||
|
||||
if (itemSlot == null) {
|
||||
itemSlot = ItemPanels.itemPanel.historyPanel.getSlotMouseOver(mousex, mousey);
|
||||
}
|
||||
|
||||
if (itemSlot == null) {
|
||||
itemSlot = ItemPanels.itemPanel.craftablesPanel.getSlotMouseOver(mousex, mousey);
|
||||
}
|
||||
|
||||
if (itemSlot != null) {
|
||||
return itemSlot.getRecipeId();
|
||||
}
|
||||
|
||||
if (gui instanceof GuiRecipe<?>guiRecipe) {
|
||||
final Recipe focusedRecipe = guiRecipe.getFocusedRecipe();
|
||||
|
||||
if (focusedRecipe != null) {
|
||||
return focusedRecipe.getRecipeId();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import static org.objectweb.asm.Opcodes.ILOAD;
|
||||
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
|
||||
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
|
||||
import static org.objectweb.asm.Opcodes.IRETURN;
|
||||
import static org.objectweb.asm.Opcodes.NEW;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -22,11 +23,14 @@ import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import codechicken.lib.asm.ASMBlock;
|
||||
@@ -98,6 +102,48 @@ public class NEITransformer implements IClassTransformer {
|
||||
}
|
||||
});
|
||||
|
||||
if (Boolean.getBoolean("nei.recipeOrigins")) {
|
||||
// Replace the plain ArrayList CraftingManager's constructor builds its recipe list with, so every recipe
|
||||
// added anywhere (including vanilla's own, added in that same constructor) is observed for
|
||||
// codechicken.nei.recipe.debug.RecipeOrigins. Must be done at classload time, since by the time any mod
|
||||
// code runs vanilla has already populated the list. Capturing a stack trace per recipe is slow, so this is
|
||||
// opt-in via -Dnei.recipeOrigins=true.
|
||||
transformer.add(
|
||||
new MethodTransformer(
|
||||
new ObfMapping("net/minecraft/item/crafting/CraftingManager", "<init>", "()V")) {
|
||||
|
||||
@Override
|
||||
public void transform(MethodNode mv) {
|
||||
ASMHelper.logger.debug("NEI: Hooking CraftingManager recipe list for origin tracking");
|
||||
|
||||
TypeInsnNode newInsn = null;
|
||||
MethodInsnNode initInsn = null;
|
||||
|
||||
// only the first ArrayList construction, the recipe list field
|
||||
for (AbstractInsnNode insn : mv.instructions.toArray()) {
|
||||
if (newInsn == null) {
|
||||
if (insn.getOpcode() == NEW
|
||||
&& "java/util/ArrayList".equals(((TypeInsnNode) insn).desc)) {
|
||||
newInsn = (TypeInsnNode) insn;
|
||||
}
|
||||
} else if (insn.getOpcode() == INVOKESPECIAL
|
||||
&& "java/util/ArrayList".equals(((MethodInsnNode) insn).owner)
|
||||
&& "<init>".equals(((MethodInsnNode) insn).name)) {
|
||||
initInsn = (MethodInsnNode) insn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newInsn == null || initInsn == null) {
|
||||
ASMHelper.logger.warn("NEI: CraftingManager recipe list not found, origins disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
newInsn.desc = initInsn.owner = "codechicken/nei/recipe/debug/RecipeOrigins$TrackingList";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// put glint alpha into the buffer correctly for exporting
|
||||
transformer.add(
|
||||
new MethodReplacer(
|
||||
|
||||
@@ -452,8 +452,9 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
if (!this.isEmpty() && this.gridGenerator.maxAbsoluteSlotIndex > 0) {
|
||||
final GroupingItem groupingItem = ItemPanels.bookmarkPanel.groupingItem;
|
||||
final int sortableGroupId = ItemPanels.bookmarkPanel.sortableGroup != null
|
||||
? ItemPanels.bookmarkPanel.sortableGroup.groupId
|
||||
: -3;
|
||||
&& ItemPanels.bookmarkPanel.sortableGroup.grid == this
|
||||
? ItemPanels.bookmarkPanel.sortableGroup.groupId
|
||||
: -3;
|
||||
final int rowShift = this.page * this.rows;
|
||||
Map<Integer, Integer> groups = this.gridGenerator.rowToGroupId;
|
||||
|
||||
@@ -795,10 +796,10 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
this.bookmarkItems.add(item);
|
||||
}
|
||||
|
||||
sortableGroup.grid = this;
|
||||
sortableGroup.groupId = groupId;
|
||||
sortableGroup.update(this, groupId);
|
||||
this.onItemsChanged();
|
||||
this.getMask();// force generate grid
|
||||
overGroupId = getRowGroupId(overRowIndex);
|
||||
}
|
||||
|
||||
if (sortableGroup.groupId == overGroupId) {
|
||||
@@ -1284,7 +1285,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
for (BookmarksGridSlot slot : getMask()) {
|
||||
Rectangle4i rect = getSlotRect(slot.slotIndex);
|
||||
|
||||
if (sortableGroup != null && slot.getGroupId() == sortableGroup.groupId) {
|
||||
if (sortableGroup != null && sortableGroup.matches(this, slot.getGroupId())) {
|
||||
NEIClientUtils.drawRect(rect.x, rect.y, rect.w, rect.h, DRAG_COLOR);
|
||||
} else if (sortableItem != null && sortableItem.items.contains(slot.itemIndex)) {
|
||||
NEIClientUtils.drawRect(rect.x, rect.y, rect.w, rect.h, DRAG_COLOR);
|
||||
@@ -1313,7 +1314,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
final SortableItem sortableItem = LayoutManager.bookmarkPanel.sortableItem;
|
||||
|
||||
for (BookmarksGridSlot slot : getMask()) {
|
||||
if ((sortableGroup == null || slot.getGroupId() != sortableGroup.groupId)
|
||||
if ((sortableGroup == null || !sortableGroup.matches(this, slot.getGroupId()))
|
||||
&& (sortableItem == null || !sortableItem.items.contains(slot.itemIndex))) {
|
||||
slot.afterDraw(getSlotRect(slot.slotIndex), mouseContext);
|
||||
}
|
||||
@@ -1330,7 +1331,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
|
||||
for (BookmarksGridSlot slot : getMask()) {
|
||||
|
||||
if ((sortableGroup == null || slot.getGroupId() != sortableGroup.groupId)
|
||||
if ((sortableGroup == null || !sortableGroup.matches(this, slot.getGroupId()))
|
||||
&& (sortableItem == null || !sortableItem.items.contains(slot.itemIndex))) {
|
||||
final BookmarkItem item = slot.getBookmarkItem();
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
||||
import codechicken.nei.ItemSorter;
|
||||
@@ -132,7 +131,7 @@ public class BookmarkGridGenerator {
|
||||
itemIndex++;
|
||||
}
|
||||
|
||||
} else if (group.crafting != null && group.crafting.itemToRecipe.values().contains(bookmarkItem.recipeId)) {
|
||||
} else if (group.crafting != null && group.crafting.recipeToItems.containsKey(bookmarkItem.recipeId)) {
|
||||
absoluteSlotIndex = generateCollapsedRecipe(prevBookmarkItem, itemIndex, absoluteSlotIndex, borderGrid);
|
||||
prevBookmarkItem = bookmarkItem;
|
||||
|
||||
@@ -218,8 +217,7 @@ public class BookmarkGridGenerator {
|
||||
}
|
||||
|
||||
private List<Integer> getShadows(BookmarkGroup group, RecipeId recipeId) {
|
||||
return group.crafting.itemToRecipe.entrySet().stream().filter(entry -> recipeId.equals(entry.getValue()))
|
||||
.map(entry -> entry.getKey()).collect(Collectors.toList());
|
||||
return new ArrayList<>(group.crafting.recipeToItems.getOrDefault(recipeId, Collections.emptyList()));
|
||||
}
|
||||
|
||||
private int nextSlotIndex(int index, BookmarkItem previousMeta, BookmarkItem meta, BookmarkViewMode viewMode) {
|
||||
@@ -340,7 +338,8 @@ public class BookmarkGridGenerator {
|
||||
0,
|
||||
chainItem.getItem(),
|
||||
null,
|
||||
group);
|
||||
group,
|
||||
this.grid);
|
||||
} else {
|
||||
return new BookmarksGridSlot(
|
||||
slotIndex,
|
||||
@@ -350,7 +349,8 @@ public class BookmarkGridGenerator {
|
||||
chainItem.getCalculatedMultiplier(),
|
||||
chainItem.getItem(),
|
||||
chainItem.calculatedType,
|
||||
group);
|
||||
group,
|
||||
this.grid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ public class BookmarkItem {
|
||||
private static synchronized String getItemGUID(ItemStack stack) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(stack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
if (fluidStack != null && (fluidStack.amount > 0 || !StackInfo.isFluidContainer(stack))) {
|
||||
return fluidStack.getFluid().getName() + ":" + fluidStack.tag;
|
||||
} else {
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -23,7 +22,9 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
|
||||
@@ -79,10 +80,21 @@ public class BookmarkStorage {
|
||||
|
||||
public int getNamespaceSize() {
|
||||
|
||||
if (this.namespaces.get(this.namespaces.size() - 1).size() > 0) {
|
||||
this.namespaces.add(new BookmarkGrid());
|
||||
} else if (this.activeNamespaceIndex == this.namespaces.size() - 2 && getActiveGrid().size() == 0) {
|
||||
this.namespaces.remove(this.namespaces.size() - 1);
|
||||
final int lastIndex = this.namespaces.size() - 1;
|
||||
final BookmarkGrid lastGrid = this.namespaces.get(lastIndex);
|
||||
final SortableGroup sortableGroup = ItemPanels.bookmarkPanel.sortableGroup;
|
||||
|
||||
if (lastGrid.size() > 0) {
|
||||
if (sortableGroup == null || sortableGroup.grid != lastGrid || !sortableGroup.aloneInGrid) {
|
||||
this.namespaces.add(new BookmarkGrid());
|
||||
}
|
||||
} else if (lastIndex > 0 && this.activeNamespaceIndex != lastIndex) {
|
||||
final BookmarkGrid prevGrid = this.namespaces.get(lastIndex - 1);
|
||||
|
||||
if (sortableGroup != null && sortableGroup.grid == prevGrid && sortableGroup.aloneInGrid
|
||||
|| prevGrid == getActiveGrid() && prevGrid.size() == 0) {
|
||||
this.namespaces.remove(lastIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return this.namespaces.size();
|
||||
@@ -198,6 +210,11 @@ public class BookmarkStorage {
|
||||
final BookmarkItem item = BookmarkItem.of(parser.parse(itemStr).getAsJsonObject());
|
||||
|
||||
if (item != null) {
|
||||
|
||||
if (!grid.groups.containsKey(item.groupId)) {
|
||||
item.groupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
||||
}
|
||||
|
||||
grid.addItem(item, false);
|
||||
} else {
|
||||
wasError = true;
|
||||
@@ -213,14 +230,7 @@ public class BookmarkStorage {
|
||||
}
|
||||
|
||||
if (wasError) {
|
||||
try {
|
||||
Files.copy(
|
||||
bookmarkFile,
|
||||
new File(bookmarkFile.getAbsolutePath() + ".backup-" + System.currentTimeMillis()));
|
||||
NEIClientConfig.logger.info("Backed up invalid bookmark file to {}", bookmarkFile);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to backup invalid bookmark file to {}", bookmarkFile, e);
|
||||
}
|
||||
NEIClientUtils.backupFile(bookmarkFile);
|
||||
}
|
||||
|
||||
for (BookmarkGrid gr : namespaces) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.ItemsGrid.ItemsGridSlot;
|
||||
import codechicken.nei.ItemsGrid.MouseContext;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -65,7 +64,8 @@ public class BookmarksGridSlot extends ItemsGridSlot {
|
||||
protected final int rowIndex;
|
||||
|
||||
public BookmarksGridSlot(int slotIndex, int itemIndex, long realMultiplier, long shiftAmount,
|
||||
long calculatedMultiplier, BookmarkItem bookmarkItem, CalculatedType calculatedType, BookmarkGroup group) {
|
||||
long calculatedMultiplier, BookmarkItem bookmarkItem, CalculatedType calculatedType, BookmarkGroup group,
|
||||
BookmarkGrid grid) {
|
||||
super(
|
||||
slotIndex,
|
||||
itemIndex,
|
||||
@@ -96,7 +96,6 @@ public class BookmarksGridSlot extends ItemsGridSlot {
|
||||
: CalculatedType.RESULT;
|
||||
}
|
||||
|
||||
final BookmarkGrid grid = ItemPanels.bookmarkPanel.getGrid();
|
||||
final BookmarkItem prevItem = grid.getCalculatedItem(
|
||||
grid.gridGenerator.slotToItem.getOrDefault(grid.gridGenerator.itemToSlot.get(this.itemIndex) - 1, -1));
|
||||
this.isFirstOutput = this.itemIndex >= 0 && this.bookmarkItem.type == BookmarkItemType.RESULT
|
||||
|
||||
@@ -111,6 +111,7 @@ public class RecipeChainDetails {
|
||||
|
||||
public final Map<Integer, BookmarkChainItem> calculatedItems = new HashMap<>();
|
||||
public final Map<Integer, RecipeId> itemToRecipe = new HashMap<>();
|
||||
public final Map<RecipeId, List<Integer>> recipeToItems = new HashMap<>();
|
||||
public final Set<RecipeId> outputRecipes = new HashSet<>();
|
||||
public final Set<RecipeId> recipeInMiddle = new HashSet<>();
|
||||
|
||||
@@ -124,6 +125,7 @@ public class RecipeChainDetails {
|
||||
}
|
||||
|
||||
this.itemToRecipe.clear();
|
||||
this.recipeToItems.clear();
|
||||
this.outputRecipes.clear();
|
||||
this.recipeInMiddle.clear();
|
||||
this.calculatedItems.clear();
|
||||
@@ -180,6 +182,10 @@ public class RecipeChainDetails {
|
||||
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, RecipeId> entry : this.itemToRecipe.entrySet()) {
|
||||
this.recipeToItems.computeIfAbsent(entry.getValue(), recipeId -> new ArrayList<>()).add(entry.getKey());
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, BookmarkItem> entry : chainItems.entrySet()) {
|
||||
final int itemIndex = entry.getKey();
|
||||
if (itemIndex >= 0 && this.calculatedItems.containsKey(itemIndex)) {
|
||||
|
||||
@@ -13,13 +13,23 @@ public class SortableGroup {
|
||||
|
||||
public int groupId;
|
||||
public BookmarkGrid grid;
|
||||
public boolean aloneInGrid;
|
||||
|
||||
public int shiftX = 0;
|
||||
public int shiftY = 0;
|
||||
|
||||
public SortableGroup(BookmarkGrid grid, int groupId) {
|
||||
update(grid, groupId);
|
||||
}
|
||||
|
||||
public void update(BookmarkGrid grid, int groupId) {
|
||||
this.grid = grid;
|
||||
this.groupId = groupId;
|
||||
this.aloneInGrid = grid.bookmarkItems.stream().allMatch(item -> item.groupId == groupId);
|
||||
}
|
||||
|
||||
public boolean matches(BookmarkGrid grid, int groupId) {
|
||||
return this.grid == grid && this.groupId == groupId;
|
||||
}
|
||||
|
||||
public void postDraw(int mousex, int mousey) {
|
||||
|
||||
@@ -37,8 +37,8 @@ public class SortableItem {
|
||||
&& (group.viewMode == BookmarkViewMode.TODO_LIST || group.crafting != null);
|
||||
this.crossGroup = !group.collapsed && group.viewMode == BookmarkViewMode.TODO_LIST
|
||||
&& bookmarkItem.type != BookmarkItemType.INGREDIENT;
|
||||
this.isCollapsedRecipe = group.crafting != null && group.crafting.itemToRecipe.values().stream()
|
||||
.anyMatch(recipeId -> this.bookmarkItem.equalsRecipe(recipeId, this.bookmarkItem.groupId));
|
||||
this.isCollapsedRecipe = group.crafting != null && this.bookmarkItem.recipeId != null
|
||||
&& group.crafting.recipeToItems.containsKey(this.bookmarkItem.recipeId);
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package codechicken.nei.bookmark.tree;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
class Camera {
|
||||
|
||||
private static final float ZOOM_MIN = 0.1f;
|
||||
@@ -39,23 +41,34 @@ class Camera {
|
||||
&& y < this.widgetY + this.widgetH;
|
||||
}
|
||||
|
||||
public void startDrag(int mouseX, int mouseY) {
|
||||
public void startDrag(Point2D mouse) {
|
||||
this.dragging = true;
|
||||
this.lastDragX = mouseX;
|
||||
this.lastDragY = mouseY;
|
||||
this.lastDragX = (float) mouse.getX();
|
||||
this.lastDragY = (float) mouse.getY();
|
||||
}
|
||||
|
||||
public void drag(int mouseX, int mouseY) {
|
||||
public void drag(Point2D mouse) {
|
||||
if (!this.dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
final float mouseX = (float) mouse.getX();
|
||||
final float mouseY = (float) mouse.getY();
|
||||
|
||||
this.scrollX -= (mouseX - this.lastDragX) / this.zoomLevel;
|
||||
this.scrollY -= (mouseY - this.lastDragY) / this.zoomLevel;
|
||||
this.lastDragX = mouseX;
|
||||
this.lastDragY = mouseY;
|
||||
}
|
||||
|
||||
public void update(Point2D mouse, int treeWidth, int treeHeight) {
|
||||
if (this.dragging && Mouse.isButtonDown(0)) {
|
||||
drag(mouse);
|
||||
}
|
||||
|
||||
clampToBounds(treeWidth, treeHeight);
|
||||
}
|
||||
|
||||
public void endDrag() {
|
||||
this.dragging = false;
|
||||
}
|
||||
@@ -79,7 +92,6 @@ class Camera {
|
||||
} else {
|
||||
this.scrollY -= direction * this.widgetH / (SCROLL_STEP_DIVISOR * this.zoomLevel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void centerOn(float worldX, float worldY) {
|
||||
|
||||
@@ -142,7 +142,11 @@ class CraftingTreeCanvas {
|
||||
public int treeWidth = 0;
|
||||
public int treeHeight = 0;
|
||||
|
||||
private final Camera camera = new Camera();
|
||||
private final Camera camera;
|
||||
|
||||
public CraftingTreeCanvas(Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
public void setViewport(int x, int y, int w, int h) {
|
||||
this.camera.setViewport(x, y, w, h);
|
||||
@@ -165,12 +169,12 @@ class CraftingTreeCanvas {
|
||||
: -FIT_MARGIN;
|
||||
}
|
||||
|
||||
public void startDrag(int mouseX, int mouseY) {
|
||||
this.camera.startDrag(mouseX, mouseY);
|
||||
public void startDrag(Point2D mouse) {
|
||||
this.camera.startDrag(mouse);
|
||||
}
|
||||
|
||||
public void drag(int mouseX, int mouseY) {
|
||||
this.camera.drag(mouseX, mouseY);
|
||||
public void drag(Point2D mouse) {
|
||||
this.camera.drag(mouse);
|
||||
}
|
||||
|
||||
public void endDrag() {
|
||||
@@ -255,7 +259,7 @@ class CraftingTreeCanvas {
|
||||
|
||||
public void draw(Point2D mouse, Set<BookmarkItem> collapsedItems, SearchResult searchResult,
|
||||
boolean useInventorySnapshot, ItemTreeSlot hoveredNode, ItemTreeSlot deleteHoverNode) {
|
||||
this.camera.clampToBounds(this.treeWidth, this.treeHeight);
|
||||
this.camera.update(mouse, this.treeWidth, this.treeHeight);
|
||||
|
||||
final float zScrollX = this.camera.scrollX * this.camera.zoomLevel;
|
||||
final float zScrollY = this.camera.scrollY * this.camera.zoomLevel;
|
||||
|
||||
@@ -2,9 +2,12 @@ package codechicken.nei.bookmark.tree;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.bookmark.BookmarkGroup;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
|
||||
class CraftingTreeState {
|
||||
@@ -25,6 +28,8 @@ class CraftingTreeState {
|
||||
HANDLERS
|
||||
}
|
||||
|
||||
private static final Map<BookmarkGroup, CraftingTreeState> GROUP_STATES = new WeakHashMap<>();
|
||||
|
||||
private static final String KEY_STATS_VISIBLE = "craftingTree.statsVisible";
|
||||
private static final String KEY_STATS_SECTIONS = "craftingTree.statsSections";
|
||||
private static final String KEY_USE_INVENTORY_SNAPSHOT = "craftingTree.useInventorySnapshot";
|
||||
@@ -35,6 +40,8 @@ class CraftingTreeState {
|
||||
public boolean useInventorySnapshot = false;
|
||||
public CollapseMode collapseMode = CollapseMode.EXPANDED;
|
||||
|
||||
public boolean initialized;
|
||||
public final Camera camera = new Camera();
|
||||
public final Set<BookmarkItem> collapsedItems = new HashSet<>();
|
||||
public ItemTreeSlot replaceRecipeNode;
|
||||
|
||||
@@ -65,6 +72,9 @@ class CraftingTreeState {
|
||||
? collapseModes[savedCollapseMode]
|
||||
: CollapseMode.EXPANDED;
|
||||
this.replaceRecipeNode = null;
|
||||
this.searchItemResult = null;
|
||||
this.searchStatsResult = null;
|
||||
this.camera.endDrag();
|
||||
}
|
||||
|
||||
public void toggleStatsPanelVisible() {
|
||||
@@ -98,6 +108,10 @@ class CraftingTreeState {
|
||||
NEIClientConfig.world.nbt.setInteger(KEY_COLLAPSE_MODE, this.collapseMode.ordinal());
|
||||
}
|
||||
|
||||
public static CraftingTreeState of(BookmarkGroup group) {
|
||||
return GROUP_STATES.computeIfAbsent(group, g -> new CraftingTreeState());
|
||||
}
|
||||
|
||||
public SearchResult activeSearchResult() {
|
||||
return this.searchItemResult != null ? this.searchItemResult : this.searchStatsResult;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@@ -40,6 +39,7 @@ import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.KeyManager;
|
||||
import codechicken.nei.LRUCache;
|
||||
import codechicken.nei.NEICPH;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.SearchField.GuiSearchField;
|
||||
@@ -58,6 +58,7 @@ import codechicken.nei.drawable.DrawableResource;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.guihook.IGuiClientSide;
|
||||
import codechicken.nei.guihook.IGuiHandleMouseWheel;
|
||||
import codechicken.nei.guihook.IGuiHotkeyListener;
|
||||
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
|
||||
import codechicken.nei.recipe.AutoCraftingManager;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
@@ -67,6 +68,7 @@ import codechicken.nei.recipe.GuiRecipeButton.UpdateRecipeButtonsEvent;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.Recipe;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.RecipeItemsTooltipLineHandler;
|
||||
import codechicken.nei.recipe.RecipeTooltipLineHandler;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.util.EmptyContainer;
|
||||
@@ -76,7 +78,7 @@ import codechicken.nei.util.SlotInaccessible;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGuiClientSide, IGuiHandleMouseWheel,
|
||||
IContainerTooltipHandler, IGuiContainerOverlay {
|
||||
IGuiHotkeyListener, IContainerTooltipHandler, IGuiContainerOverlay {
|
||||
|
||||
public static class EventHandler {
|
||||
|
||||
@@ -101,24 +103,23 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MARGIN = 4;
|
||||
private static final int PADDING = 9;
|
||||
private static final int PADDING_TOP = 22;
|
||||
|
||||
private static final DrawableResource BG_TEXTURE = new DrawableBuilder(
|
||||
"nei:textures/gui/craftingtree.png",
|
||||
0,
|
||||
0,
|
||||
64,
|
||||
64).build();
|
||||
64).setSlices(PADDING, PADDING, PADDING_TOP, PADDING).build();
|
||||
|
||||
private static final DateTimeFormatter SCREENSHOT_DATE_FORMAT = DateTimeFormatter
|
||||
.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
|
||||
|
||||
private static final int MARGIN = 4;
|
||||
private static final int PADDING = 9;
|
||||
private static final int PADDING_TOP = 22;
|
||||
|
||||
private static LRUCache<String, String> handlerTitleCache = new LRUCache<>(100);
|
||||
private final LRUCache<String, String> handlerTitleCache = new LRUCache<>(100);
|
||||
|
||||
private GuiScreen prevGui;
|
||||
private boolean isFirstScreen = true;
|
||||
|
||||
private final BookmarkGrid grid;
|
||||
private final int groupId;
|
||||
@@ -127,15 +128,16 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
private final StatsPanel statsPanel = new StatsPanel();
|
||||
private final StatsSectionsMenu statsSectionsMenu = new StatsSectionsMenu();
|
||||
private final CraftingTreeCanvas canvas = new CraftingTreeCanvas();
|
||||
private final CraftingTreeCanvas canvas;
|
||||
private boolean statsPanelVisible;
|
||||
|
||||
private GuiSearchField searchField;
|
||||
|
||||
private RecipeTooltipLineHandler recipeTooltipLineHandler;
|
||||
private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
|
||||
private RecipeItemsTooltipLineHandler recipeItemsTooltipLineHandler;
|
||||
|
||||
private final CraftingTreeState uiState = new CraftingTreeState();
|
||||
private final CraftingTreeState uiState;
|
||||
private final CraftingTreeToolbar toolbar;
|
||||
|
||||
private ItemTreeSlot hoveredNode;
|
||||
@@ -147,6 +149,8 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
this.grid = grid;
|
||||
this.groupId = groupId;
|
||||
|
||||
this.uiState = CraftingTreeState.of(grid.getGroup(groupId));
|
||||
this.canvas = new CraftingTreeCanvas(this.uiState.camera);
|
||||
this.toolbar = new CraftingTreeToolbar(this.uiState);
|
||||
}
|
||||
|
||||
@@ -159,7 +163,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
final ItemTreeSlot replaceNode = this.uiState.replaceRecipeNode;
|
||||
this.uiState.replaceRecipeNode = null;
|
||||
|
||||
if (recipe != null) {
|
||||
if (recipe != null && this.grid.getGroup(this.groupId) != null) {
|
||||
final RecipeId recipeId = recipe.getRecipeId();
|
||||
boolean changed = false;
|
||||
|
||||
@@ -187,6 +191,13 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
|
||||
// the group can be removed from the bookmark panel while a recipe screen opened from this tree is shown
|
||||
if (this.grid.getGroup(this.groupId) == null) {
|
||||
this.mc.displayGuiScreen(this.prevGui);
|
||||
return;
|
||||
}
|
||||
|
||||
this.xSize = this.width;
|
||||
this.ySize = this.height;
|
||||
|
||||
@@ -283,7 +294,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
this.canvas.graph.rebuild(this.math);
|
||||
|
||||
if (this.isFirstScreen) {
|
||||
if (!this.uiState.initialized) {
|
||||
updateCollapsedItems();
|
||||
} else {
|
||||
this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, anchor);
|
||||
@@ -291,8 +302,8 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
rebuildStatsPanel();
|
||||
|
||||
if (this.isFirstScreen) {
|
||||
this.isFirstScreen = false;
|
||||
if (!this.uiState.initialized) {
|
||||
this.uiState.initialized = true;
|
||||
this.canvas.fitToView();
|
||||
}
|
||||
}
|
||||
@@ -328,15 +339,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
this.hoveredNode = canHover && hoveredBadgeHandler == null ? this.canvas.getNodeMouseOver(getMousePosition())
|
||||
: null;
|
||||
|
||||
BG_TEXTURE.draw(
|
||||
MARGIN,
|
||||
MARGIN,
|
||||
this.width - MARGIN * 2,
|
||||
this.height - MARGIN * 2,
|
||||
PADDING,
|
||||
PADDING,
|
||||
PADDING_TOP,
|
||||
PADDING);
|
||||
BG_TEXTURE.draw(MARGIN, MARGIN, this.width - MARGIN * 2, this.height - MARGIN * 2);
|
||||
|
||||
if (this.math.outputRecipes.isEmpty()) {
|
||||
drawCenteredString(
|
||||
@@ -755,7 +758,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
return true;
|
||||
}
|
||||
|
||||
this.canvas.startDrag(mouseX, mouseY);
|
||||
this.canvas.startDrag(getMousePosition());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -776,7 +779,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
}
|
||||
|
||||
this.canvas.drag(mouseX, mouseY);
|
||||
this.canvas.drag(getMousePosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -841,7 +844,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
(int) mouse.getY(),
|
||||
direction,
|
||||
NEIClientUtils.shiftKey(),
|
||||
NEIClientUtils.controlKey());
|
||||
NEIClientUtils.controlKey() || NEIClientConfig.craftingTreeZoomWithoutModifier());
|
||||
}
|
||||
|
||||
private boolean handleItemWheel(int wheel, Point2D mouse) {
|
||||
@@ -903,6 +906,18 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
this.mc.displayGuiScreen(this.prevGui);
|
||||
NEICPH.sendRequestContainer();
|
||||
return;
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
if (this.statsPanelVisible && KeyManager.isKeyDown("recipe.recipe")) {
|
||||
final Point2D mouse = getMousePosition();
|
||||
final Widget widget = this.statsPanel.getWidgetUnderMouse((int) mouse.getX(), (int) mouse.getY());
|
||||
@@ -910,22 +925,15 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
if (widget != null && widget instanceof StatsPanel.ItemStatsSlot itemStatsSlot
|
||||
&& itemStatsSlot.recipeId != null) {
|
||||
GuiCraftingRecipe.openRecipeGui("recipeId", itemStatsSlot.recipeId.getResult(), itemStatsSlot.recipeId);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String getHandlerTitle(String handlerName) {
|
||||
return handlerTitleCache.computeIfAbsent(
|
||||
handlerName,
|
||||
hname -> Stream
|
||||
.concat(
|
||||
GuiCraftingRecipe.craftinghandlers.stream(),
|
||||
GuiCraftingRecipe.serialCraftingHandlers.stream())
|
||||
.filter(handler -> hname.equals(GuiRecipeTab.getHandlerInfo(handler).getHandlerName()))
|
||||
.findFirst().map(handler -> handler.getRecipeName().trim()).orElse(hname));
|
||||
private String getHandlerTitle(String handlerName) {
|
||||
return this.handlerTitleCache.computeIfAbsent(handlerName, GuiRecipeTab::getHandlerTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -939,12 +947,15 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
if (toolbarTooltip != null) {
|
||||
currenttip.add(toolbarTooltip);
|
||||
} else if (this.hoveredBadgeHandler != null) {
|
||||
final RecipeId recipeId = this.hoveredBadgeHandler.prefItem != null
|
||||
? this.hoveredBadgeHandler.prefItem.recipeId
|
||||
: null;
|
||||
final long multiplier = this.hoveredBadgeHandler.multiplier;
|
||||
final ItemTreeSlot node = this.hoveredBadgeHandler;
|
||||
final RecipeId recipeId = node.prefItem != null ? node.prefItem.recipeId : null;
|
||||
|
||||
if (recipeId != null && NEIClientUtils.shiftKey()) {
|
||||
addRecipeItemsTooltipLine(recipeId, node.multiplier, currenttip);
|
||||
} else {
|
||||
addRecipeTooltipLine(recipeId, node.multiplier, currenttip);
|
||||
}
|
||||
|
||||
addRecipeTooltipLine(recipeId, multiplier, currenttip);
|
||||
} else {
|
||||
|
||||
if (this.statsPanelVisible) {
|
||||
@@ -960,6 +971,14 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
EnumChatFormatting.GRAY + NEIClientUtils.translate(
|
||||
"bookmark.tree.stats.handler_iterations",
|
||||
handlerStatsSlot.stats.iterations));
|
||||
} else if (widget instanceof StatsPanel.ItemStatsSlot itemStatsSlot && itemStatsSlot.recipeId != null) {
|
||||
if (NEIClientUtils.shiftKey()) {
|
||||
addRecipeItemsTooltipLine(itemStatsSlot.recipeId, itemStatsSlot.multiplier, currenttip);
|
||||
} else {
|
||||
currenttip.add(itemStatsSlot.stack.getDisplayName() + GuiDraw.TOOLTIP_LINESPACE);
|
||||
|
||||
addRecipeTooltipLine(itemStatsSlot.recipeId, itemStatsSlot.multiplier, currenttip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -968,6 +987,19 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
private void addRecipeItemsTooltipLine(RecipeId recipeId, long multiplier, List<String> currenttip) {
|
||||
|
||||
if (this.recipeItemsTooltipLineHandler == null
|
||||
|| this.recipeItemsTooltipLineHandler.getMultiplier() != multiplier
|
||||
|| !this.recipeItemsTooltipLineHandler.getRecipeId().equals(recipeId)) {
|
||||
this.recipeItemsTooltipLineHandler = new RecipeItemsTooltipLineHandler(recipeId, multiplier)
|
||||
.setUseInventory(true);
|
||||
}
|
||||
|
||||
currenttip.add(this.recipeItemsTooltipLineHandler.getTitle() + GuiDraw.TOOLTIP_LINESPACE);
|
||||
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.recipeItemsTooltipLineHandler));
|
||||
}
|
||||
|
||||
private void addRecipeTooltipLine(RecipeId recipeId, long multiplier, List<String> currenttip) {
|
||||
|
||||
if (recipeId == null) {
|
||||
@@ -1078,14 +1110,6 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
|
||||
|
||||
} else {
|
||||
this.acceptsFollowingTooltipLineHandler = null;
|
||||
|
||||
if (this.statsPanelVisible) {
|
||||
final Widget widget = this.statsPanel.getWidgetUnderMouse(mousex, mousey);
|
||||
if (widget instanceof StatsPanel.ItemStatsSlot itemStatsSlot) {
|
||||
addRecipeTooltipLine(itemStatsSlot.recipeId, itemStatsSlot.multiplier, currenttip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
|
||||
@@ -3,6 +3,7 @@ package codechicken.nei.bookmark.tree;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -88,6 +89,10 @@ class StatsPanel extends ScrollContainer {
|
||||
this(stack, stackSize, icon, null, 1);
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return StackInfo.withAmount(this.stack, stackSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mx, int my) {
|
||||
|
||||
@@ -118,7 +123,7 @@ class StatsPanel extends ScrollContainer {
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glTranslatef(badgeX, y - 6 * scale, 3.0f);
|
||||
GL11.glTranslatef(badgeX, y - 6 * scale, 10.0f);
|
||||
GL11.glScalef(scale, scale, 1.0f);
|
||||
|
||||
if (this.info.hasImageOrItem()) {
|
||||
@@ -237,7 +242,7 @@ class StatsPanel extends ScrollContainer {
|
||||
26,
|
||||
84,
|
||||
46,
|
||||
16).build();
|
||||
16).setSlices(0, 0, 2, 0).build();
|
||||
|
||||
private static final DrawableResource SLOT_DEFAULT = new DrawableBuilder(
|
||||
"nei:textures/gui/craftingtree.png",
|
||||
@@ -285,8 +290,8 @@ class StatsPanel extends ScrollContainer {
|
||||
|
||||
public StatsPanel() {
|
||||
final ScrollBar scrollbar = new ScrollBar().setTrackWidth(4)
|
||||
.setThumbTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 100, 24, 4).build(), 0, 0)
|
||||
.setTrackTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 104, 24, 4).build(), 0, 0)
|
||||
.setThumbTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 100, 24, 4).build())
|
||||
.setTrackTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 104, 24, 4).build())
|
||||
.setTrackPadding(1, -5, 1, 0).setOverflowType(ScrollBar.OverflowType.AUTO);
|
||||
|
||||
setHorizontalScroll(scrollbar);
|
||||
@@ -519,7 +524,7 @@ class StatsPanel extends ScrollContainer {
|
||||
|
||||
public ItemStack getStackMouseOver(int mouseX, int mouseY) {
|
||||
final Widget widget = getWidgetUnderMouse(mouseX, mouseY);
|
||||
return widget instanceof ItemStatsSlot slot ? slot.stack : null;
|
||||
return widget instanceof ItemStatsSlot slot && slot.recipeId == null ? slot.getStack() : null;
|
||||
}
|
||||
|
||||
public void setHighlight(SearchResult searchResult) {
|
||||
@@ -584,7 +589,7 @@ class StatsPanel extends ScrollContainer {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
BG_TEXTURE.draw(this.x, this.y, this.w, this.h, 0, 0, 2, 0);
|
||||
BG_TEXTURE.draw(this.x, this.y, this.w, this.h);
|
||||
|
||||
super.draw(mouseX, mouseY);
|
||||
|
||||
@@ -711,8 +716,14 @@ class StatsPanel extends ScrollContainer {
|
||||
private List<Widget> collectHandlers(RecipeChainMath math) {
|
||||
final Map<String, HandlerStats> handlerStats = new HashMap<>();
|
||||
final List<Widget> widgets = new ArrayList<>();
|
||||
final Set<RecipeId> countedRecipes = new HashSet<>();
|
||||
|
||||
for (BookmarkItem item : math.recipeResults) {
|
||||
// a recipe adds one result item per output, count it only once
|
||||
if (!countedRecipes.add(item.recipeId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final HandlerStats stats = handlerStats
|
||||
.computeIfAbsent(item.recipeId.getHandlerName(), k -> new HandlerStats());
|
||||
stats.iterations += item.getMultiplier();
|
||||
|
||||
@@ -13,6 +13,10 @@ public class ConfigSet {
|
||||
public NBTTagCompound nbt;
|
||||
public final ConfigTagParent config;
|
||||
|
||||
public ConfigSet(File nbtFile) {
|
||||
this(nbtFile, null);
|
||||
}
|
||||
|
||||
public ConfigSet(File nbtFile, ConfigTagParent config) {
|
||||
this.nbtFile = nbtFile;
|
||||
this.config = config;
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class DataDumper extends Option {
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return renderTag().getIntValue(0);
|
||||
return getTag().getIntValue(0);
|
||||
}
|
||||
|
||||
public void drawButton(int mousex, int mousey, Rectangle4i b, String text) {
|
||||
|
||||
@@ -29,7 +29,6 @@ public class GuiHighlightTips extends GuiScreenWidget {
|
||||
private GuiCCButton toggleButton;
|
||||
private final Option opt;
|
||||
private final GuiOptionList parentGui;
|
||||
private final boolean world;
|
||||
private Point dragDown;
|
||||
|
||||
public GuiHighlightTips(Option opt) {
|
||||
@@ -37,7 +36,6 @@ public class GuiHighlightTips extends GuiScreenWidget {
|
||||
this.opt = opt;
|
||||
name = opt.name;
|
||||
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
|
||||
this.world = parentGui.worldConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,15 +61,11 @@ public class GuiHighlightTips extends GuiScreenWidget {
|
||||
}
|
||||
|
||||
private boolean show() {
|
||||
return renderTag(name).getBooleanValue();
|
||||
return getTag(name).getBooleanValue();
|
||||
}
|
||||
|
||||
private ConfigTag getTag(String s) {
|
||||
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
|
||||
}
|
||||
|
||||
private ConfigTag renderTag(String s) {
|
||||
return (world && opt.worldSpecific(s) ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
|
||||
return opt.configSet().config.getTag(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +89,7 @@ public class GuiHighlightTips extends GuiScreenWidget {
|
||||
}
|
||||
|
||||
public Point getPos() {
|
||||
return new Point(renderTag(name + ".x").getIntValue(), renderTag(name + ".y").getIntValue());
|
||||
return new Point(getTag(name + ".x").getIntValue(), getTag(name + ".y").getIntValue());
|
||||
}
|
||||
|
||||
public Dimension sampleSize() // copied from HUDManager when running with the sample for this gui
|
||||
@@ -161,7 +155,6 @@ public class GuiHighlightTips extends GuiScreenWidget {
|
||||
}
|
||||
|
||||
private void setPos(Point p) {
|
||||
getTag(name).setBooleanValue(show()); // duplicates global tag for the option gui if in world mode
|
||||
getTag(name + ".x").setIntValue(p.x);
|
||||
getTag(name + ".y").setIntValue(p.y);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public class GuiItemSorter extends GuiOptionPane {
|
||||
public final List<SortItem> slots = new ArrayList<>();
|
||||
public final List<SortEntry> list;
|
||||
private final GuiOptionList parentGui;
|
||||
private final boolean world;
|
||||
|
||||
boolean dragging;
|
||||
public SortItem dragged;
|
||||
@@ -62,8 +61,7 @@ public class GuiItemSorter extends GuiOptionPane {
|
||||
public GuiItemSorter(Option opt) {
|
||||
this.opt = opt;
|
||||
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
|
||||
this.world = parentGui.worldConfig();
|
||||
list = ItemSorter.fromSaveString(renderTag(opt.configName()).getValue());
|
||||
list = ItemSorter.fromSaveString(getTag(opt.configName()).getValue());
|
||||
for (SortEntry e : list) slots.add(new SortItem(e));
|
||||
}
|
||||
|
||||
@@ -122,10 +120,7 @@ public class GuiItemSorter extends GuiOptionPane {
|
||||
list.add(nslot, dragged.e);
|
||||
|
||||
getTag(opt.configName()).setValue(ItemSorter.getSaveString(list));
|
||||
|
||||
if (opt.activeTag() == getTag(opt.configName())) {
|
||||
ItemSorter.list = new ArrayList<>(list);
|
||||
}
|
||||
ItemSorter.list = new ArrayList<>(list);
|
||||
|
||||
ItemList.refreshItems.restart();
|
||||
}
|
||||
@@ -133,11 +128,7 @@ public class GuiItemSorter extends GuiOptionPane {
|
||||
}
|
||||
|
||||
private ConfigTag getTag(String s) {
|
||||
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
|
||||
}
|
||||
|
||||
private ConfigTag renderTag(String s) {
|
||||
return (world && opt.worldSpecific(s) ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
|
||||
return opt.configSet().config.getTag(s);
|
||||
}
|
||||
|
||||
public SortItem itemAt(int mx, int my) {
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
|
||||
public class GuiNEIOptionList extends GuiOptionList implements GuiYesNoCallback {
|
||||
|
||||
public GuiNEIOptionList(GuiScreen parent, OptionList optionList, boolean world) {
|
||||
super(parent, optionList, world);
|
||||
public GuiNEIOptionList(GuiScreen parent, OptionList optionList) {
|
||||
super(parent, optionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.nei.config;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.drawMultilineTip;
|
||||
import static codechicken.lib.gui.GuiDraw.drawStringC;
|
||||
import static codechicken.lib.gui.GuiDraw.fontRenderer;
|
||||
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
import static net.minecraft.util.StatCollector.translateToLocal;
|
||||
@@ -10,7 +9,6 @@ import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,8 +21,6 @@ import org.lwjgl.opengl.GL11;
|
||||
import codechicken.core.gui.GuiCCButton;
|
||||
import codechicken.core.gui.GuiScreenWidget;
|
||||
import codechicken.core.gui.GuiScrollSlot;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.LayoutManager;
|
||||
|
||||
public class GuiOptionList extends GuiScreenWidget {
|
||||
|
||||
@@ -66,25 +62,11 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
protected void drawSlot(int slot, int x, int y, int mx, int my, float frame) {
|
||||
Option o = options.get(slot);
|
||||
GL11.glTranslatef(x, y, 0);
|
||||
if (o.showWorldSelector() && world) drawWorldSelector(o, mx, my);
|
||||
GL11.glTranslatef(24, 2, 0);
|
||||
o.draw(mx - 24, my - 2, frame);
|
||||
GL11.glTranslatef(-x - 24, -y - 2, 0);
|
||||
}
|
||||
|
||||
public Rectangle4i worldButtonSize() {
|
||||
return new Rectangle4i(0, 2, 20, 20);
|
||||
}
|
||||
|
||||
private void drawWorldSelector(Option o, int mousex, int mousey) {
|
||||
Rectangle4i b = worldButtonSize();
|
||||
boolean set = o.hasWorldOverride();
|
||||
boolean mouseover = b.contains(mousex, mousey);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, !set ? 0 : mouseover ? 2 : 1);
|
||||
drawStringC("W", b.x, b.y, b.w, b.h, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(float frame) {
|
||||
Rectangle sbar = scrollbarBounds();
|
||||
@@ -116,16 +98,7 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
|
||||
@Override
|
||||
protected void slotClicked(int slot, int button, int mx, int my, int count) {
|
||||
Option o = options.get(slot);
|
||||
if (world && o.showWorldSelector() && worldButtonSize().contains(mx, my)) {
|
||||
if (button == 1 && o.hasWorldOverride()) {
|
||||
o.useGlobals();
|
||||
Option.playClickSound();
|
||||
} else if (button == 0 && !o.hasWorldOverride()) {
|
||||
o.copyGlobals();
|
||||
Option.playClickSound();
|
||||
}
|
||||
} else if (slotBounds(slot).contains(mx, my)) {
|
||||
if (slotBounds(slot).contains(mx, my)) {
|
||||
options.get(slot).mouseClicked(mx - 24, my - 2, button);
|
||||
}
|
||||
}
|
||||
@@ -167,26 +140,20 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
}
|
||||
|
||||
private List<String> handleTooltip(int slot, int mx, int my, List<String> tooltip) {
|
||||
Option o = options.get(slot);
|
||||
if (world && o.showWorldSelector() && worldButtonSize().contains(mx, my))
|
||||
tooltip.add(translateToLocal("nei.options.wbutton.tip." + (o.hasWorldOverride() ? "1" : "0")));
|
||||
if (slotBounds(slot).contains(mx, my)) return o.handleTooltip(mx - 24, my - 2, tooltip);
|
||||
if (slotBounds(slot).contains(mx, my)) return options.get(slot).handleTooltip(mx - 24, my - 2, tooltip);
|
||||
return tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
protected final GuiScreen parent;
|
||||
protected final OptionList optionList;
|
||||
protected boolean world;
|
||||
|
||||
protected OptionScrollSlot slot;
|
||||
protected GuiCCButton backButton;
|
||||
protected GuiCCButton worldButton;
|
||||
|
||||
public GuiOptionList(GuiScreen parent, OptionList optionList, boolean world) {
|
||||
public GuiOptionList(GuiScreen parent, OptionList optionList) {
|
||||
this.parent = parent;
|
||||
this.optionList = optionList;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,29 +169,18 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
backButton.width = Math.min(200, width - 40);
|
||||
backButton.x = (width - backButton.width) / 2;
|
||||
backButton.y = height - 25;
|
||||
worldButton.width = 60;
|
||||
worldButton.x = width - worldButton.width - 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets() {
|
||||
add(slot = new OptionScrollSlot());
|
||||
add(backButton = new GuiCCButton(0, 0, 0, 20, translateToLocal("nei.options.back")).setActionCommand("back"));
|
||||
add(worldButton = new GuiCCButton(0, 2, 0, 16, worldButtonName()).setActionCommand("world"));
|
||||
}
|
||||
|
||||
private String worldButtonName() {
|
||||
return translateToLocal("nei.options." + (world ? "world" : "global"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(String ident, Object... params) {
|
||||
if (ident.equals("back")) {
|
||||
if (parent instanceof GuiOptionList) ((GuiOptionList) parent).world = world;
|
||||
Minecraft.getMinecraft().displayGuiScreen(parent);
|
||||
} else if (ident.equals("world")) {
|
||||
world = !world;
|
||||
worldButton.text = worldButtonName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,9 +198,6 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
private void drawTooltip() {
|
||||
List<String> tooltip = new LinkedList<>();
|
||||
Point mouse = getMousePosition();
|
||||
if (worldButton.pointInside(mouse.x, mouse.y))
|
||||
tooltip.addAll(Arrays.asList(translateToLocal("nei.options.global.tip." + (world ? "1" : "0")).split(":")));
|
||||
|
||||
tooltip = slot.handleTooltip(mouse.x, mouse.y, tooltip);
|
||||
drawMultilineTip(mouse.x + 12, mouse.y - 12, tooltip);
|
||||
}
|
||||
@@ -265,8 +218,4 @@ public class GuiOptionList extends GuiScreenWidget {
|
||||
super.keyTyped(c, keycode);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean worldConfig() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,6 @@ public class GuiPanelSettings extends GuiScreenWidget {
|
||||
|
||||
private final Option opt;
|
||||
private final String name;
|
||||
private final boolean world;
|
||||
private Rectangle4i margin;
|
||||
private Point dragDown;
|
||||
private String dragDir;
|
||||
@@ -69,10 +68,9 @@ public class GuiPanelSettings extends GuiScreenWidget {
|
||||
private PanelResizeButton rightButton = new PanelResizeButton(PANEL_SIZE, PANEL_SIZE * 2);
|
||||
private PanelResizeButton bottomButton = new PanelResizeButton(PANEL_SIZE * 2, PANEL_SIZE);
|
||||
|
||||
public PanelPlaceholder(Option opt, String name, boolean world) {
|
||||
public PanelPlaceholder(Option opt, String name) {
|
||||
this.opt = opt;
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void resize(Rectangle4i margin) {
|
||||
@@ -163,7 +161,7 @@ public class GuiPanelSettings extends GuiScreenWidget {
|
||||
}
|
||||
|
||||
private ConfigTag getTag(String s) {
|
||||
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
|
||||
return opt.configSet().config.getTag(s);
|
||||
}
|
||||
|
||||
protected void drawItems() {
|
||||
@@ -241,9 +239,8 @@ public class GuiPanelSettings extends GuiScreenWidget {
|
||||
super(176, 198);
|
||||
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
boolean world = parentGui.worldConfig();
|
||||
bookmarksPanel = new PanelPlaceholder(opt, opt.name + ".bookmarks", world);
|
||||
itemsPanel = new PanelPlaceholder(opt, opt.name + ".items", world);
|
||||
bookmarksPanel = new PanelPlaceholder(opt, opt.name + ".bookmarks");
|
||||
itemsPanel = new PanelPlaceholder(opt, opt.name + ".items");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,7 +74,11 @@ public class IMCHandler {
|
||||
tag.getInteger("imageX"),
|
||||
tag.getInteger("imageY"),
|
||||
tag.getInteger("imageWidth"),
|
||||
tag.getInteger("imageHeight"));
|
||||
tag.getInteger("imageHeight"),
|
||||
tag.hasKey("imageTextureWidth") ? tag.getInteger("imageTextureWidth")
|
||||
: HandlerInfo.DEFAULT_IMAGE_TEXTURE_SIZE,
|
||||
tag.hasKey("imageTextureHeight") ? tag.getInteger("imageTextureHeight")
|
||||
: HandlerInfo.DEFAULT_IMAGE_TEXTURE_SIZE);
|
||||
}
|
||||
if (!info.hasImageOrItem()) {
|
||||
final String itemName = tag.getString("itemName");
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ItemPanelDumper extends DataDumper {
|
||||
}
|
||||
|
||||
public int getRes() {
|
||||
int i = renderTag(name + ".res").getIntValue(0);
|
||||
int i = getTag(name + ".res").getIntValue(0);
|
||||
int size = 16 << i;
|
||||
if (size >= getSmallerScreenAxisSize() || i < 0) {
|
||||
getTag(name + ".res").setIntValue(0);
|
||||
@@ -95,7 +95,7 @@ public class ItemPanelDumper extends DataDumper {
|
||||
}
|
||||
if (resButtonSize().contains(mousex, mousey)) {
|
||||
NEIClientUtils.playClickSound();
|
||||
int current = renderTag(name + ".res").getIntValue(0);
|
||||
int current = getTag(name + ".res").getIntValue(0);
|
||||
int next;
|
||||
// 31 - numberOfLeadingZeros(x) = floor(log2(x))
|
||||
int max = 31 - Integer.numberOfLeadingZeros(getSmallerScreenAxisSize()) - 3;
|
||||
|
||||
@@ -59,12 +59,8 @@ public abstract class Option {
|
||||
return elem;
|
||||
}
|
||||
|
||||
public ConfigSet globalConfigSet() {
|
||||
return assertParentOverride(parent.globalConfigSet());
|
||||
}
|
||||
|
||||
public ConfigSet worldConfigSet() {
|
||||
return assertParentOverride(parent.worldConfigSet());
|
||||
public ConfigSet configSet() {
|
||||
return assertParentOverride(parent.configSet());
|
||||
}
|
||||
|
||||
public OptionList configBase() {
|
||||
@@ -72,127 +68,19 @@ public abstract class Option {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the world config contains a tag with this name
|
||||
*/
|
||||
public boolean worldSpecific() {
|
||||
return worldSpecific(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the world config contains a tag with this name
|
||||
*/
|
||||
public boolean worldSpecific(String s) {
|
||||
ConfigTag tag = worldConfigSet().config.getTag(s, false);
|
||||
return tag != null && tag.value != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The currently config set for the gui based on the world/global button
|
||||
*/
|
||||
public ConfigSet configSet() {
|
||||
return worldConfig() ? worldConfigSet() : globalConfigSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag to render, world if world override, otherwise global
|
||||
*/
|
||||
public ConfigTag renderTag() {
|
||||
return renderTag(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag to render, world if world override, otherwise global
|
||||
*/
|
||||
public ConfigTag renderTag(String s) {
|
||||
return (worldConfig() && worldSpecific(s) ? worldConfigSet() : globalConfigSet()).config.getTag(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag with this name from the current configSet
|
||||
* @return The tag with this name from the config set
|
||||
*/
|
||||
public ConfigTag getTag() {
|
||||
return getTag(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag with this name from the current configSet
|
||||
* @return The tag with this name from the config set
|
||||
*/
|
||||
public ConfigTag getTag(String s) {
|
||||
return configSet().config.getTag(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag currently being used ingame, world if a world override exists, otherwise global
|
||||
*/
|
||||
public ConfigTag activeTag() {
|
||||
return activeTag(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The tag currently being used ingame, world if a world override exists, otherwise global
|
||||
*/
|
||||
public ConfigTag activeTag(String s) {
|
||||
return (worldSpecific() ? worldConfigSet() : globalConfigSet()).config.getTag(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the gui is in world config mode
|
||||
*/
|
||||
public boolean worldConfig() {
|
||||
return getSlot().getGui().worldConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if in world mode, but this tag has no world override. Changes should not be made in this mode
|
||||
*/
|
||||
public boolean defaulting() {
|
||||
return defaulting(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if in world mode, but this tag has no world override. Changes should not be made in this mode
|
||||
*/
|
||||
public boolean defaulting(String s) {
|
||||
return worldConfig() && !worldSpecific(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when world specific is disabled for this option. Should delete all world specific overrides
|
||||
*/
|
||||
public void useGlobals() {
|
||||
useGlobal(configName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a specific named tag from the worldConfig
|
||||
*/
|
||||
public void useGlobal(String s) {
|
||||
if (worldConfig()) worldConfigSet().config.removeTag(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when world specific is activated for this option. Should copy the global value into a world specific
|
||||
* override
|
||||
*/
|
||||
public void copyGlobals() {
|
||||
copyGlobal(configName(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the global value into a world specific override
|
||||
*/
|
||||
public void copyGlobal(String s) {
|
||||
copyGlobal(s, false);
|
||||
}
|
||||
|
||||
public void copyGlobal(String s, boolean recursive) {
|
||||
if (!worldConfig()) return;
|
||||
|
||||
ConfigTag tag = globalConfigSet().config.getTag(s);
|
||||
worldConfigSet().config.getTag(s).setValue(tag.getValue());
|
||||
if (recursive) for (String s2 : tag.childTagMap().keySet()) copyGlobal(s + "." + s2);
|
||||
}
|
||||
|
||||
public void onAdded(OptionScrollSlot slot) {
|
||||
this.slotRef = new WeakReference<>(slot);
|
||||
}
|
||||
@@ -217,12 +105,4 @@ public abstract class Option {
|
||||
public List<String> handleTooltip(int mx, int my, List<String> currenttip) {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
public boolean showWorldSelector() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasWorldOverride() {
|
||||
return worldSpecific();
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,11 @@ public class OptionCycled extends OptionButton {
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return renderTag().getIntValue();
|
||||
return getTag().getIntValue();
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
getTag().setIntValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +56,7 @@ public class OptionCycled extends OptionButton {
|
||||
|
||||
if (next == value()) return false;
|
||||
|
||||
getTag().setIntValue(next);
|
||||
setValue(next);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package codechicken.nei.config;
|
||||
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import codechicken.nei.ClientHandler;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
public class OptionExportConfig extends OptionButton {
|
||||
|
||||
private final String fileName;
|
||||
|
||||
public OptionExportConfig(String fileName) {
|
||||
super("tools.export_configs." + fileName.substring(0, fileName.lastIndexOf('.')));
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN("tools.export_configs.button");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
final boolean exported = ClientHandler.exportDefaultConfig(fileName);
|
||||
|
||||
NEIClientUtils.printChatMessage(
|
||||
new ChatComponentTranslation(
|
||||
exported ? "nei.options.tools.export_configs.done" : "nei.options.tools.export_configs.skipped",
|
||||
fileName));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class OptionIntegerField extends OptionTextField {
|
||||
@Override
|
||||
protected int getMaxInputWidth() {
|
||||
|
||||
if (renderTag().getValue().startsWith("0x")) {
|
||||
if (getTag().getValue().startsWith("0x")) {
|
||||
return GuiDraw.getStringWidth("0x" + Long.toHexString(this.max).toUpperCase()) + 32;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@ public class OptionList extends OptionButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSet globalConfigSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSet worldConfigSet() {
|
||||
public ConfigSet configSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -35,8 +30,8 @@ public class OptionList extends OptionButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
|
||||
return new GuiOptionList(parent, list, world);
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list) {
|
||||
return new GuiOptionList(parent, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,41 +113,25 @@ public class OptionList extends OptionButton {
|
||||
*
|
||||
* @param parent The parent screen for the back button
|
||||
* @param list The option list to be displayed in the gui
|
||||
* @param world true if in world config mode, false for global
|
||||
*/
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
|
||||
return this.parent.getGui(parent, list, world);
|
||||
public GuiOptionList getGui(GuiScreen parent, OptionList list) {
|
||||
return this.parent.getGui(parent, list);
|
||||
}
|
||||
|
||||
public void openGui(GuiScreen parent, boolean world) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(getGui(parent, this, world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this option to a temporary slot and gui for internal setting manipulation.
|
||||
*/
|
||||
public GuiOptionList synthesizeEnvironment(boolean world) {
|
||||
GuiOptionList gui = getGui(null, this, world);
|
||||
gui.addWidgets();
|
||||
return gui;
|
||||
public void openGui(GuiScreen parent) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(getGui(parent, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
openGui(getSlot().getGui(), getSlot().getGui().worldConfig());
|
||||
openGui(getSlot().getGui());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showWorldSelector() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded(OptionScrollSlot slot) {
|
||||
super.onAdded(slot);
|
||||
|
||||
globalConfigSet().config.getTag(configName()).useBraces();
|
||||
worldConfigSet().config.getTag(configName()).useBraces();
|
||||
configSet().config.getTag(configName()).useBraces();
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public abstract class OptionStringSet extends Option {
|
||||
}
|
||||
|
||||
public List<String> values() {
|
||||
return Arrays.asList(renderTag().getValue().replace(" ", "").split(","));
|
||||
return Arrays.asList(getTag().getValue().replace(" ", "").split(","));
|
||||
}
|
||||
|
||||
public int buttonX() {
|
||||
|
||||
@@ -16,8 +16,7 @@ public class OptionTextField extends Option {
|
||||
|
||||
@Override
|
||||
public void onTextChange(String oldText) {
|
||||
// don't override global if text hasn't changed
|
||||
if (focused() && isValidValue(text()) && (!defaulting() || !text().equals(getTag().getValue()))) {
|
||||
if (focused() && isValidValue(text())) {
|
||||
getTag().setValue(text());
|
||||
OptionTextField.this.onTextChange(text());
|
||||
}
|
||||
@@ -25,7 +24,7 @@ public class OptionTextField extends Option {
|
||||
|
||||
@Override
|
||||
public void setFocus(boolean focus) {
|
||||
if (!focus && !isValidValue(text())) setText(renderTag().getValue());
|
||||
if (!focus && !isValidValue(text())) setText(getTag().getValue());
|
||||
super.setFocus(focus);
|
||||
}
|
||||
|
||||
@@ -45,7 +44,7 @@ public class OptionTextField extends Option {
|
||||
@Override
|
||||
public void update() {
|
||||
textField.update();
|
||||
if (!textField.focused()) textField.setText(renderTag().getValue());
|
||||
if (!textField.focused()) textField.setText(getTag().getValue());
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class OptionToggleButton extends OptionButton {
|
||||
}
|
||||
|
||||
public boolean state() {
|
||||
return renderTag().getBooleanValue();
|
||||
return getTag().getBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ public class OptionToggleButtonBoubs extends OptionButton {
|
||||
}
|
||||
|
||||
public boolean state() {
|
||||
return renderTag().getBooleanValue();
|
||||
return getTag().getBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package codechicken.nei.config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.RecipeJsonWriter;
|
||||
|
||||
public class RecipeDumper extends DataDumper {
|
||||
|
||||
public RecipeDumper(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] header() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String[]> dump(int mode) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renderName() {
|
||||
return translateN(name);
|
||||
}
|
||||
|
||||
public Rectangle4i separateButtonSize() {
|
||||
return dumpButtonSize();
|
||||
}
|
||||
|
||||
public Rectangle4i combinedButtonSize() {
|
||||
return modeButtonSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawPrefix();
|
||||
drawButton(mousex, mousey, combinedButtonSize(), translateN(name + ".combined"));
|
||||
drawButton(mousex, mousey, separateButtonSize(), translateN(name + ".separate"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mousex, int mousey, int button) {
|
||||
final boolean combined = combinedButtonSize().contains(mousex, mousey);
|
||||
|
||||
if (combined || separateButtonSize().contains(mousex, mousey)) {
|
||||
NEIClientUtils.playClickSound();
|
||||
RecipeJsonWriter.dumpAll(!combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,19 +79,24 @@ public class RightPanel extends GuiWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastKeyTyped(int keyID, char keyChar) {
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
if (!focused() && KeyManager.isHashDown("gui.search")) {
|
||||
setFocus(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getprevioussearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.PREVIOUS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (focused() && KeyManager.isKeyDown("gui.getnextsearch")) {
|
||||
handleNavigateHistory(TextHistory.Direction.NEXT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,13 +15,21 @@ public class DrawableBuilder {
|
||||
private int paddingBottom = 0;
|
||||
private int paddingLeft = 0;
|
||||
private int paddingRight = 0;
|
||||
private int sliceLeft = 0;
|
||||
private int sliceRight = 0;
|
||||
private int sliceTop = 0;
|
||||
private int sliceBottom = 0;
|
||||
|
||||
public DrawableBuilder(String resourceLocation, int u, int v, int width, int height) {
|
||||
this(new ResourceLocation(resourceLocation), u, v, width, height);
|
||||
}
|
||||
|
||||
public DrawableBuilder(ResourceLocation resource, int u, int v, int width, int height) {
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.resourceLocation = new ResourceLocation(resourceLocation);
|
||||
this.resourceLocation = resource;
|
||||
}
|
||||
|
||||
public DrawableBuilder setTextureSize(int width, int height) {
|
||||
@@ -38,6 +46,14 @@ public class DrawableBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DrawableBuilder setSlices(int sliceLeft, int sliceRight, int sliceTop, int sliceBottom) {
|
||||
this.sliceLeft = sliceLeft;
|
||||
this.sliceRight = sliceRight;
|
||||
this.sliceTop = sliceTop;
|
||||
this.sliceBottom = sliceBottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DrawableBuilder trim(int trimTop, int trimBottom, int trimLeft, int trimRight) {
|
||||
this.u += trimLeft;
|
||||
this.v += trimTop;
|
||||
@@ -58,6 +74,10 @@ public class DrawableBuilder {
|
||||
paddingLeft,
|
||||
paddingRight,
|
||||
textureWidth,
|
||||
textureHeight);
|
||||
textureHeight,
|
||||
sliceLeft,
|
||||
sliceRight,
|
||||
sliceTop,
|
||||
sliceBottom);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package codechicken.nei.drawable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -19,9 +19,42 @@ public class DrawableResource extends Image {
|
||||
private final int paddingLeft;
|
||||
private final int paddingRight;
|
||||
|
||||
private final int sliceLeft;
|
||||
private final int sliceRight;
|
||||
private final int sliceTop;
|
||||
private final int sliceBottom;
|
||||
|
||||
public DrawableResource(ResourceLocation resourceLocation, int u, int v, int width, int height, int paddingTop,
|
||||
int paddingBottom, int paddingLeft, int paddingRight, int textureWidth, int textureHeight) {
|
||||
this(
|
||||
resourceLocation,
|
||||
u,
|
||||
v,
|
||||
width,
|
||||
height,
|
||||
paddingTop,
|
||||
paddingBottom,
|
||||
paddingLeft,
|
||||
paddingRight,
|
||||
textureWidth,
|
||||
textureHeight,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
}
|
||||
|
||||
// negative padding lets the texture overflow the box it is drawn into
|
||||
public DrawableResource(ResourceLocation resourceLocation, int u, int v, int width, int height, int paddingTop,
|
||||
int paddingBottom, int paddingLeft, int paddingRight, int textureWidth, int textureHeight, int sliceLeft,
|
||||
int sliceRight, int sliceTop, int sliceBottom) {
|
||||
super(u, v, width, height);
|
||||
|
||||
this.sliceLeft = sliceLeft;
|
||||
this.sliceRight = sliceRight;
|
||||
this.sliceTop = sliceTop;
|
||||
this.sliceBottom = sliceBottom;
|
||||
|
||||
this.resourceLocation = resourceLocation;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
@@ -40,6 +73,14 @@ public class DrawableResource extends Image {
|
||||
return height + paddingTop + paddingBottom;
|
||||
}
|
||||
|
||||
public int getTextureWidth() {
|
||||
return this.textureWidth;
|
||||
}
|
||||
|
||||
public int getTextureHeight() {
|
||||
return this.textureHeight;
|
||||
}
|
||||
|
||||
public void bindTexture() {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation);
|
||||
}
|
||||
@@ -55,18 +96,28 @@ public class DrawableResource extends Image {
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
bindTexture();
|
||||
drawModalRectWithCustomSizedTexture(xOffset + maskLeft, yOffset + maskTop, maskLeft, maskTop, width, height);
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
addQuad(tessellator, xOffset + maskLeft, yOffset + maskTop, maskLeft, maskTop, width, height);
|
||||
tessellator.draw();
|
||||
if (!is2DTexture) GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public void draw(int xOffset, int yOffset, int width, int height, int sliceLeft, int sliceRight, int sliceTop,
|
||||
int sliceBottom) {
|
||||
final int textureWidth = getWidth();
|
||||
final int textureHeight = getHeight();
|
||||
final int middleWidth = textureWidth - sliceLeft - sliceRight;
|
||||
final int middleHeight = textureHeight - sliceTop - sliceBottom;
|
||||
final int tileWidth = width - sliceLeft - sliceRight;
|
||||
final int tileHeight = height - sliceTop - sliceBottom;
|
||||
public void draw(int xOffset, int yOffset, int width, int height) {
|
||||
|
||||
if (width == getWidth() && height == getHeight()) {
|
||||
draw(xOffset, yOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
final int sliceLeft = this.sliceLeft;
|
||||
final int sliceRight = this.sliceRight;
|
||||
final int sliceTop = this.sliceTop;
|
||||
final int sliceBottom = this.sliceBottom;
|
||||
final int middleWidth = this.width - sliceLeft - sliceRight;
|
||||
final int middleHeight = this.height - sliceTop - sliceBottom;
|
||||
final int tileWidth = width - this.paddingLeft - this.paddingRight - sliceLeft - sliceRight;
|
||||
final int tileHeight = height - this.paddingTop - this.paddingBottom - sliceTop - sliceBottom;
|
||||
|
||||
if (middleWidth > 0 && middleHeight > 0 && tileWidth > 0 && tileHeight > 0) {
|
||||
final boolean is2DTexture = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
|
||||
@@ -78,14 +129,30 @@ public class DrawableResource extends Image {
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
bindTexture();
|
||||
|
||||
// middle parts
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
for (int tileW = 0; tileW <= tileWidthCount; tileW++) {
|
||||
final int tileWidthSize = (tileW == tileWidthCount) ? remainderWidth : middleWidth;
|
||||
final int x = xOffset + sliceLeft + tileW * middleWidth;
|
||||
|
||||
// border top
|
||||
addQuad(tessellator, x, yOffset, sliceLeft, 0, tileWidthSize, sliceTop);
|
||||
// border bottom
|
||||
addQuad(
|
||||
tessellator,
|
||||
x,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
sliceLeft,
|
||||
sliceTop + middleHeight,
|
||||
tileWidthSize,
|
||||
sliceBottom);
|
||||
|
||||
// middle parts
|
||||
for (int tileH = 0; tileH <= tileHeightCount; tileH++) {
|
||||
final int tileHeightSize = (tileH == tileHeightCount) ? remainderHeight : middleHeight;
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
addQuad(
|
||||
tessellator,
|
||||
x,
|
||||
yOffset + sliceTop + tileH * middleHeight,
|
||||
sliceLeft,
|
||||
@@ -95,114 +162,75 @@ public class DrawableResource extends Image {
|
||||
}
|
||||
}
|
||||
|
||||
// border top
|
||||
if (sliceTop > 0) {
|
||||
for (int tileW = 0; tileW <= tileWidthCount; tileW++) {
|
||||
final int tileWidthSize = (tileW == tileWidthCount) ? remainderWidth : middleWidth;
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset + sliceLeft + tileW * middleWidth,
|
||||
yOffset,
|
||||
sliceLeft,
|
||||
0,
|
||||
tileWidthSize,
|
||||
sliceTop);
|
||||
}
|
||||
}
|
||||
for (int tileH = 0; tileH <= tileHeightCount; tileH++) {
|
||||
final int tileHeightSize = (tileH == tileHeightCount) ? remainderHeight : middleHeight;
|
||||
final int y = yOffset + sliceTop + tileH * middleHeight;
|
||||
|
||||
// border bottom
|
||||
if (sliceBottom > 0) {
|
||||
for (int tileW = 0; tileW <= tileWidthCount; tileW++) {
|
||||
final int tileWidthSize = (tileW == tileWidthCount) ? remainderWidth : middleWidth;
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset + sliceLeft + tileW * middleWidth,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
sliceLeft,
|
||||
sliceTop + middleHeight,
|
||||
tileWidthSize,
|
||||
sliceBottom);
|
||||
}
|
||||
}
|
||||
|
||||
// border left
|
||||
if (sliceLeft > 0) {
|
||||
for (int tileH = 0; tileH <= tileHeightCount; tileH++) {
|
||||
final int tileHeightSize = (tileH == tileHeightCount) ? remainderHeight : middleHeight;
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset,
|
||||
yOffset + sliceTop + tileH * middleHeight,
|
||||
0,
|
||||
sliceTop,
|
||||
sliceLeft,
|
||||
tileHeightSize);
|
||||
}
|
||||
}
|
||||
|
||||
// border right
|
||||
if (sliceRight > 0) {
|
||||
for (int tileH = 0; tileH <= tileHeightCount; tileH++) {
|
||||
final int tileHeightSize = (tileH == tileHeightCount) ? remainderHeight : middleHeight;
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
yOffset + sliceTop + tileH * middleHeight,
|
||||
sliceLeft + middleWidth,
|
||||
sliceTop,
|
||||
sliceRight,
|
||||
tileHeightSize);
|
||||
}
|
||||
// border left
|
||||
addQuad(tessellator, xOffset, y, 0, sliceTop, sliceLeft, tileHeightSize);
|
||||
// border right
|
||||
addQuad(
|
||||
tessellator,
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
y,
|
||||
sliceLeft + middleWidth,
|
||||
sliceTop,
|
||||
sliceRight,
|
||||
tileHeightSize);
|
||||
}
|
||||
|
||||
// angle left-top
|
||||
if (sliceLeft > 0 && sliceTop > 0) {
|
||||
drawModalRectWithCustomSizedTexture(xOffset, yOffset, 0, 0, sliceLeft, sliceTop);
|
||||
}
|
||||
|
||||
addQuad(tessellator, xOffset, yOffset, 0, 0, sliceLeft, sliceTop);
|
||||
// angle right-top
|
||||
if (sliceRight > 0 && sliceTop > 0) {
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
yOffset,
|
||||
sliceLeft + middleWidth,
|
||||
0,
|
||||
sliceRight,
|
||||
sliceTop);
|
||||
}
|
||||
|
||||
addQuad(
|
||||
tessellator,
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
yOffset,
|
||||
sliceLeft + middleWidth,
|
||||
0,
|
||||
sliceRight,
|
||||
sliceTop);
|
||||
// angle left-bottom
|
||||
if (sliceLeft > 0 && sliceBottom > 0) {
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
0,
|
||||
sliceTop + middleHeight,
|
||||
sliceLeft,
|
||||
sliceBottom);
|
||||
}
|
||||
|
||||
addQuad(
|
||||
tessellator,
|
||||
xOffset,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
0,
|
||||
sliceTop + middleHeight,
|
||||
sliceLeft,
|
||||
sliceBottom);
|
||||
// angle right-bottom
|
||||
if (sliceRight > 0 && sliceBottom > 0) {
|
||||
drawModalRectWithCustomSizedTexture(
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
sliceLeft + middleWidth,
|
||||
sliceTop + middleHeight,
|
||||
sliceRight,
|
||||
sliceBottom);
|
||||
}
|
||||
addQuad(
|
||||
tessellator,
|
||||
xOffset + sliceLeft + tileWidth,
|
||||
yOffset + sliceTop + tileHeight,
|
||||
sliceLeft + middleWidth,
|
||||
sliceTop + middleHeight,
|
||||
sliceRight,
|
||||
sliceBottom);
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
if (!is2DTexture) GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawModalRectWithCustomSizedTexture(int xOffset, int yOffset, int u, int v, int width, int height) {
|
||||
Gui.func_146110_a(
|
||||
xOffset + this.paddingLeft,
|
||||
yOffset + this.paddingTop,
|
||||
this.x + u,
|
||||
this.y + v,
|
||||
width,
|
||||
height,
|
||||
this.textureWidth,
|
||||
this.textureHeight);
|
||||
private void addQuad(Tessellator tessellator, int xOffset, int yOffset, int u, int v, int width, int height) {
|
||||
if (width <= 0 || height <= 0) return;
|
||||
|
||||
final float scaleU = 1.0F / this.textureWidth;
|
||||
final float scaleV = 1.0F / this.textureHeight;
|
||||
final int x = xOffset + this.paddingLeft;
|
||||
final int y = yOffset + this.paddingTop;
|
||||
final float u0 = (this.x + u) * scaleU;
|
||||
final float u1 = (this.x + u + width) * scaleU;
|
||||
final float v0 = (this.y + v) * scaleV;
|
||||
final float v1 = (this.y + v + height) * scaleV;
|
||||
|
||||
tessellator.addVertexWithUV(x, y + height, 0.0D, u0, v1);
|
||||
tessellator.addVertexWithUV(x + width, y + height, 0.0D, u1, v1);
|
||||
tessellator.addVertexWithUV(x + width, y, 0.0D, u1, v0);
|
||||
tessellator.addVertexWithUV(x, y, 0.0D, u0, v0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
@@ -30,7 +30,10 @@ public class AllMultiRecipeFilter implements IRecipeFilter {
|
||||
try {
|
||||
if (filter != null && !filter.matches(handler, recipeIndex)) return false;
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Exception filtering " + handler + " with " + filter, e);
|
||||
NEIClientUtils.errorOnce(
|
||||
"filter:" + handler.getHandlerId() + ":" + filter.getClass().getName(),
|
||||
"Exception filtering " + handler.getHandlerId() + " with " + filter,
|
||||
e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package codechicken.nei.filter;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
public class AllOthersRecipeFilter implements IRecipeFilter {
|
||||
|
||||
private final ItemFilter filter;
|
||||
|
||||
public AllOthersRecipeFilter(ItemFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IRecipeHandler handler, int recipeIndex) {
|
||||
|
||||
for (PositionedStack pStack : handler.getOtherStacks(recipeIndex)) {
|
||||
if (!match(pStack)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean match(PositionedStack pStack) {
|
||||
if (pStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ItemStack stack : pStack.items) {
|
||||
if (filter.matches(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
@@ -30,7 +30,10 @@ public class AnyMultiRecipeFilter implements IRecipeFilter {
|
||||
try {
|
||||
if (filter != null && filter.matches(handler, recipeIndex)) return true;
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Exception filtering " + handler + " with " + filter, e);
|
||||
NEIClientUtils.errorOnce(
|
||||
"filter:" + handler.getHandlerId() + ":" + filter.getClass().getName(),
|
||||
"Exception filtering " + handler.getHandlerId() + " with " + filter,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package codechicken.nei.filter;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
public class AnyOthersRecipeFilter implements IRecipeFilter {
|
||||
|
||||
private final ItemFilter filter;
|
||||
|
||||
public AnyOthersRecipeFilter(ItemFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IRecipeHandler handler, int recipeIndex) {
|
||||
|
||||
for (PositionedStack pStack : handler.getOtherStacks(recipeIndex)) {
|
||||
if (match(pStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean match(PositionedStack pStack) {
|
||||
if (pStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ItemStack stack : pStack.items) {
|
||||
if (filter.matches(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,8 @@ public class RecipeFilter implements IRecipeFilter {
|
||||
|
||||
ANY,
|
||||
INPUT,
|
||||
OUTPUT;
|
||||
OUTPUT,
|
||||
AUXILIARY;
|
||||
|
||||
public static FilterContext fromChar(char c) {
|
||||
switch (c) {
|
||||
@@ -24,6 +25,8 @@ public class RecipeFilter implements IRecipeFilter {
|
||||
return INPUT;
|
||||
case '>':
|
||||
return OUTPUT;
|
||||
case '^':
|
||||
return AUXILIARY;
|
||||
default:
|
||||
return ANY;
|
||||
}
|
||||
@@ -48,17 +51,14 @@ public class RecipeFilter implements IRecipeFilter {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
if (this.context == FilterContext.ANY || this.context == FilterContext.OUTPUT) {
|
||||
final PositionedStack result = handler.getResultStack(recipeIndex);
|
||||
|
||||
if (result != null && matchPositionedStack(result) == this.anyMatch) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
if (matchPositionedStack(handler.getOtherStacks(recipeIndex), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
if ((this.context == FilterContext.ANY || this.context == FilterContext.OUTPUT)
|
||||
&& matchPositionedStack(handler.getResultStacks(recipeIndex), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
if ((this.context == FilterContext.ANY || this.context == FilterContext.AUXILIARY)
|
||||
&& matchPositionedStack(handler.getAuxiliaryStacks(recipeIndex), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
return !this.anyMatch;
|
||||
|
||||
@@ -449,6 +449,7 @@ public class GuiContainerManager {
|
||||
}
|
||||
|
||||
private int clickHandled = 0;
|
||||
private int hotkeyHandled = 0;
|
||||
public final List<IContainerTooltipHandler> instanceTooltipHandlers;
|
||||
|
||||
public GuiContainerManager(GuiContainer screen) {
|
||||
@@ -483,6 +484,7 @@ public class GuiContainerManager {
|
||||
|
||||
public void load() {
|
||||
clickHandled = 0;
|
||||
hotkeyHandled = 0;
|
||||
for (IContainerObjectHandler objectHandler : objectHandlers) objectHandler.load(window);
|
||||
}
|
||||
|
||||
@@ -499,9 +501,60 @@ public class GuiContainerManager {
|
||||
public boolean lastKeyTyped(int keyID, char keyChar) {
|
||||
if (keyID == 1) return false;
|
||||
|
||||
// hotkeys go before lastKeyTyped, otherwise a third-party handler that consumes every key blocks them
|
||||
if (handleHotkeys()) return true;
|
||||
|
||||
for (IContainerInputHandler inputhander : inputHandlers)
|
||||
if (inputhander.lastKeyTyped(window, keyChar, keyID)) return true;
|
||||
|
||||
return handleScreenHotkeys();
|
||||
}
|
||||
|
||||
public boolean onHotkeyPressed() {
|
||||
return handleHotkeys() || handleScreenHotkeys();
|
||||
}
|
||||
|
||||
private boolean handleHotkeys() {
|
||||
|
||||
if (window instanceof IGuiHotkeyListener && ((IGuiHotkeyListener) window).onHotkeyPressed()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IContainerInputHandler inputhander : inputHandlers) {
|
||||
if (inputhander.onHotkeyPressed(window)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleScreenHotkeys() {
|
||||
return window instanceof IGuiHotkeyListener && ((IGuiHotkeyListener) window).onScreenHotkeyPressed();
|
||||
}
|
||||
|
||||
public boolean handleMouseHotkey() {
|
||||
final int button = Mouse.getEventButton();
|
||||
|
||||
if (button < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Mouse.getEventButtonState()) {
|
||||
// the press has been consumed, so the release must not reach the screen either
|
||||
if ((hotkeyHandled & 1 << button) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hotkeyHandled &= ~(1 << button);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (KeyManager.handleMouseHotkey(button, this::onHotkeyPressed)) {
|
||||
hotkeyHandled |= 1 << button;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,18 @@ public interface IContainerInputHandler {
|
||||
*/
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID);
|
||||
|
||||
/**
|
||||
* Called when a key or a mouse button is pressed and the event has not been handled by the first pass. Use this for
|
||||
* key bindings that work globally and check them with {@link codechicken.nei.KeyManager#isKeyDown}, so they work
|
||||
* the same for keyboard keys and mouse buttons.
|
||||
*
|
||||
* @param gui An instance of the currentscreen
|
||||
* @return true to terminate further processing of this event.
|
||||
*/
|
||||
default boolean onHotkeyPressed(GuiContainer gui) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked in the gui
|
||||
*
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package codechicken.nei.guihook;
|
||||
|
||||
/**
|
||||
* Interface for GuiContainers to receive NEI compatible hotkey events from both keyboard keys and mouse buttons
|
||||
*/
|
||||
public interface IGuiHotkeyListener {
|
||||
|
||||
/**
|
||||
* Called before the input handlers when a key or a mouse button is pressed, check key bindings with
|
||||
* {@link codechicken.nei.KeyManager#isKeyDown}
|
||||
*
|
||||
* @return true to terminate further processing of this event.
|
||||
*/
|
||||
default boolean onHotkeyPressed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the input handlers for screen-wide hotkeys that do not depend on the hovered object, so they never
|
||||
* take priority over more specific actions
|
||||
*
|
||||
* @return true to terminate further processing of this event.
|
||||
*/
|
||||
default boolean onScreenHotkeyPressed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 172 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user