Compare commits

...
36 changed files with 1087 additions and 197 deletions

No files matched your search

+3 -1
View File
@@ -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
+10 -5
View File
@@ -5,8 +5,8 @@ configurations.create('gtnhlibEmbed') {
}
dependencies {
api('com.github.GTNewHorizons:CodeChickenCore:1.4.17:dev')
devOnlyNonPublishable('com.github.GTNewHorizons:GTNHLib:0.11.37:dev')
api('com.github.GTNewHorizons:CodeChickenCore:1.4.21:dev')
devOnlyNonPublishable('com.github.GTNewHorizons:GTNHLib:0.11.49: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.37") { transitive = false }
gtnhlibEmbed("com.github.GTNewHorizons:GTNHLib:0.11.37") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTNHLib:0.11.49") { transitive = false }
gtnhlibEmbed("com.github.GTNewHorizons:GTNHLib:0.11.49") { 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'
}
+5
View File
@@ -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],
+10 -10
View File
@@ -1,12 +1,12 @@
#This file is generated by updateDaemonJvm
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1df82b76031285ef2e6a4f59ffe9299d/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/c7d5be6a02945ac2e045048ee54a7d32/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/643f404f769811f5f265fd66f7af5d89/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/38256085a73e137cb4937ea9c4807fec/redirect
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/9064f22734b42ac03e85df04b632e167/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/4d0277c49991306ac78048580fe34bcf/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a9fa3b809e484a1e1ac4308a5dda661a/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/aa99913fa6d767d899ffc96082da01ca/redirect
toolchainVersion=25
Binary file not shown.
+3 -1
View File
@@ -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
Vendored
+3 -3
View File
@@ -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
View File
@@ -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
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.29'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.31'
}
@@ -10,6 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
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;
@@ -227,17 +228,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;
}
}
}
@@ -6,11 +6,14 @@ 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 net.minecraftforge.fluids.FluidContainerRegistry;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.ItemsGrid.ItemsGridSlot;
@@ -21,7 +24,6 @@ import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.Recipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.StackInfo;
@@ -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,16 @@ 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() {
pendingResult.set(generateCraftables(ItemCraftablesPanel.this.pendingSnapshot));
}
};
public ItemCraftablesPanel() {
this.grid = new ItemsGrid<>() {
@@ -114,12 +162,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 +238,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 +272,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 {
@@ -244,17 +303,28 @@ public class ItemCraftablesPanel
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 +340,126 @@ 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 resultStack = handler.getResultStack(recipeIndex);
if (resultStack != null) {
return resultStack.item;
}
final List<PositionedStack> otherStacks = handler.getOtherStacks(recipeIndex);
for (PositionedStack otherStack : otherStacks) {
if (!FluidContainerRegistry.isContainer(otherStack.items[0])
|| StackInfo.getFluid(otherStack.items[0]) != null) {
return otherStack.item;
}
}
return otherStacks.isEmpty() ? null : otherStacks.get(0).item;
}
private static ItemStack getCheapResult(IRecipeHandler handler, int recipeIndex) {
final PositionedStack resultStack = handler.getResultStack(recipeIndex);
final List<PositionedStack> results = resultStack != null ? Collections.singletonList(resultStack)
: handler.getOtherStacks(recipeIndex);
if (results.isEmpty()) {
return null;
}
ItemStack stack = null;
if (results.size() > 1) {
for (PositionedStack result : results) {
if (!FluidContainerRegistry.isContainer(result.item) || StackInfo.getFluid(result.item) != null) {
stack = result.item;
break;
}
}
}
if (stack == null) {
stack = results.get(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 +468,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);
@@ -0,0 +1,125 @@
package codechicken.nei;
import static codechicken.lib.gui.GuiDraw.fontRenderer;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.guihook.GuiContainerManager;
public class ItemsListTooltipLineHandler extends ItemsTooltipLineHandler {
protected static final int NAME_MARGIN = 2;
protected final List<String> names = new ArrayList<>();
protected int tailCount = 0;
public ItemsListTooltipLineHandler(String label, List<ItemStack> items, int maxRows) {
super(label, items, true, maxRows);
this.rows = Math.min(maxRows, this.length);
this.count = this.length > this.rows ? this.rows - 1 : this.length;
int width = fontRenderer.getStringWidth(this.label) + 15;
for (int index = 0; index < this.count; index++) {
final String name = this.items.get(index).getDisplayName();
this.names.add(name);
width = Math.max(width, SLOT_SIZE + NAME_MARGIN + fontRenderer.getStringWidth(name));
}
if (this.count < this.length) {
final int tail = this.length - this.count;
width = Math.max(width, Math.min(tail, MAX_COLUMNS) * SLOT_SIZE);
final int fit = width / SLOT_SIZE;
if (tail <= fit) {
this.tailCount = tail;
} else {
final String text = "+" + (tail - fit);
this.tailCount = Math
.max(0, fit - (int) Math.ceil((float) (fontRenderer.getStringWidth(text) - 2) / SLOT_SIZE));
}
}
this.size.width = this.length > 0 ? width : 0;
this.size.height = this.length > 0 ? this.rows * SLOT_SIZE + fontRenderer.FONT_HEIGHT + 2 + MARGIN_TOP : 0;
}
@Override
public void setLabel(String label) {
this.label = label;
this.size.width = Math.max(this.size.width, fontRenderer.getStringWidth(this.label) + 15);
}
@Override
public void draw(int x, int y) {
if (this.length == 0) return;
y += MARGIN_TOP;
fontRenderer.drawStringWithShadow(this.labelColor + this.label + ":", x, y, 0);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
RenderHelper.enableGUIStandardItemLighting();
final int xTranslation = x;
final int yTranslation = y + fontRenderer.FONT_HEIGHT + 2;
final int zTranslation = GuiContainerManager.TOOLTIP_Z_OFFSET;
GL11.glTranslatef(xTranslation, yTranslation, zTranslation);
for (int index = 0; index < this.count; index++) {
drawSlot(0, index * SLOT_SIZE, index);
}
for (int index = 0; index < this.tailCount; index++) {
drawSlot(index * SLOT_SIZE, this.count * SLOT_SIZE, this.count + index);
}
NEIClientUtils.gl2DRenderContext(() -> {
final int textShift = ICON_OFFSET + Math.round((ICON_SIZE - fontRenderer.FONT_HEIGHT) / 2f);
for (int index = 0; index < this.count; index++) {
fontRenderer.drawStringWithShadow(
EnumChatFormatting.GRAY + this.names.get(index),
SLOT_SIZE + NAME_MARGIN,
index * SLOT_SIZE + textShift,
0xFFFFFF);
}
final int hidden = this.length - this.count - this.tailCount;
if (hidden > 0) {
final String text = "+" + hidden;
fontRenderer.drawStringWithShadow(
EnumChatFormatting.GRAY + text,
this.size.width - fontRenderer.getStringWidth(text) - 2,
this.count * SLOT_SIZE + textShift,
0xFFFFFF);
}
});
GL11.glTranslatef(-xTranslation, -yTranslation, -zTranslation);
GL11.glPopAttrib();
}
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);
}
}
@@ -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,22 +18,151 @@ 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 {
@FunctionalInterface
public interface AmountRenderer {
void draw(int x, int y, ItemStack stack, long amount);
}
public static class NoAmountRenderer implements AmountRenderer {
@Override
public void draw(int x, int y, ItemStack stack, long amount) {
GuiContainerManager.drawItem(x, y, stack, true, "");
}
protected static void drawAmountText(String text, Rectangle4i rect, int color, Alignment alignment) {
NEIClientUtils.drawNEIOverlayText(text, rect, 1, color, true, alignment);
}
}
public static class TotalAmountRenderer extends NoAmountRenderer {
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 FLUID_STACK_SIZE = 144;
protected final List<ItemStack> items;
protected final List<Long> amounts = new ArrayList<>();
protected AmountRenderer 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;
@@ -45,7 +175,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
public ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows) {
this.label = label;
this.items = groupingItemStacks(items);
this.saveStackSize = saveStackSize;
this.amountRenderer = saveStackSize ? new TotalAmountRenderer() : new NoAmountRenderer();
this.length = this.items.size();
if (this.length > 0) {
@@ -69,6 +199,11 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
}
public ItemsTooltipLineHandler setAmountRenderer(AmountRenderer amountRenderer) {
this.amountRenderer = amountRenderer;
return this;
}
public void setActiveStack(ItemStack activeStack) {
final ItemStack realStack = items.stream().filter(stack -> NEIClientUtils.areStacksSameType(stack, activeStack))
.findFirst().orElse(null);
@@ -126,19 +261,15 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
}
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;
String stackSize = !this.saveStackSize || drawStack.stackSize == 0 ? ""
: ReadableNumberConverter.INSTANCE.toWideReadableForm(drawStack.stackSize);
if (this.activeStackIndex == index + indexShift) {
NEIClientUtils.gl2DRenderContext(
() -> GuiDraw.drawRect(col * SLOT_SIZE - 1, row * SLOT_SIZE - 1, 18, 18, 0x66555555));
() -> GuiDraw.drawRect(col * SLOT_SIZE, row * SLOT_SIZE, SLOT_SIZE, SLOT_SIZE, 0x66555555));
}
drawItem(col * SLOT_SIZE, row * SLOT_SIZE, drawStack, stackSize);
drawStackWithAmount(col * SLOT_SIZE, row * SLOT_SIZE, index + indexShift);
}
if (this.count < this.items.size()) {
@@ -157,25 +288,23 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
GL11.glPopAttrib();
}
protected void drawItem(int x, int y, ItemStack drawStack, String stackSize) {
GuiContainerManager.drawItem(x, y, drawStack, true, stackSize);
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;
@@ -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();
@@ -102,6 +102,7 @@ public class NEIModContainer extends DummyModContainer {
gregTech5Loaded = Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi_post");
gtnhLibLoaded = Loader.isModLoaded("gtnhlib");
cubicChunksLoaded = Loader.isModLoaded("cubicchunks");
ServerHandler.preInit();
if (CommonUtils.isClient()) ClientHandler.preInit();
asmDataTable = event.getAsmData();
}
@@ -10,6 +10,7 @@ import net.minecraftforge.event.world.WorldEvent;
import codechicken.core.CommonUtils;
import codechicken.lib.packet.PacketCustom;
import codechicken.nei.item.ItemFluidDisplay;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent;
@@ -18,6 +19,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.registry.GameRegistry;
public class ServerHandler {
@@ -31,6 +33,14 @@ public class ServerHandler {
NEIActions.init();
}
public static void preInit() {
registerFluidDisplayItem();
}
private static void registerFluidDisplayItem() {
GameRegistry.registerItem(new ItemFluidDisplay(), "neiFluidDisplay");
}
@SubscribeEvent
public void tickEvent(TickEvent.WorldTickEvent event) {
if (event.phase == Phase.START && !event.world.isRemote
+2 -2
View File
@@ -146,14 +146,14 @@ public class API {
* Hide an item from the item panel Damage values of OreDictionary.WILDCARD_VALUE and ItemStackMap.WILDCARD_TAG tags
* function as wildcards for their respective variables
*/
public static void hideItem(ItemStack item) {
public static synchronized void hideItem(ItemStack item) {
if (!ItemInfo.hiddenItems.contains(item)) {
ItemInfo.hiddenItems.add(item);
LayoutManager.markItemsDirty();
}
}
public static void hideItem(String rule) {
public static synchronized void hideItem(String rule) {
ItemFilter filter = ItemStackFilterParser.parse(rule);
if (filter != null) {
ItemInfo.hiddenItemsRules.filters.add(filter);
@@ -36,6 +36,7 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.RegistryNamespaced;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.oredict.OreDictionary;
@@ -60,6 +61,7 @@ import codechicken.nei.config.HandlerDumper;
import codechicken.nei.config.ItemPanelDumper;
import codechicken.nei.config.RegistryDumper;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.item.FluidDisplayRenderer;
import codechicken.nei.item.ItemFluidDisplay;
import codechicken.nei.recipe.BrewingRecipeHandler;
import codechicken.nei.recipe.RecipeItemInputHandler;
@@ -134,7 +136,7 @@ public class ItemInfo {
public static void preInit() {
addMobSpawnerItem();
addFluidDisplayItem();
setupFluidDisplayItemClient();
}
public static void load() {
@@ -320,8 +322,9 @@ public class ItemInfo {
GameDataManipulator.replaceItem(Block.getIdFromBlock(Blocks.mob_spawner), new ItemMobSpawner());
}
private static void addFluidDisplayItem() {
GameRegistry.registerItem(new ItemFluidDisplay(), "neiFluidDisplay");
private static void setupFluidDisplayItemClient() {
ItemFluidDisplay.INSTANCE.setCreativeTab(ItemFluidDisplay.tabFluids);
MinecraftForgeClient.registerItemRenderer(ItemFluidDisplay.INSTANCE, new FluidDisplayRenderer());
}
private static void addInfiniteHandlers() {
@@ -67,6 +67,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;
@@ -134,6 +135,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
private RecipeTooltipLineHandler recipeTooltipLineHandler;
private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
private RecipeItemsTooltipLineHandler recipeItemsTooltipLineHandler;
private final CraftingTreeState uiState = new CraftingTreeState();
private final CraftingTreeToolbar toolbar;
@@ -939,12 +941,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 +965,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 +981,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 +1104,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;
@@ -88,6 +88,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) {
@@ -519,7 +523,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) {
@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IRecipeFilter;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.IRecipeHandler;
public class RecipeFilter implements IRecipeFilter {
@@ -78,7 +79,7 @@ public class RecipeFilter implements IRecipeFilter {
if (pStack == null) return false;
for (ItemStack stack : pStack.items) {
if (this.filter.matches(stack)) {
if (!ItemInfo.isHidden(stack) && this.filter.matches(stack)) {
return true;
}
}
@@ -2,17 +2,20 @@ package codechicken.nei.item;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import codechicken.nei.util.ReadableNumberConverter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class FluidDisplayRenderer implements IItemRenderer {
@Override
@@ -49,7 +52,8 @@ public class FluidDisplayRenderer implements IItemRenderer {
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);
OpenGlHelper
.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
final Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
@@ -64,17 +68,17 @@ public class FluidDisplayRenderer implements IItemRenderer {
}
private void renderAmountOverlay(ItemStack item, ItemFluidDisplay fluidDisplay) {
final FluidStack fluidStack = fluidDisplay.getFluid(item);
if (fluidStack == null || fluidStack.amount <= 0) {
final long amount = fluidDisplay.getAmountLong(item);
if (amount <= 0) {
return;
}
String amountString = "";
if (fluidStack.amount < 10_000) {
amountString = String.valueOf(fluidStack.amount) + "L";
if (amount < 10_000) {
amountString = String.valueOf(amount) + "L";
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(fluidStack.amount) + "L";
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(amount) + "L";
}
final FontRenderer fontRender = Minecraft.getMinecraft().fontRenderer;
@@ -10,7 +10,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@@ -40,36 +39,32 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
};
public ItemFluidDisplay() {
setMaxStackSize(1);
setUnlocalizedName("nei.fluidDisplay");
setMaxStackSize(1);
INSTANCE = this;
setCreativeTab(tabFluids);
MinecraftForgeClient.registerItemRenderer(this, new FluidDisplayRenderer());
}
public static ItemStack createStack(FluidStack fluidStack) {
if (fluidStack == null || fluidStack.getFluid() == null) {
return fluidStack == null ? null : createStack(fluidStack.getFluid(), fluidStack.amount);
}
public static ItemStack createStack(Fluid fluid, long amount) {
if (fluid == null) {
return null;
}
int fluidId;
try {
fluidId = FluidRegistry.getFluidID(fluidStack.getFluid());
fluidId = FluidRegistry.getFluidID(fluid);
} catch (Exception e) {
NEIClientConfig.logger.error("Failed to get fluid id for: " + fluidStack.getFluid().getName(), e);
NEIClientConfig.logger.error("Failed to get fluid id for: " + fluid.getName(), e);
return null;
}
final ItemStack stack = new ItemStack(INSTANCE, 1, fluidId);
final NBTTagCompound nbtTag = new NBTTagCompound();
if (fluidStack.tag != null) {
nbtTag.setTag("FluidTag", fluidStack.tag.copy());
}
nbtTag.setInteger("neiFluidDisplayAmount", fluidStack.amount);
nbtTag.setLong("neiFluidDisplayAmount", amount);
stack.setTagCompound(nbtTag);
return stack;
}
@@ -88,23 +83,25 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
}
final NBTTagCompound nbTag = stack.getTagCompound();
final FluidStack fluidStack = new FluidStack(fluid, nbTag.getInteger("neiFluidDisplayAmount"));
if (nbTag.hasKey("FluidTag")) {
fluidStack.tag = nbTag.getCompoundTag("FluidTag");
}
final FluidStack fluidStack = new FluidStack(
fluid,
(int) Math.min(nbTag.getLong("neiFluidDisplayAmount"), Integer.MAX_VALUE));
return fluidStack;
}
@Override
public int getCapacity(ItemStack stack) {
public long getAmountLong(ItemStack stack) {
if (stack == null || !(stack.getItem() instanceof ItemFluidDisplay) || !stack.hasTagCompound()) {
return 0;
}
return stack.getTagCompound().getInteger("neiFluidDisplayAmount");
return stack.getTagCompound().getLong("neiFluidDisplayAmount");
}
@Override
public int getCapacity(ItemStack stack) {
return (int) Math.min(getAmountLong(stack), Integer.MAX_VALUE);
}
@Override
@@ -180,7 +177,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item aItem, CreativeTabs aTab, List<ItemStack> aList) {
for (int i = 0, j = FluidRegistry.getMaxID(); i < j; i++) {
for (int i = 0, j = FluidRegistry.getMaxID(); i <= j; i++) {
final Fluid fluid = FluidRegistry.getFluid(i);
if (fluid == null) {
continue;
@@ -20,6 +20,7 @@ public class AcceptsFollowingTooltipLineHandler extends ItemsTooltipLineHandler
super(NEIClientUtils.translate("recipe.accepts"), items, false, maxRows);
this.tooltipGUID = tooltipGUID;
setActiveStack(activeStack);
setAmountRenderer(new FavoriteAmountRenderer());
}
public static AcceptsFollowingTooltipLineHandler of(Object tooltipGUID, List<ItemStack> items,
@@ -38,12 +39,15 @@ public class AcceptsFollowingTooltipLineHandler extends ItemsTooltipLineHandler
return null;
}
@Override
protected void drawItem(int x, int y, ItemStack drawStack, String stackSize) {
super.drawItem(x, y, drawStack, stackSize);
protected static class FavoriteAmountRenderer extends NoAmountRenderer {
if (FavoriteRecipes.containsManual(drawStack)) {
NEIClientUtils.drawNEIOverlayText("F", x, y);
@Override
public void draw(int x, int y, ItemStack stack, long amount) {
super.draw(x, y, stack, amount);
if (FavoriteRecipes.containsManual(stack)) {
NEIClientUtils.drawNEIOverlayText("F", x, y);
}
}
}
@@ -70,7 +70,7 @@ public class GuiOverlayButton extends GuiRecipeButton {
if (format == ItemOverlayFormat.BACKGROUND) {
NEIClientUtils.gl2DRenderContext(
() -> drawRect(
() -> GuiDraw.drawRect(
this.slot.relx,
this.slot.rely,
this.slot.width,
@@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.item.Item;
@@ -43,7 +45,13 @@ public class Recipe {
if (!isShapedRecipe()) {
// sort to ignore ingredients position in shapeless recipes
this.ingredients.sort(Comparator.comparing(StackInfo::getItemStackGUID));
final Map<ItemStack, String> guids = new IdentityHashMap<>();
for (ItemStack ingredient : this.ingredients) {
guids.put(ingredient, StackInfo.getItemStackGUID(ingredient));
}
this.ingredients.sort(Comparator.comparing(guids::get));
}
}
@@ -52,7 +60,10 @@ public class Recipe {
}
public static RecipeId of(IRecipeHandler handler, int recipeIndex) {
final List<PositionedStack> ingredients = handler.getIngredientStacks(recipeIndex);
return of(handler, recipeIndex, handler.getIngredientStacks(recipeIndex));
}
public static RecipeId of(IRecipeHandler handler, int recipeIndex, List<PositionedStack> ingredients) {
final String handlerName = GuiRecipeTab.getHandlerInfo(handler).getHandlerName();
PositionedStack pStackResult = handler.getResultStack(recipeIndex);
@@ -0,0 +1,332 @@
package codechicken.nei.recipe;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.ItemsListTooltipLineHandler;
import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.ItemsTooltipLineHandler.StacksAmountRenderer;
import codechicken.nei.ItemsTooltipLineHandler.TotalAmountRenderer;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IGuiContainerOverlay;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.Recipe.RecipeIngredient;
import codechicken.nei.util.ReadableNumberConverter;
public class RecipeItemsTooltipLineHandler implements ITooltipLineHandler {
protected static class ChanceTotalAmountRenderer extends TotalAmountRenderer {
protected final Set<ItemStack> approximate;
public ChanceTotalAmountRenderer(Set<ItemStack> approximate) {
this.approximate = approximate;
}
@Override
protected String formatAmount(ItemStack stack, long amount) {
final String text = super.formatAmount(stack, amount);
if (!this.approximate.contains(stack)) {
return text;
} else if (!text.isEmpty()) {
return EnumChatFormatting.GOLD + "~" + text;
} else if (amount == 0) {
return EnumChatFormatting.GOLD + "~0";
}
return text;
}
}
protected static class ChanceStacksAmountRenderer extends StacksAmountRenderer {
protected static final int APPROXIMATE_COLOR = 0xFFAA00;
protected final Set<ItemStack> approximate;
public ChanceStacksAmountRenderer(Set<ItemStack> approximate) {
this.approximate = approximate;
}
@Override
protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) {
if (amount == 0) {
Badge.notConsumed().draw(rect);
} else {
super.drawAmount(rect, stack, amount);
}
}
@Override
protected String getPrefix(ItemStack stack) {
return this.approximate.contains(stack) ? "~" : "";
}
@Override
protected int getColor(ItemStack stack) {
return this.approximate.contains(stack) ? APPROXIMATE_COLOR : super.getColor(stack);
}
}
protected static final int MAX_ROWS = 15;
protected final RecipeId recipeId;
protected final long multiplier;
protected boolean useInventory = false;
protected final List<ItemsTooltipLineHandler> lines = new ArrayList<>();
protected final Dimension size = new Dimension();
protected String title = "";
protected boolean created = false;
public RecipeItemsTooltipLineHandler(RecipeId recipeId, long multiplier) {
this.recipeId = recipeId;
this.multiplier = multiplier;
}
public RecipeItemsTooltipLineHandler setUseInventory(boolean useInventory) {
this.useInventory = useInventory;
this.created = false;
return this;
}
public RecipeId getRecipeId() {
return this.recipeId;
}
public long getMultiplier() {
return this.multiplier;
}
public boolean isUseInventory() {
return this.useInventory;
}
public String getTitle() {
ensureCreated();
return this.title;
}
@Override
public Dimension getSize() {
ensureCreated();
return this.size;
}
protected void ensureCreated() {
if (!this.created) {
this.created = true;
createLines();
}
}
@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 static int getIngredientOrder(ItemStack stack) {
return StackInfo.isFluidDisplayItem(stack) ? 2 : stack.stackSize == 0 ? 0 : 1;
}
protected void createLines() {
this.lines.clear();
this.size.setSize(0, 0);
final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(this.recipeId);
if (handlerRef == null) {
return;
}
final Recipe recipe = Recipe.of(handlerRef);
final Set<NBTTagCompound> approximateResults = new HashSet<>();
final Set<NBTTagCompound> approximateIngredients = new HashSet<>();
final List<ItemStack> results = multiplyItems(recipe.getResults(), false, approximateResults);
final List<ItemStack> ingredients = multiplyItems(recipe.getIngredients(), true, approximateIngredients);
final ItemStackAmount ingredientsAmount = ItemStackAmount.of(ingredients);
ingredients.sort(Comparator.comparingInt(RecipeItemsTooltipLineHandler::getIngredientOrder));
this.title = handlerRef.handler.getRecipeName().trim() + " (x"
+ ReadableNumberConverter.INSTANCE.toWideReadableForm(this.multiplier)
+ ")";
addResultLine(results, approximateResults);
addRequiredLine(ingredients, approximateIngredients);
if (this.useInventory) {
final List<ItemStack> needed = subtractItems(ingredientsAmount, getInventoryItems());
final ItemStackAmount neededAmount = ItemStackAmount.of(needed);
final ItemStackAmount consumedAmount = ItemStackAmount.of(ingredientsAmount);
consumedAmount.removeIf(entry -> entry.getValue() <= 0);
if (!neededAmount.equals(consumedAmount)) {
addNeededLine(
needed,
approximateIngredients,
needed.size() == 1 || ingredientsAmount.size() + neededAmount.size() <= MAX_ROWS);
}
}
int width = 0;
int height = 0;
for (ItemsTooltipLineHandler line : this.lines) {
width = Math.max(width, line.getSize().width);
height += line.getSize().height;
}
this.size.setSize(width, height);
}
protected void addResultLine(List<ItemStack> items, Set<NBTTagCompound> approximate) {
final String label = NEIClientUtils.translate("recipe.items.results");
final ItemsTooltipLineHandler line = items.size() == 1 ? new ItemsListTooltipLineHandler(label, items, MAX_ROWS)
: new ItemsTooltipLineHandler(label, items);
if (line.isEmpty()) {
return;
}
line.setLabelColor(EnumChatFormatting.GREEN);
final Set<ItemStack> approximateItems = Collections.newSetFromMap(new IdentityHashMap<>());
for (ItemStack stack : line.getItems()) {
if (approximate.contains(StackInfo.itemStackToNBT(stack, false))) {
approximateItems.add(stack);
}
}
line.setAmountRenderer(new ChanceTotalAmountRenderer(approximateItems));
this.lines.add(line);
}
protected void addRequiredLine(List<ItemStack> items, Set<NBTTagCompound> approximate) {
final String label = NEIClientUtils.translate("recipe.items.ingredients");
final ItemsTooltipLineHandler line = new ItemsListTooltipLineHandler(label, items, MAX_ROWS);
if (line.isEmpty()) {
return;
}
line.setLabelColor(EnumChatFormatting.YELLOW);
final Set<ItemStack> approximateItems = Collections.newSetFromMap(new IdentityHashMap<>());
for (ItemStack stack : line.getItems()) {
if (approximate.contains(StackInfo.itemStackToNBT(stack, false))) {
approximateItems.add(stack);
}
}
line.setAmountRenderer(new ChanceStacksAmountRenderer(approximateItems));
this.lines.add(line);
}
protected void addNeededLine(List<ItemStack> items, Set<NBTTagCompound> approximate, boolean vertical) {
final String label = NEIClientUtils.translate("recipe.items.ingredients_needed");
final ItemsTooltipLineHandler line = vertical ? new ItemsListTooltipLineHandler(label, items, MAX_ROWS)
: new ItemsTooltipLineHandler(label, items);
if (line.isEmpty()) {
return;
}
line.setLabelColor(EnumChatFormatting.RED);
final Set<ItemStack> approximateItems = Collections.newSetFromMap(new IdentityHashMap<>());
for (ItemStack stack : line.getItems()) {
if (approximate.contains(StackInfo.itemStackToNBT(stack, false))) {
approximateItems.add(stack);
}
}
line.setAmountRenderer(new ChanceStacksAmountRenderer(approximateItems));
this.lines.add(line);
}
protected List<ItemStack> multiplyItems(List<RecipeIngredient> items, boolean ingredients,
Set<NBTTagCompound> approximate) {
final ItemStackAmount chanceAmounts = new ItemStackAmount();
final List<ItemStack> result = new ArrayList<>();
for (RecipeIngredient item : items) {
chanceAmounts.add(item.getItemStack(), (long) item.getAmount() * item.getChance());
}
for (Map.Entry<NBTTagCompound, Long> entry : chanceAmounts.entrySet()) {
final long amount = entry.getValue() * this.multiplier;
final long entryAmount = ingredients
? (amount + PositionedStack.CHANCE_FULL - 1) / PositionedStack.CHANCE_FULL
: amount / PositionedStack.CHANCE_FULL;
final ItemStack stack = StackInfo.loadFromNBT(entry.getKey(), entryAmount);
if (amount % PositionedStack.CHANCE_FULL != 0) {
approximate.add(entry.getKey());
}
result.add(stack);
}
return result;
}
protected static ItemStackAmount getInventoryItems() {
GuiScreen screen = NEIClientUtils.mc().currentScreen;
if (screen instanceof IGuiContainerOverlay overlay) {
screen = overlay.getFirstScreen();
}
if (screen instanceof GuiContainer container) {
return AutoCraftingManager.getInventoryItems(container);
}
return new ItemStackAmount();
}
protected static List<ItemStack> subtractItems(ItemStackAmount items, ItemStackAmount subtrahend) {
final List<ItemStack> result = new ArrayList<>();
for (Map.Entry<NBTTagCompound, Long> entry : items.entrySet()) {
final ItemStack stack = StackInfo.loadFromNBT(entry.getKey(), 0);
final long amount = entry.getValue() - subtrahend.getOrDefault(stack, 0L);
if (amount > 0) {
result.add(StackInfo.withAmount(stack, amount));
}
}
return result;
}
}
@@ -2,13 +2,17 @@ package codechicken.nei.recipe;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import net.minecraft.client.gui.GuiRepair;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import codechicken.nei.ItemList;
@@ -35,14 +39,17 @@ public class RepairRecipeHandler extends TemplateRecipeHandler {
private static class ItemStackKey {
private final ItemStack stack;
private final int hashCode;
public ItemStackKey(ItemStack stack) {
this.stack = stack;
this.hashCode = stack.isItemStackDamageable() ? stack.getItem().hashCode()
: 31 * stack.getItem().hashCode() + stack.getItemDamage();
}
@Override
public int hashCode() {
return stack.getItem().hashCode();
return this.hashCode;
}
@Override
@@ -104,22 +111,48 @@ public class RepairRecipeHandler extends TemplateRecipeHandler {
reloadRepairRecipesTask.restart();
}
private void buildCache() {
final Map<ItemStackKey, RepairPair> recipes = new HashMap<>();
private static final Set<Integer> knownBrokenItemTypes = ConcurrentHashMap.newKeySet();
private static volatile List<ItemStack> uniqueMaterials;
for (ItemStack itemstack1 : ItemList.items) {
recipes.computeIfAbsent(new ItemStackKey(itemstack1), key -> this.getRepairRecipe(key.stack));
private void buildCache() {
if (cachedRecipes != null) return;
uniqueMaterials = collectUniqueMaterials();
final Map<ItemStackKey, RepairPair> recipes = new ConcurrentHashMap<>();
try {
ItemList.forkJoinPool.submit(
() -> ItemList.items.parallelStream().forEach(
itemstack1 -> recipes
.computeIfAbsent(new ItemStackKey(itemstack1), key -> getRepairRecipe(key.stack))))
.get();
} catch (InterruptedException | ExecutionException e) {
NEIClientConfig.logger.error("Failed to build repair recipe cache", e);
}
cachedRecipes = recipes.values().stream().filter(recipe -> recipe != null).collect(Collectors.toList());
}
private static List<ItemStack> collectUniqueMaterials() {
final Map<Long, ItemStack> unique = new LinkedHashMap<>();
for (ItemStack stack : ItemList.items) {
final long key = ((long) Item.getIdFromItem(stack.getItem()) << 32) | (stack.getItemDamage() & 0xFFFFFFFFL);
unique.putIfAbsent(key, stack);
}
return new ArrayList<>(unique.values());
}
private RepairPair getRepairRecipe(ItemStack itemstack1) {
if (!itemstack1.isItemStackDamageable()) return null;
final List<ItemStack> permutations = new ArrayList<>();
final int itemId = Item.getIdFromItem(itemstack1.getItem());
if (knownBrokenItemTypes.contains(itemId)) return null;
for (ItemStack itemstack2 : ItemList.items) {
final List<ItemStack> permutations = new ArrayList<>();
final List<ItemStack> candidates = uniqueMaterials != null ? uniqueMaterials : collectUniqueMaterials();
for (ItemStack itemstack2 : candidates) {
try {
if (itemstack1.getItem().getIsRepairable(itemstack1, itemstack2)) {
final ItemStack right = itemstack2.copy();
@@ -127,7 +160,8 @@ public class RepairRecipeHandler extends TemplateRecipeHandler {
permutations.add(right);
}
} catch (Exception e) {
// Catch exceptions from mods that don't properly implement getIsRepairable
knownBrokenItemTypes.add(itemId);
break;
}
}
@@ -74,20 +74,18 @@ class SearchRecipeHandler<H extends IRecipeHandler> {
}
List<Integer> filtered = null;
final List<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed()
.collect(Collectors.toCollection(ArrayList::new));
final List<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed().collect(Collectors.toList());
try {
filtered = ItemList.forkJoinPool.submit(
() -> recipes.parallelStream()
.filter(recipe -> mathRecipe(this.original, filteredRecipes.get(recipe), filter))
.collect(Collectors.toCollection(ArrayList::new)))
.collect(Collectors.toList()))
.get();
filtered.sort((a, b) -> a - b);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return filtered;
@@ -59,7 +59,7 @@ public class StackInfo {
if (nbtTag != null) {
nbtTag = (NBTTagCompound) nbtTag.copy();
nbtTag.setInteger("Count", (int) Math.max(Math.min(customCount, Integer.MAX_VALUE), 0));
nbtTag.setLong("Count", Math.max(customCount, 0));
return loadFromNBT(nbtTag);
}
@@ -126,7 +126,15 @@ public class StackInfo {
}
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
if (stackA == null || stackB == null || stackA.getItem() != stackB.getItem()) {
if (stackA == null || stackB == null) {
return false;
}
if (isFluidDisplayItem(stackA)) {
return isFluidDisplayItem(stackB) && getFluid(stackA).isFluidEqual(getFluid(stackB));
}
if (stackA.getItem() != stackB.getItem()) {
return false;
}
@@ -142,6 +150,10 @@ public class StackInfo {
}
public static synchronized FluidStack getFluid(ItemStack stack) {
if (stack == null) {
return null;
}
ItemStackKey key = new ItemStackKey(stack);
FluidStack fluid = fluidcache.get(key);
@@ -158,7 +170,8 @@ public class StackInfo {
}
public static boolean isFluidContainer(ItemStack stack) {
return stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack);
return stack.getItem() instanceof IFluidContainerItem && !isFluidDisplayItem(stack)
|| FluidContainerRegistry.isContainer(stack);
}
public static String getItemStackGUID(ItemStack stack) {
@@ -45,7 +45,7 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
final ItemStack stack = ItemStack.loadItemStackFromNBT(nbtTag);
if (stack != null) {
stack.stackSize = nbtTag.getInteger("Count");
stack.stackSize = (int) Math.min(nbtTag.getLong("Count"), Integer.MAX_VALUE);
}
return stack;
@@ -31,13 +31,10 @@ public class FluidDisplayStackStringifyHandler implements IStackStringifyHandler
return null;
}
final long amount = ((ItemFluidDisplay) stack.getItem()).getAmountLong(stack);
final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString(NBT_FLUID_NAME, fluidStack.getFluid().getName());
nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 1);
if (fluidStack.tag != null) {
nbTag.setTag("FluidTag", fluidStack.tag.copy());
}
nbTag.setLong("Count", saveStackSize ? amount : 1);
return nbTag;
}
@@ -55,13 +52,7 @@ public class FluidDisplayStackStringifyHandler implements IStackStringifyHandler
return null;
}
final FluidStack fluidStack = new FluidStack(fluid, nbtTag.getInteger("Count"));
if (nbtTag.hasKey("FluidTag")) {
fluidStack.tag = nbtTag.getCompoundTag("FluidTag");
}
return ItemFluidDisplay.createStack(fluidStack);
return ItemFluidDisplay.createStack(fluid, nbtTag.getLong("Count"));
}
@Override
@@ -67,10 +67,9 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
if (nbtTag.hasKey("gtFluidName")) {
final String fluidName = nbtTag.getString("gtFluidName");
final Fluid fluid = FluidRegistry.getFluid(fluidName);
final int amount = nbtTag.getInteger("Count");
if (fluid != null) {
return ItemFluidDisplay.createStack(new FluidStack(fluid, amount));
return ItemFluidDisplay.createStack(fluid, nbtTag.getLong("Count"));
}
}
@@ -98,11 +97,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
Fluid fluid = FluidRegistry.getFluid(nbtTag.getString("Fluid").toLowerCase());
if (fluid != null) {
FluidStack fluidStack = new FluidStack(fluid, stack.stackSize);
if (nbtTag.hasKey("FluidTag")) {
fluidStack.tag = nbtTag.getCompoundTag("FluidTag");
}
return fluidStack;
return new FluidStack(fluid, stack.stackSize);
}
}
} catch (Exception e) {}
@@ -4,8 +4,11 @@ import java.util.regex.Pattern;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.recipe.StackInfo;
import cpw.mods.fml.common.registry.GameData;
public class IdentifierFilter implements ItemFilter {
@@ -18,15 +21,33 @@ public class IdentifierFilter implements ItemFilter {
@Override
public boolean matches(ItemStack stack) {
final FluidStack fluidStack = StackInfo.isFluidDisplayItem(stack) ? StackInfo.getFluid(stack) : null;
if (fluidStack != null) {
return this.pattern.matcher(getFluidStringIdentifier(fluidStack) + "\n" + getFluidIdentifier(fluidStack))
.find();
}
return this.pattern.matcher(getStringIdentifier(stack) + "\n" + getIdentifier(stack)).find();
}
protected String getFluidIdentifier(FluidStack fluidStack) {
return String.valueOf(FluidRegistry.getFluidID(fluidStack.getFluid()));
}
protected String getFluidStringIdentifier(FluidStack fluidStack) {
final String name = FluidRegistry.getDefaultFluidName(fluidStack.getFluid());
return name == null || name.isEmpty() ? "Unknown:Unknown" : name;
}
protected String getIdentifier(ItemStack stack) {
return Item.getIdFromItem(stack.getItem()) + ":" + stack.getItemDamage();
}
protected String getStringIdentifier(ItemStack stack) {
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
final String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
return name == null || name.isEmpty() ? "Unknown:Unknown" : name;
}
@@ -7,11 +7,12 @@ import java.util.regex.Pattern;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.item.ItemFluidDisplay;
import codechicken.nei.recipe.StackInfo;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -41,9 +42,10 @@ public class ModNameFilter implements ItemFilter {
}
protected static String getModId(ItemStack itemStack) {
final FluidStack fluidStack = StackInfo.isFluidDisplayItem(itemStack) ? StackInfo.getFluid(itemStack) : null;
if (itemStack.getItem() instanceof ItemFluidDisplay fluidDisplay) {
return getFluidModId(fluidDisplay, itemStack);
if (fluidStack != null) {
return getFluidModId(fluidStack.getFluid());
}
if (!ItemInfo.itemOwners.containsKey(itemStack.getItem())) {
@@ -59,8 +61,7 @@ public class ModNameFilter implements ItemFilter {
return ItemInfo.itemOwners.get(itemStack.getItem());
}
private static String getFluidModId(ItemFluidDisplay fluidDisplay, ItemStack itemStack) {
final Fluid fluid = FluidRegistry.getFluid(itemStack.getItemDamage());
private static String getFluidModId(Fluid fluid) {
final String fluidName = FluidRegistry.getDefaultFluidName(fluid);
if (!fluidOwners.containsKey(fluidName)) {
@@ -667,6 +667,10 @@ nei.recipe.badge.ncp.tooltip=Considered in parallel calculation, but not get con
nei.recipe.badge.chance.consume=Consume Chance: %s
nei.recipe.badge.chance.output=Output Chance: %s
nei.recipe.items.results=Results
nei.recipe.items.ingredients=Ingredients
nei.recipe.items.ingredients_needed=Ingredients Needed
# Deprecated
nei.recipe.fuel.required=%s required
# Deprecated