mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-19 20:00:00 +00:00
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4062f6c001 | ||
|
|
8fbb876a81 | ||
|
|
e050faaa90 | ||
|
|
576da1468c | ||
|
|
316494df15 | ||
|
|
66deab6dbd | ||
|
|
4953edde4b | ||
|
|
9873de760f | ||
|
|
355cc5bd0e | ||
|
|
183e40a6c2 | ||
|
|
79660a09d5 | ||
|
|
b03ae51e3c | ||
|
|
91d57c28b7 | ||
|
|
06cdea3fd6 | ||
|
|
ceae486a31 | ||
|
|
d35e77661f | ||
|
|
4285632807 | ||
|
|
b16916dbe6 |
No files matched your search
+24
-5
@@ -1,4 +1,4 @@
|
||||
//version: 1704751096
|
||||
//version: 1706545953
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
Also, you may replace this file at any time if there is an update available.
|
||||
@@ -122,6 +122,7 @@ propertyDefaultIfUnset("modrinthProjectId", "")
|
||||
propertyDefaultIfUnset("modrinthRelations", "")
|
||||
propertyDefaultIfUnset("curseForgeProjectId", "")
|
||||
propertyDefaultIfUnset("curseForgeRelations", "")
|
||||
propertyDefaultIfUnset("versionPattern", "")
|
||||
propertyDefaultIfUnset("minimizeShadowedDependencies", true)
|
||||
propertyDefaultIfUnset("relocateShadowedDependencies", true)
|
||||
// Deprecated properties (kept for backwards compat)
|
||||
@@ -370,6 +371,7 @@ catch (Exception ignored) {
|
||||
// Pulls version first from the VERSION env and then git tag
|
||||
String identifiedVersion
|
||||
String versionOverride = System.getenv("VERSION") ?: null
|
||||
boolean checkVersion = false
|
||||
try {
|
||||
// Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty
|
||||
if (versionOverride == null) {
|
||||
@@ -388,6 +390,8 @@ try {
|
||||
}
|
||||
} else if (isDirty) {
|
||||
identifiedVersion += "-${branchName}+${gitDetails.gitHash}-dirty"
|
||||
} else {
|
||||
checkVersion = true
|
||||
}
|
||||
} else {
|
||||
identifiedVersion = versionOverride
|
||||
@@ -409,6 +413,8 @@ ext {
|
||||
|
||||
if (identifiedVersion == versionOverride) {
|
||||
out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7')
|
||||
} else if (checkVersion && versionPattern && !(identifiedVersion ==~ versionPattern)) {
|
||||
throw new GradleException("Invalid version: '$identifiedVersion' does not match version pattern '$versionPattern'")
|
||||
}
|
||||
|
||||
group = "com.github.GTNewHorizons"
|
||||
@@ -428,18 +434,31 @@ minecraft {
|
||||
for (f in replaceGradleTokenInFile.split(',')) {
|
||||
tagReplacementFiles.add f
|
||||
}
|
||||
out.style(Style.Info).text('replaceGradleTokenInFile is deprecated! Consider using generateGradleTokenClass.').println()
|
||||
}
|
||||
if (gradleTokenModId) {
|
||||
injectedTags.put gradleTokenModId, modId
|
||||
if (replaceGradleTokenInFile) {
|
||||
injectedTags.put gradleTokenModId, modId
|
||||
} else {
|
||||
out.style(Style.Failure).text('gradleTokenModId is deprecated! The field will no longer be generated.').println()
|
||||
}
|
||||
}
|
||||
if (gradleTokenModName) {
|
||||
injectedTags.put gradleTokenModName, modName
|
||||
if (replaceGradleTokenInFile) {
|
||||
injectedTags.put gradleTokenModName, modName
|
||||
} else {
|
||||
out.style(Style.Failure).text('gradleTokenModName is deprecated! The field will no longer be generated.').println()
|
||||
}
|
||||
}
|
||||
if (gradleTokenVersion) {
|
||||
injectedTags.put gradleTokenVersion, modVersion
|
||||
}
|
||||
if (gradleTokenGroupName) {
|
||||
injectedTags.put gradleTokenGroupName, modGroup
|
||||
if (replaceGradleTokenInFile) {
|
||||
injectedTags.put gradleTokenGroupName, modGroup
|
||||
} else {
|
||||
out.style(Style.Failure).text('gradleTokenGroupName is deprecated! The field will no longer be generated.').println()
|
||||
}
|
||||
}
|
||||
if (enableGenericInjection.toBoolean()) {
|
||||
injectMissingGenerics.set(true)
|
||||
@@ -632,7 +651,7 @@ repositories {
|
||||
|
||||
def mixinProviderGroup = "io.github.legacymoddingmc"
|
||||
def mixinProviderModule = "unimixins"
|
||||
def mixinProviderVersion = "0.1.13"
|
||||
def mixinProviderVersion = "0.1.15"
|
||||
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
|
||||
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
|
||||
ext.mixinProviderSpec = mixinProviderSpec
|
||||
|
||||
+3
-3
@@ -28,10 +28,10 @@ developmentEnvironmentUserName = Developer
|
||||
# Leave these properties empty to skip individual token replacements
|
||||
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
|
||||
generateGradleTokenClass = codechicken.nei.Tags
|
||||
gradleTokenModId = MODID
|
||||
gradleTokenModName = MODNAME
|
||||
gradleTokenModId =
|
||||
gradleTokenModName =
|
||||
gradleTokenVersion = VERSION
|
||||
gradleTokenGroupName = GROUPNAME
|
||||
gradleTokenGroupName =
|
||||
# [DEPRECATED]
|
||||
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
|
||||
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
|
||||
@@ -269,27 +269,23 @@ public class BookmarkCraftingChain {
|
||||
return false;
|
||||
}
|
||||
|
||||
int shift = 0;
|
||||
int minRecipeIndex = 0;
|
||||
int minShift = 0x7fffff;
|
||||
int minShift = Integer.MAX_VALUE;
|
||||
|
||||
for (CraftingChainItem item : request.outputs.get(stackIndex)) {
|
||||
if (!request.initialItems.contains(item.recipeIndex) && item.factor > 0) {
|
||||
long ingrCount = calculateCount(request, request.inputs.get(item.stackIndex));
|
||||
long outputCount = calculateCount(request, request.outputs.get(item.stackIndex));
|
||||
long shift = (long) Math.ceil((ingrCount - outputCount) / (double) item.factor);
|
||||
|
||||
while ((outputCount + item.factor * shift) < ingrCount && shift < minShift) {
|
||||
shift++;
|
||||
}
|
||||
|
||||
if (shift < minShift) {
|
||||
minShift = shift;
|
||||
if (shift > 0 && shift < minShift) {
|
||||
minShift = (int) shift;
|
||||
minRecipeIndex = item.recipeIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (minShift < 0x7fffff) {
|
||||
if (minShift < Integer.MAX_VALUE) {
|
||||
request.multiplier.put(minRecipeIndex, request.multiplier.get(minRecipeIndex) + minShift);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,44 @@ public class BookmarkPanel extends PanelWidget {
|
||||
this.ungroup = ungroup;
|
||||
this.rowIndexA = rowIndexA;
|
||||
}
|
||||
|
||||
public int getTopRowIndex(BookmarkGrid BGrid) {
|
||||
int topRowIndex = Math.min(this.rowIndexA, this.rowIndexB);
|
||||
int topItemIndex = BGrid.getRowItemIndex(topRowIndex, true);
|
||||
ItemStackMetadata meta = topItemIndex >= 0 ? BGrid.metadata.get(topItemIndex) : null;
|
||||
|
||||
if (meta != null && meta.recipeId != null) {
|
||||
while (topItemIndex > 0 && meta.groupId == BGrid.metadata.get(topItemIndex - 1).groupId
|
||||
&& meta.recipeId.equals(BGrid.metadata.get(topItemIndex - 1).recipeId)) {
|
||||
topItemIndex--;
|
||||
}
|
||||
|
||||
int index = BGrid.getMask().indexOf(topItemIndex);
|
||||
topRowIndex = index == -1 ? 0 : index / BGrid.columns;
|
||||
}
|
||||
|
||||
return topRowIndex;
|
||||
}
|
||||
|
||||
public int getBottomRowIndex(BookmarkGrid BGrid) {
|
||||
int bottomRowIndex = Math.max(this.rowIndexA, this.rowIndexB);
|
||||
int bottomItemIndex = BGrid.getRowItemIndex(bottomRowIndex, false);
|
||||
ItemStackMetadata meta = bottomItemIndex >= 0 ? BGrid.metadata.get(bottomItemIndex) : null;
|
||||
|
||||
if (meta != null && meta.recipeId != null) {
|
||||
int size = BGrid.size();
|
||||
|
||||
while (bottomItemIndex < size - 1 && meta.groupId == BGrid.metadata.get(bottomItemIndex + 1).groupId
|
||||
&& meta.recipeId.equals(BGrid.metadata.get(bottomItemIndex + 1).recipeId)) {
|
||||
bottomItemIndex++;
|
||||
}
|
||||
|
||||
int index = BGrid.getMask().indexOf(bottomItemIndex);
|
||||
bottomRowIndex = index == -1 ? BGrid.getLastRowIndex() : index / BGrid.columns;
|
||||
}
|
||||
|
||||
return bottomRowIndex;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ItemStackMetadata {
|
||||
@@ -179,7 +217,9 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
private static class RecipeTooltipRenderer {
|
||||
|
||||
public int slotIndex = 0;
|
||||
public ItemStack stack = null;
|
||||
public BookmarkRecipeId recipeId = null;
|
||||
|
||||
public GuiRecipe<?> gui = null;
|
||||
public Runnable createRecipeGui = null;
|
||||
}
|
||||
@@ -281,6 +321,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
if (c == 0 && (meta.recipeId == null || meta.ingredient == false
|
||||
|| index + 1 < rows * columns && isInvalidSlot(index + 1)
|
||||
|| previousMeta.groupId != meta.groupId
|
||||
|| meta.ingredient && !meta.recipeId.equals(previousMeta.recipeId))) {
|
||||
// In first column must be an item without recipe, a recipe result, or an ingredient
|
||||
// if the second column is occupied
|
||||
@@ -402,8 +443,8 @@ public class BookmarkPanel extends PanelWidget {
|
||||
int previoudGroupId = DEFAULT_GROUP_ID;
|
||||
|
||||
if (groupingItem != null && groupingItem.rowIndexB != -1) {
|
||||
int topRowIndex = Math.min(groupingItem.rowIndexA, groupingItem.rowIndexB);
|
||||
int bottomRowIndex = Math.max(groupingItem.rowIndexA, groupingItem.rowIndexB);
|
||||
int topRowIndex = groupingItem.getTopRowIndex(this);
|
||||
int bottomRowIndex = groupingItem.getBottomRowIndex(this);
|
||||
int groupIdA = groupMask.get(groupingItem.rowIndexA);
|
||||
int groupId = groupingItem.ungroup ? DEFAULT_GROUP_ID : (groupIdA == DEFAULT_GROUP_ID ? -1 : groupIdA);
|
||||
groupMask = new ArrayList<>(groupMask);
|
||||
@@ -414,12 +455,12 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
if (groupIdA != DEFAULT_GROUP_ID && !groupingItem.ungroup
|
||||
&& groupingItem.rowIndexA != groupingItem.rowIndexB) {
|
||||
if (groupingItem.rowIndexB == topRowIndex) {
|
||||
if (groupingItem.rowIndexB < groupingItem.rowIndexA) {
|
||||
for (int rowIndex = topRowIndex - 1; rowIndex >= 0
|
||||
&& groupMask.get(rowIndex) == groupIdA; rowIndex--) {
|
||||
groupMask.set(rowIndex, DEFAULT_GROUP_ID);
|
||||
}
|
||||
} else if (groupingItem.rowIndexB == bottomRowIndex) {
|
||||
} else if (groupingItem.rowIndexB > groupingItem.rowIndexA) {
|
||||
for (int rowIndex = bottomRowIndex + 1; rowIndex < groupMask.size()
|
||||
&& groupMask.get(rowIndex) == groupIdA; rowIndex++) {
|
||||
groupMask.set(rowIndex, DEFAULT_GROUP_ID);
|
||||
@@ -633,8 +674,8 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
protected void createGroup(GroupingItem groupingItem) {
|
||||
final List<Integer> mask = getMask();
|
||||
final int topRowIndex = Math.min(groupingItem.rowIndexA, groupingItem.rowIndexB);
|
||||
final int bottomRowIndex = Math.max(groupingItem.rowIndexA, groupingItem.rowIndexB);
|
||||
final int topRowIndex = groupingItem.getTopRowIndex(this);
|
||||
final int bottomRowIndex = groupingItem.getBottomRowIndex(this);
|
||||
final int groupIdA = getRowGroupId(groupingItem.rowIndexA);
|
||||
final int startMaskIndex = topRowIndex * columns;
|
||||
final int endMaskIntex = Math.min((bottomRowIndex + 1) * columns, mask.size());
|
||||
@@ -1032,16 +1073,17 @@ public class BookmarkPanel extends PanelWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.recipeTooltipRenderer == null || this.recipeTooltipRenderer.slotIndex != focused.slotIndex) {
|
||||
|
||||
if (this.recipeTooltipRenderer == null || this.recipeTooltipRenderer.recipeId != meta.recipeId) {
|
||||
this.recipeTooltipRenderer = new RecipeTooltipRenderer();
|
||||
this.recipeTooltipRenderer.slotIndex = focused.slotIndex;
|
||||
this.recipeTooltipRenderer.stack = this.realItems.get(focused.slotIndex);
|
||||
this.recipeTooltipRenderer.recipeId = meta.recipeId;
|
||||
|
||||
this.recipeTooltipRenderer.createRecipeGui = () -> {
|
||||
final int slotIndex = this.recipeTooltipRenderer.slotIndex;
|
||||
final BookmarkRecipeId recipeId = this.metadata.get(slotIndex).recipeId;
|
||||
GuiRecipe<?> gui = GuiCraftingRecipe
|
||||
.createRecipeGui("recipeId", false, this.realItems.get(slotIndex), recipeId);
|
||||
GuiRecipe<?> gui = GuiCraftingRecipe.createRecipeGui(
|
||||
"recipeId",
|
||||
false,
|
||||
this.recipeTooltipRenderer.stack,
|
||||
this.recipeTooltipRenderer.recipeId);
|
||||
|
||||
if (gui != null) {
|
||||
gui.initGui();
|
||||
@@ -1285,12 +1327,21 @@ public class BookmarkPanel extends PanelWidget {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int getHoveredGroupId() {
|
||||
public int getHoveredGroupId(boolean groupPanel) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
final int overRowIndex = BGrid.getHoveredRowIndex(true);
|
||||
final int overRowIndex = BGrid.getHoveredRowIndex(groupPanel);
|
||||
return overRowIndex >= 0 ? BGrid.getRowGroupId(overRowIndex) : -1;
|
||||
}
|
||||
|
||||
public void removeGroup(int groupId) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
|
||||
if (groupId >= 0 || groupId < BGrid.groups.size()) {
|
||||
BGrid.removeGroup(groupId);
|
||||
saveBookmarks();
|
||||
}
|
||||
}
|
||||
|
||||
protected String getNamespaceLabelText(boolean shortFormat) {
|
||||
String activePage = String.valueOf(activeNamespaceIndex + 1);
|
||||
|
||||
@@ -1951,39 +2002,13 @@ public class BookmarkPanel extends PanelWidget {
|
||||
return super.handleTooltip(mx, my, tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleKeyPress(int keyID, char keyChar) {
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items")) {
|
||||
return this.pullBookmarkItems(this.getHoveredGroupId(), false);
|
||||
}
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items_ingredients")) {
|
||||
return this.pullBookmarkItems(this.getHoveredGroupId(), true);
|
||||
}
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
final int overRowIndex = BGrid.getHoveredRowIndex(true);
|
||||
|
||||
if (overRowIndex >= 0) {
|
||||
BGrid.removeGroup(BGrid.getRowGroupId(overRowIndex));
|
||||
saveBookmarks();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.handleKeyPress(keyID, keyChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int mousex, int mousey, int button) {
|
||||
|
||||
if (this.sortableItem != null) {
|
||||
this.sortableItem = null;
|
||||
this.mouseDownSlot = -1;
|
||||
grid.onGridChanged(); /* make sure grid redraws the new item */
|
||||
grid.onItemsChanged(); /* make sure grid redraws the new item */
|
||||
saveBookmarks();
|
||||
} else if (this.groupingItem != null) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
@@ -2005,6 +2030,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
this.mouseDownSlot = -1;
|
||||
this.groupingItem = null;
|
||||
grid.onItemsChanged(); /* make sure grid redraws the new item */
|
||||
saveBookmarks();
|
||||
} else {
|
||||
super.mouseUp(mousex, mousey, button);
|
||||
@@ -2092,7 +2118,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
* meta.factor;
|
||||
|
||||
if (count <= Integer.MAX_VALUE) {
|
||||
return StackInfo.loadFromNBT(nbTag, Math.max((int) count, 0));
|
||||
return StackInfo.loadFromNBT(nbTag, Math.max(count, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2109,12 +2135,10 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
final ArrayList<ItemStack> items = new ArrayList<>();
|
||||
final ItemStackMap<Integer> uniqueItems = new ItemStackMap<>();
|
||||
final ItemStackMap<Long> uniqueItems = new ItemStackMap<>();
|
||||
final BookmarkGroup group = groupId >= 0 ? BGrid.groups.get(groupId) : null;
|
||||
ItemStackMetadata meta;
|
||||
|
||||
System.out.println("onlyIngredients: " + onlyIngredients);
|
||||
|
||||
for (int idx = 0; idx < BGrid.realItems.size(); idx++) {
|
||||
meta = BGrid.metadata.get(idx);
|
||||
|
||||
@@ -2123,16 +2147,21 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|
||||
if (!onlyIngredients || meta.ingredient && (group == null || group.crafting == null
|
||||
|| group.crafting.inputs.containsKey(BGrid.realItems.get(idx)))) {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack);
|
||||
uniqueItems.put(stack, uniqueItems.getOrDefault(stack, 0) + nbTag.getInteger("Count"));
|
||||
uniqueItems.put(
|
||||
stack,
|
||||
uniqueItems.getOrDefault(stack, 0L) + StackInfo.itemStackToNBT(stack).getInteger("Count"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStackMap.Entry<Integer> entry : uniqueItems.entries()) {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(entry.key);
|
||||
items.add(StackInfo.loadFromNBT(nbTag, entry.value));
|
||||
for (ItemStackMap.Entry<Long> entry : uniqueItems.entries()) {
|
||||
if (entry.value > 0) {
|
||||
items.add(
|
||||
StackInfo.loadFromNBT(
|
||||
StackInfo.itemStackToNBT(entry.key),
|
||||
Math.min(entry.value, 9 * 4 * entry.key.getMaxStackSize())));
|
||||
}
|
||||
}
|
||||
|
||||
if (items.isEmpty()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -84,20 +85,18 @@ public class ItemList {
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
public AllMultiItemFilter() {
|
||||
this(new LinkedList<>());
|
||||
public AllMultiItemFilter(ItemFilter... filters) {
|
||||
this(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
public AllMultiItemFilter(ItemFilter a, ItemFilter b) {
|
||||
this.filters = new ArrayList<>();
|
||||
this.filters.add(a);
|
||||
this.filters.add(b);
|
||||
public AllMultiItemFilter() {
|
||||
this(new LinkedList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack item) {
|
||||
for (ItemFilter filter : filters) try {
|
||||
if (!filter.matches(item)) return false;
|
||||
if (filter != null && !filter.matches(item)) return false;
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Exception filtering " + item + " with " + filter, e);
|
||||
}
|
||||
|
||||
@@ -432,8 +432,13 @@ public class NEIClientConfig {
|
||||
}
|
||||
|
||||
public static void unloadWorld() {
|
||||
ItemPanels.bookmarkPanel.saveBookmarks();
|
||||
world.saveNBT();
|
||||
if (ItemPanels.bookmarkPanel != null) {
|
||||
ItemPanels.bookmarkPanel.saveBookmarks();
|
||||
}
|
||||
|
||||
if (world != null) {
|
||||
world.saveNBT();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getKeyBinding(String string) {
|
||||
|
||||
@@ -1,54 +1,14 @@
|
||||
package codechicken.nei.api;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
|
||||
public interface IRecipeFilter {
|
||||
|
||||
public static interface IRecipeFilterProvider {
|
||||
|
||||
static HashMap<String, Boolean> override = new HashMap<>();
|
||||
|
||||
static boolean filteringAvailable(IRecipeHandler handler) {
|
||||
return handler instanceof TemplateRecipeHandler && !overrideMethod(handler.getClass().getName());
|
||||
}
|
||||
|
||||
static boolean overrideMethod(String className) {
|
||||
try {
|
||||
|
||||
if (override.containsKey(className)) {
|
||||
return override.get(className);
|
||||
}
|
||||
|
||||
String[] methods = new String[] { "getResultStack", "getOtherStacks", "getIngredientStacks" };
|
||||
Class<?> cls = Class.forName(className);
|
||||
|
||||
for (String method : methods) {
|
||||
Method m = cls.getMethod(method, Integer.TYPE);
|
||||
if (!m.getDeclaringClass().getName().equals("codechicken.nei.recipe.TemplateRecipeHandler")) {
|
||||
override.put(className, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Method m = cls.getMethod("numRecipes");
|
||||
if (!m.getDeclaringClass().getName().equals("codechicken.nei.recipe.TemplateRecipeHandler")) {
|
||||
override.put(className, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
override.put(className, false);
|
||||
return false;
|
||||
} catch (Throwable e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public IRecipeFilter getFilter();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,23 @@ public abstract class ShortcutInputHandler {
|
||||
return hideOverlayRecipe();
|
||||
}
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items")) {
|
||||
return ItemPanels.bookmarkPanel.pullBookmarkItems(ItemPanels.bookmarkPanel.getHoveredGroupId(true), false);
|
||||
}
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items_ingredients")) {
|
||||
return ItemPanels.bookmarkPanel.pullBookmarkItems(ItemPanels.bookmarkPanel.getHoveredGroupId(true), true);
|
||||
}
|
||||
|
||||
if (stackover == null && NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
|
||||
final int groupId = ItemPanels.bookmarkPanel.getHoveredGroupId(true);
|
||||
|
||||
if (groupId != -1) {
|
||||
ItemPanels.bookmarkPanel.removeGroup(groupId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (stackover == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.fontRenderer;
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
@@ -14,7 +13,6 @@ import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -31,6 +29,7 @@ import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.Button;
|
||||
import codechicken.nei.GuiNEIButton;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEICPH;
|
||||
@@ -112,7 +111,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
private final Rectangle area = new Rectangle();
|
||||
private final GuiRecipeTabs recipeTabs;
|
||||
private final GuiRecipeCatalyst guiRecipeCatalyst;
|
||||
private H handler;
|
||||
private SearchRecipeHandler<H> handler;
|
||||
private HandlerInfo handlerInfo;
|
||||
|
||||
private int yShift = 0;
|
||||
@@ -175,10 +174,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
public AllMultiRecipeFilter(IRecipeFilter a, IRecipeFilter b) {
|
||||
this.filters = new ArrayList<>();
|
||||
this.filters.add(a);
|
||||
this.filters.add(b);
|
||||
public AllMultiRecipeFilter(IRecipeFilter filters) {
|
||||
this(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
public AllMultiRecipeFilter() {
|
||||
@@ -207,22 +204,24 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
if (currentScreen instanceof GuiRecipe) {
|
||||
final GuiRecipe<?> guiRecipe = (GuiRecipe<?>) currentScreen;
|
||||
final IRecipeHandler handler = guiRecipe.handler;
|
||||
final SearchRecipeHandler<?> searchHandler = guiRecipe.handler;
|
||||
|
||||
if (handler != null && IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
if (searchHandler != null && searchHandler.searchingAvailable()) {
|
||||
|
||||
if (GuiRecipe.searchField.text().isEmpty()) {
|
||||
guiRecipe.updateRecipeList(handler, null);
|
||||
searchHandler.setSearchIndices(null);
|
||||
guiRecipe.changePage(0);
|
||||
} else {
|
||||
final IRecipeFilter filter = new ItemRecipeFilter(GuiRecipe.searchField.getFilter());
|
||||
ArrayList<Integer> filtered = ((TemplateRecipeHandler) handler).getSearchResult(filter);
|
||||
ArrayList<Integer> filtered = searchHandler.getSearchResult(filter);
|
||||
|
||||
if (filtered == null) {
|
||||
stop();
|
||||
}
|
||||
|
||||
if (interrupted()) return;
|
||||
guiRecipe.updateRecipeList(handler, filtered);
|
||||
searchHandler.setSearchIndices(filtered);
|
||||
guiRecipe.changePage(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -233,12 +232,12 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
};
|
||||
|
||||
public static final RecipeSearchField searchField = new RecipeSearchField("") {
|
||||
protected static final RecipeSearchField searchField = new RecipeSearchField("") {
|
||||
|
||||
@Override
|
||||
protected boolean noResults() {
|
||||
GuiScreen currentScreen = NEIClientUtils.mc().currentScreen;
|
||||
return !(currentScreen instanceof GuiRecipe) || ((GuiRecipe<?>) currentScreen).handler.numRecipes() > 0;
|
||||
return !(currentScreen instanceof GuiRecipe) || ((GuiRecipe<?>) currentScreen).numRecipes() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -248,6 +247,28 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
};
|
||||
|
||||
protected static final Button toggleSearch = new Button() {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (rightclick) return false;
|
||||
|
||||
if (searchField.isVisible()) {
|
||||
searchField.setText("");
|
||||
searchField.setFocus(false);
|
||||
searchField.setVisible(false);
|
||||
state = 0;
|
||||
} else {
|
||||
searchField.setVisible(true);
|
||||
searchField.setFocus(true);
|
||||
state = 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* This will only be true iff height hacking has been configured for the current recipe handler AND we are currently
|
||||
* within the scope of an active {@link CompatibilityHacks} instance.
|
||||
@@ -310,7 +331,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
trueGuiTop = guiTop;
|
||||
|
||||
isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream()
|
||||
.map(pattern -> pattern.matcher(handler.getHandlerId())).anyMatch(Matcher::matches);
|
||||
.map(pattern -> pattern.matcher(handler.original.getHandlerId())).anyMatch(Matcher::matches);
|
||||
if (isHeightHackApplied) {
|
||||
// guiTop is the top edge of the recipe screen on the y-axis. Old recipe handlers expect a single paging
|
||||
// widget at the top and at the bottom of the recipe screen with a height of 16px each, but GTNH NEI
|
||||
@@ -395,6 +416,9 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<");
|
||||
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">");
|
||||
|
||||
toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 38, 8, 8).setTextureSize(128, 128)
|
||||
.build();
|
||||
|
||||
buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage));
|
||||
|
||||
if (currenthandlers.size() == 1) {
|
||||
@@ -437,34 +461,23 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
itemPresenceCacheRecipe = -1;
|
||||
}
|
||||
|
||||
public static IRecipeFilter getRecipeListFilter(IRecipeHandler handler) {
|
||||
if (IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
LinkedList<IRecipeFilter> filters = new LinkedList<>();
|
||||
public static IRecipeFilter getRecipeListFilter() {
|
||||
if (recipeFilterers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (recipeFilterers) {
|
||||
for (IRecipeFilterProvider p : recipeFilterers) {
|
||||
IRecipeFilter filter = p.getFilter();
|
||||
if (filter != null) {
|
||||
filters.add(filter);
|
||||
}
|
||||
final AllMultiRecipeFilter recipeFilter = new AllMultiRecipeFilter();
|
||||
|
||||
synchronized (recipeFilterers) {
|
||||
for (IRecipeFilterProvider p : recipeFilterers) {
|
||||
IRecipeFilter filter = p.getFilter();
|
||||
if (filter != null) {
|
||||
recipeFilter.filters.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!filters.isEmpty()) {
|
||||
return filters.size() == 1 ? filters.get(0) : new AllMultiRecipeFilter(filters);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void updateRecipeList(IRecipeHandler h, ArrayList<Integer> filtered) {
|
||||
synchronized (handler) {
|
||||
if (handler != null && handler == h && IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
((TemplateRecipeHandler) handler).applySearch(filtered);
|
||||
changePage(0);
|
||||
}
|
||||
}
|
||||
return recipeFilter.filters.size() == 1 ? recipeFilter.filters.get(0) : recipeFilter;
|
||||
}
|
||||
|
||||
private void checkYShift() {
|
||||
@@ -475,18 +488,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
setRecipePage(idx, 0);
|
||||
}
|
||||
|
||||
public void setRecipePage(int idx, int recipe) {
|
||||
public void setRecipePage(int idx, int refIndex) {
|
||||
recipetype = (currenthandlers.size() + idx) % currenthandlers.size();
|
||||
|
||||
handler = currenthandlers.get(recipetype);
|
||||
handlerInfo = GuiRecipeTab.getHandlerInfo(handler);
|
||||
handler = new SearchRecipeHandler<>(currenthandlers.get(recipetype));
|
||||
handlerInfo = GuiRecipeTab.getHandlerInfo(handler.original);
|
||||
|
||||
if (!limitToOneRecipe) {
|
||||
searchField.setText("");
|
||||
searchField.setVisible(false);
|
||||
toggleSearch.state = 0;
|
||||
}
|
||||
|
||||
page = Math.min(Math.max(0, recipe), handler.numRecipes() - 1) / getRecipesPerPage();
|
||||
page = Math.min(Math.max(0, refIndex), this.numRecipes() - 1) / getRecipesPerPage();
|
||||
changePage(0);
|
||||
recipeTabs.calcPageNumber();
|
||||
checkYShift();
|
||||
@@ -498,26 +512,24 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
|
||||
public int openTargetRecipe(BookmarkRecipeId recipeId) {
|
||||
int recipe = -1;
|
||||
int refIndex = -1;
|
||||
int recipetype = 0;
|
||||
|
||||
this.recipeId = recipeId;
|
||||
|
||||
if (this.recipeId != null) {
|
||||
for (int j = 0; j < currenthandlers.size(); j++) {
|
||||
IRecipeHandler localHandler = currenthandlers.get(j);
|
||||
H localHandler = currenthandlers.get(j);
|
||||
HandlerInfo localHandlerInfo = GuiRecipeTab.getHandlerInfo(localHandler);
|
||||
|
||||
if (localHandlerInfo.getHandlerName().equals(this.recipeId.handlerName)) {
|
||||
recipetype = j;
|
||||
|
||||
if (!this.recipeId.ingredients.isEmpty()) {
|
||||
for (int i = 0; i < localHandler.numRecipes(); i++) {
|
||||
if (this.recipeId.equalsIngredients(localHandler.getIngredientStacks(i))) {
|
||||
recipetype = j;
|
||||
recipe = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
refIndex = SearchRecipeHandler.findFirst(
|
||||
localHandler,
|
||||
(recipeIndex) -> this.recipeId
|
||||
.equalsIngredients(localHandler.getIngredientStacks(recipeIndex)));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -525,16 +537,16 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
}
|
||||
|
||||
setRecipePage(recipetype, Math.max(0, recipe));
|
||||
setRecipePage(recipetype, Math.max(0, refIndex));
|
||||
|
||||
return recipe;
|
||||
return refIndex;
|
||||
}
|
||||
|
||||
public List<PositionedStack> getFocusedRecipeIngredients() {
|
||||
|
||||
for (int idx : getRecipeIndices()) {
|
||||
if (recipeInFocus(idx)) {
|
||||
return handler.getIngredientStacks(idx);
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (recipeInFocus(recipeIndex)) {
|
||||
return handler.original.getIngredientStacks(recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,16 +555,16 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
public int prepareFocusedRecipeResultStackSize(ItemStack stackover) {
|
||||
|
||||
for (int idx : getRecipeIndices()) {
|
||||
if (recipeInFocus(idx)) {
|
||||
final PositionedStack result = handler.getResultStack(idx);
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (recipeInFocus(recipeIndex)) {
|
||||
final PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
int stackSize = 0;
|
||||
|
||||
if (result != null && StackInfo.equalItemAndNBT(result.item, stackover, true)) {
|
||||
stackSize += result.item.stackSize;
|
||||
}
|
||||
|
||||
final List<PositionedStack> stacks = handler.getOtherStacks(idx);
|
||||
final List<PositionedStack> stacks = handler.original.getOtherStacks(recipeIndex);
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (StackInfo.equalItemAndNBT(pStack.item, stackover, true)) {
|
||||
stackSize += pStack.item.stackSize;
|
||||
@@ -566,15 +578,15 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return stackover.stackSize;
|
||||
}
|
||||
|
||||
protected boolean recipeInFocus(int idx) {
|
||||
final PositionedStack result = handler.getResultStack(idx);
|
||||
if (result != null && isMouseOver(result, idx)) {
|
||||
protected boolean recipeInFocus(int recipeIndex) {
|
||||
final PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
if (result != null && isMouseOver(result, recipeIndex)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final List<PositionedStack> stacks = handler.getOtherStacks(idx);
|
||||
final List<PositionedStack> stacks = handler.original.getOtherStacks(recipeIndex);
|
||||
for (PositionedStack stack : stacks) {
|
||||
if (isMouseOver(stack, idx)) {
|
||||
if (isMouseOver(stack, recipeIndex)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -587,15 +599,24 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
|
||||
public H getHandler() {
|
||||
return handler;
|
||||
return handler.original;
|
||||
}
|
||||
|
||||
public List<Integer> getRecipeIndices() {
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
int minIndex = page * recipesPerPage;
|
||||
int maxIndex = Math.min(handler.numRecipes(), (page + 1) * recipesPerPage);
|
||||
final int minIndex = page * recipesPerPage;
|
||||
final int maxIndex = Math.min(this.numRecipes(), (page + 1) * recipesPerPage);
|
||||
final ArrayList<Integer> range = new ArrayList<>();
|
||||
|
||||
return IntStream.range(minIndex, maxIndex).boxed().collect(Collectors.toList());
|
||||
for (int index = minIndex; index < maxIndex; index++) {
|
||||
range.add(handler.ref(index));
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
private int numRecipes() {
|
||||
return handler == null ? 0 : handler.numRecipes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -621,8 +642,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
for (int recipe : getRecipeIndices()) {
|
||||
if (handler.keyTyped(this, c, i, recipe)) {
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (handler.original.keyTyped(this, c, i, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -647,33 +668,33 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
protected void mouseClicked(int mousex, int mousey, int button) {
|
||||
|
||||
if (!limitToOneRecipe && handler != null && IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
if (new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
|
||||
.contains(mousex - guiLeft, mousey - guiTop)) {
|
||||
searchField.setVisible(true);
|
||||
if (!limitToOneRecipe && handler != null && handler.searchingAvailable()) {
|
||||
if (toggleSearch.contains(mousex - guiLeft, mousey - guiTop)) {
|
||||
toggleSearch.handleClick(mousex - guiLeft, mousey - guiTop, button);
|
||||
} else if (searchField.contains(mousex - guiLeft, mousey - guiTop)) {
|
||||
searchField.handleClick(mousex - guiLeft, mousey - guiTop, button);
|
||||
if (!searchField.focused()) {
|
||||
searchField.setFocus(true);
|
||||
}
|
||||
} else {
|
||||
searchField.onGuiClick(mousex - guiLeft, mousey - guiTop);
|
||||
if (searchField.text().isEmpty() && !searchField.focused()) {
|
||||
searchField.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
for (int recipe : getRecipeIndices()) if (handler.mouseClicked(this, button, recipe)) return;
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (handler.original.mouseClicked(this, button, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recipeTabs.mouseClicked(mousex, mousey, button)) return;
|
||||
if (recipeTabs.mouseClicked(mousex, mousey, button)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseClicked(mousex, mousey, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseScrolled(int i) {
|
||||
public void mouseScrolled(int scroll) {
|
||||
// Height hacking is not necessary here since mouse scrolling is a new feature, added in
|
||||
// GTNH NEI. So no old mods will use this. Though not hacking the height here does mean that
|
||||
// the value of the height field will be different from in other mouseover methods, which
|
||||
@@ -681,14 +702,18 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
// First, invoke scroll handling over recipe handler tabbar. Makes sure it is not overwritten by recipe
|
||||
// handler-specific scroll behavior.
|
||||
if (recipeTabs.mouseScrolled(i)) return;
|
||||
if (recipeTabs.mouseScrolled(scroll)) return;
|
||||
|
||||
for (int recipe : getRecipeIndices()) if (handler.mouseScrolled(this, i, recipe)) return;
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (handler.original.mouseScrolled(this, scroll, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If shift is held, try switching to the next recipe handler. Replicates the GuiRecipeTabs.mouseScrolled()
|
||||
// without the checking for the cursor being inside the tabbar.
|
||||
if (NEIClientUtils.shiftKey()) {
|
||||
if (i < 0) {
|
||||
if (scroll < 0) {
|
||||
nextType();
|
||||
} else {
|
||||
prevType();
|
||||
@@ -699,7 +724,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
// Finally, if nothing else has handled scrolling, try changing to the next recipe page.
|
||||
if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) {
|
||||
if (i > 0) {
|
||||
if (scroll > 0) {
|
||||
prevPage();
|
||||
} else {
|
||||
nextPage();
|
||||
@@ -727,10 +752,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
if (overlayButtons != null && guibutton.id >= OVERLAY_BUTTON_ID_START
|
||||
&& guibutton.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) {
|
||||
mc.displayGuiScreen(firstGui);
|
||||
overlayRecipe(
|
||||
page * getRecipesPerPage() + guibutton.id - OVERLAY_BUTTON_ID_START,
|
||||
NEIClientUtils.shiftKey());
|
||||
final List<Integer> indices = getRecipeIndices();
|
||||
final int refIndex = guibutton.id - OVERLAY_BUTTON_ID_START;
|
||||
|
||||
if (refIndex >= 0 && refIndex < indices.size()) {
|
||||
mc.displayGuiScreen(firstGui);
|
||||
overlayRecipe(indices.get(refIndex), NEIClientUtils.shiftKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,25 +770,30 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
/** updateScreen() that's safe to call when this isn't the currently open GUI */
|
||||
public void updateAsTooltip() {
|
||||
handler.onUpdate();
|
||||
handler.original.onUpdate();
|
||||
refreshPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
|
||||
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
for (int i : getRecipeIndices()) currenttip = handler.handleTooltip(this, currenttip, i);
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
currenttip = handler.original.handleTooltip(this, currenttip, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
recipeTabs.handleTooltip(mousex, mousey, currenttip);
|
||||
|
||||
if (currenttip.isEmpty()
|
||||
&& new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
|
||||
if (currenttip.isEmpty() && searchField.isVisible()
|
||||
&& new Rectangle(searchField.x + searchField.w, 15, 44, 16)
|
||||
.contains(mousex - guiLeft, mousey - guiTop)) {
|
||||
|
||||
if (!searchField.isVisible() && IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
currenttip.add(translate("recipe.search.show"));
|
||||
}
|
||||
final String s = String.format("%d/%d", page + 1, (this.numRecipes() - 1) / getRecipesPerPage() + 1);
|
||||
|
||||
if (fontRendererObj.getStringWidth(s) >= 45) {
|
||||
currenttip.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
@@ -769,8 +802,11 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack stack, int mousex, int mousey,
|
||||
List<String> currenttip) {
|
||||
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
for (int i : getRecipeIndices()) currenttip = handler.handleItemTooltip(this, stack, currenttip, i);
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
currenttip = handler.original.handleItemTooltip(this, stack, currenttip, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
@@ -797,19 +833,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
setRecipePage(--recipetype);
|
||||
}
|
||||
|
||||
protected void overlayRecipe(int recipe, final boolean shift) {
|
||||
protected void overlayRecipe(int recipeIndex, final boolean shift) {
|
||||
|
||||
if (handler == null || !handler.hasOverlay(firstGui, firstGui.inventorySlots, recipe)) {
|
||||
if (handler == null || !handler.original.hasOverlay(firstGui, firstGui.inventorySlots, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean moveItems = shift || !NEIClientConfig.requireShiftForOverlayRecipe();
|
||||
final IRecipeOverlayRenderer renderer = handler.getOverlayRenderer(firstGui, recipe);
|
||||
final IOverlayHandler overlayHandler = handler.getOverlayHandler(firstGui, recipe);
|
||||
final IRecipeOverlayRenderer renderer = handler.original.getOverlayRenderer(firstGui, recipeIndex);
|
||||
final IOverlayHandler overlayHandler = handler.original.getOverlayHandler(firstGui, recipeIndex);
|
||||
|
||||
if (renderer == null || moveItems) {
|
||||
if (overlayHandler != null) {
|
||||
overlayHandler.overlayRecipe(firstGui, handler, recipe, moveItems);
|
||||
overlayHandler.overlayRecipe(firstGui, handler.original, recipeIndex, moveItems);
|
||||
}
|
||||
} else {
|
||||
LayoutManager.overlayRenderer = renderer;
|
||||
@@ -818,7 +854,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
protected void changePage(int shift) {
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
final int numRecipes = handler != null ? handler.numRecipes() : 0;
|
||||
final int numRecipes = this.numRecipes();
|
||||
|
||||
if (numRecipes > 0) {
|
||||
final int numPages = (int) Math.ceil(numRecipes / (float) recipesPerPage);
|
||||
@@ -835,8 +871,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
changePage(0);
|
||||
refreshSlots();
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
final boolean multiplepages = handler.numRecipes() > recipesPerPage;
|
||||
final int numRecipes = Math.min(handler.numRecipes() - (page * recipesPerPage), recipesPerPage);
|
||||
final boolean multiplepages = this.numRecipes() > recipesPerPage;
|
||||
final int numRecipes = Math.min(this.numRecipes() - (page * recipesPerPage), recipesPerPage);
|
||||
|
||||
area.width = handlerInfo.getWidth();
|
||||
area.height = handlerInfo.getHeight() * numRecipes;
|
||||
@@ -845,9 +881,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
checkYShift();
|
||||
|
||||
if (!limitToOneRecipe) {
|
||||
toggleSearch.w = toggleSearch.h = 12;
|
||||
toggleSearch.x = borderPadding + buttonWidth;
|
||||
toggleSearch.y = 17;
|
||||
|
||||
searchField.y = 16;
|
||||
searchField.x = borderPadding + buttonWidth - 2;
|
||||
searchField.w = xSize - (borderPadding + buttonWidth) * 2 + 1 - 45;
|
||||
searchField.x = borderPadding + buttonWidth + toggleSearch.w - 1;
|
||||
searchField.w = xSize - (borderPadding + buttonWidth) * 2 + 1 - toggleSearch.w - 45;
|
||||
searchField.h = 14;
|
||||
}
|
||||
|
||||
@@ -858,12 +898,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
overlay.visible = false;
|
||||
}
|
||||
} else {
|
||||
final List<Integer> indices = getRecipeIndices();
|
||||
for (int i = 0; i < overlayButtons.length; i++) {
|
||||
if (i >= numRecipes) {
|
||||
if (i >= indices.size()) {
|
||||
overlayButtons[i].visible = false;
|
||||
} else {
|
||||
final int curRecipe = page * recipesPerPage + i;
|
||||
overlayButtons[i].visible = handler.hasOverlay(firstGui, firstGui.inventorySlots, curRecipe);
|
||||
overlayButtons[i].visible = handler.original
|
||||
.hasOverlay(firstGui, firstGui.inventorySlots, indices.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -873,8 +914,11 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
private void refreshSlots() {
|
||||
slotcontainer.inventorySlots.clear();
|
||||
for (int i : getRecipeIndices()) {
|
||||
Point p = getRecipePosition(i);
|
||||
final List<Integer> indices = getRecipeIndices();
|
||||
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
int recipeIndex = indices.get(refIndex);
|
||||
Point p = getRecipePosition(refIndex);
|
||||
// Legacy recipe handlers only expect a single paging widget at the top of the recipe screen, in contrast,
|
||||
// GTNH NEI moves the recipe paging widget from the bottom to the top, which means said legacy handlers will
|
||||
// position item slots 16px too high in the screen.
|
||||
@@ -882,36 +926,40 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
p.translate(0, 16);
|
||||
}
|
||||
|
||||
List<PositionedStack> stacks = handler.getIngredientStacks(i);
|
||||
TemplateRecipeHandler.disableCycledIngredients = false;
|
||||
|
||||
List<PositionedStack> stacks = handler.original.getIngredientStacks(recipeIndex);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
|
||||
stacks = handler.getOtherStacks(i);
|
||||
stacks = handler.original.getOtherStacks(recipeIndex);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
|
||||
PositionedStack result = handler.getResultStack(i);
|
||||
PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
if (result != null) slotcontainer.addSlot(result, p.x, p.y);
|
||||
|
||||
if (!limitToOneRecipe) {
|
||||
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler);
|
||||
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler.original);
|
||||
for (PositionedStack catalyst : catalysts) {
|
||||
int xOffset = -GuiRecipeCatalyst.ingredientSize + 1;
|
||||
int yOffset = BG_TOP_Y + GuiRecipeCatalyst.fullBorder;
|
||||
slotcontainer.addSlot(catalyst, xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
TemplateRecipeHandler.disableCycledIngredients = true;
|
||||
}
|
||||
}
|
||||
|
||||
private int itemPresenceCacheRecipe = -1;
|
||||
private ArrayList<Boolean> itemPresenceCacheSlots;
|
||||
|
||||
private void updateItemPresenceCache(int recipe) {
|
||||
private void updateItemPresenceCache(int recipeIndex) {
|
||||
if (itemPresenceCacheSlots == null) {
|
||||
itemPresenceCacheSlots = new ArrayList<>();
|
||||
}
|
||||
itemPresenceCacheRecipe = recipe;
|
||||
itemPresenceCacheRecipe = recipeIndex;
|
||||
itemPresenceCacheSlots.clear();
|
||||
List<PositionedStack> ingredients = handler.getIngredientStacks(recipe);
|
||||
List<PositionedStack> ingredients = handler.original.getIngredientStacks(recipeIndex);
|
||||
ArrayList<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots).stream()
|
||||
.filter(
|
||||
s -> s != null && s.getStack() != null
|
||||
@@ -937,14 +985,18 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
final int ySkip = limitToOneRecipe ? 25 : 0;
|
||||
|
||||
if (!limitToOneRecipe) {
|
||||
String s = handler.getRecipeName().trim();
|
||||
String s = handler.original.getRecipeName().trim();
|
||||
fontRendererObj.drawStringWithShadow(s, (xSize - fontRendererObj.getStringWidth(s)) / 2, 5, 0xffffff);
|
||||
|
||||
if (!limitToOneRecipe && searchField.isVisible()) {
|
||||
if (handler.searchingAvailable()) {
|
||||
toggleSearch.draw(mouseX - guiLeft, mouseY - guiTop);
|
||||
}
|
||||
|
||||
if (searchField.isVisible()) {
|
||||
searchField.draw(mouseX - guiLeft, mouseY - guiTop);
|
||||
s = NEIClientUtils.cropText(
|
||||
fontRendererObj,
|
||||
String.format("%d/%d", page + 1, (handler.numRecipes() - 1) / recipesPerPage + 1),
|
||||
String.format("%d/%d", page + 1, (this.numRecipes() - 1) / recipesPerPage + 1),
|
||||
45);
|
||||
fontRendererObj.drawStringWithShadow(
|
||||
s,
|
||||
@@ -952,7 +1004,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
19,
|
||||
0xffffff);
|
||||
} else {
|
||||
s = NEIClientUtils.translate("recipe.page", page + 1, (handler.numRecipes() - 1) / recipesPerPage + 1);
|
||||
s = NEIClientUtils.translate("recipe.page", page + 1, (this.numRecipes() - 1) / recipesPerPage + 1);
|
||||
fontRendererObj.drawStringWithShadow(s, (xSize - fontRendererObj.getStringWidth(s)) / 2, 19, 0xffffff);
|
||||
}
|
||||
|
||||
@@ -963,18 +1015,24 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(5, 32 - ySkip + yShift, 0);
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
List<Integer> indices = getRecipeIndices();
|
||||
|
||||
for (int i : getRecipeIndices()) {
|
||||
handler.drawForeground(i);
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
int recipeIndex = indices.get(refIndex);
|
||||
|
||||
handler.original.drawForeground(recipeIndex);
|
||||
|
||||
if (drawItemPresence && firstGui != null
|
||||
&& firstGui.inventorySlots != null
|
||||
&& (isMouseOverOverlayButton(i - page * recipesPerPage) || limitToOneRecipe)) {
|
||||
List<PositionedStack> ingredients = handler.getIngredientStacks(i);
|
||||
if (itemPresenceCacheRecipe != i || itemPresenceCacheSlots == null
|
||||
&& (isMouseOverOverlayButton(refIndex) || limitToOneRecipe)) {
|
||||
|
||||
List<PositionedStack> ingredients = handler.original.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (itemPresenceCacheRecipe != recipeIndex || itemPresenceCacheSlots == null
|
||||
|| itemPresenceCacheSlots.size() != ingredients.size()) {
|
||||
updateItemPresenceCache(i);
|
||||
updateItemPresenceCache(recipeIndex);
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredients.size(); j++) {
|
||||
PositionedStack stack = ingredients.get(j);
|
||||
boolean isPresent = itemPresenceCacheSlots.get(j);
|
||||
@@ -986,6 +1044,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -1023,8 +1082,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
GL11.glTranslatef(guiLeft + 5, guiTop - ySkip + 32 + yShift, 0);
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
|
||||
for (int i : getRecipeIndices()) {
|
||||
handler.drawBackground(i);
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
handler.original.drawBackground(recipeIndex);
|
||||
GL11.glTranslatef(0, handlerInfo.getHeight(), 0);
|
||||
}
|
||||
|
||||
@@ -1073,10 +1132,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return firstGuiGeneral;
|
||||
}
|
||||
|
||||
public boolean isMouseOver(PositionedStack stack, int recipe) {
|
||||
Slot stackSlot = slotcontainer
|
||||
.getSlotWithStack(stack, getRecipePosition(recipe).x, getRecipePosition(recipe).y);
|
||||
public boolean isMouseOver(PositionedStack stack, int refIndex) {
|
||||
Point p = getRecipePosition(refIndex);
|
||||
Point mousepos = GuiDraw.getMousePosition();
|
||||
Slot stackSlot = slotcontainer.getSlotWithStack(stack, p.x, p.y);
|
||||
Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);
|
||||
|
||||
return stackSlot == mouseoverSlot;
|
||||
@@ -1107,12 +1166,12 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
handlerInfo.getMaxRecipesPerPage()),
|
||||
1);
|
||||
} else if (handler != null) {
|
||||
return handler.recipiesPerPage();
|
||||
return handler.original.recipiesPerPage();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Point getRecipePosition(int recipe) {
|
||||
public Point getRecipePosition(int refIndex) {
|
||||
// Legacy recipe handlers using the height hack might use getRecipePosition in combination with guiTop/height to
|
||||
// position certain elements like tooltips. Since guiTop is moved down by 16px during height hacking, we need to
|
||||
// reduce the vertical shift here to 16px instead of 32px.
|
||||
@@ -1120,7 +1179,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
5,
|
||||
(isHeightHackApplied ? 16 : 32) - (limitToOneRecipe ? 25 : 0)
|
||||
+ yShift
|
||||
+ ((recipe % getRecipesPerPage()) * handlerInfo.getHeight()));
|
||||
+ ((refIndex % getRecipesPerPage()) * handlerInfo.getHeight()));
|
||||
}
|
||||
|
||||
public abstract ArrayList<H> getCurrentRecipeHandlers();
|
||||
@@ -1143,10 +1202,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
|
||||
|
||||
if (!limitToOneRecipe && handler != null
|
||||
&& new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
|
||||
.contains(mousex - guiLeft, mousey - guiTop)
|
||||
&& IRecipeFilterProvider.filteringAvailable(handler)) {
|
||||
if (searchField.isVisible() && searchField.contains(mousex - guiLeft, mousey - guiTop)) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(draggedStack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
@@ -1155,7 +1211,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
searchField.setText(formattingText(draggedStack.getDisplayName()));
|
||||
}
|
||||
|
||||
searchField.setVisible(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1175,11 +1230,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
protected static BookmarkRecipeId getCurrentRecipe(GuiScreen gui) {
|
||||
|
||||
if (gui instanceof GuiRecipe && !((GuiRecipe<?>) gui).handler.isEmpty()) {
|
||||
GuiRecipe<?> gRecipe = (GuiRecipe<?>) gui;
|
||||
if (gui instanceof GuiRecipe && ((GuiRecipe<?>) gui).handler.numRecipes() > 0) {
|
||||
final GuiRecipe<?> gRecipe = (GuiRecipe<?>) gui;
|
||||
final List<Integer> indices = gRecipe.getRecipeIndices();
|
||||
final int curRecipe = indices.isEmpty() ? 0 : indices.get(0);
|
||||
|
||||
return new BookmarkRecipeId(
|
||||
gRecipe.handlerInfo.getHandlerName(),
|
||||
gRecipe.handler.getIngredientStacks(gRecipe.page * gRecipe.getRecipesPerPage()));
|
||||
gRecipe.handler.original.getIngredientStacks(curRecipe));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -50,14 +50,6 @@ public interface IRecipeHandler {
|
||||
*/
|
||||
int numRecipes();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <tt>true</tt> if this list contains no elements
|
||||
*/
|
||||
default boolean isEmpty() {
|
||||
return numRecipes() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the background of this recipe handler (basically the slot layout image).
|
||||
*
|
||||
|
||||
@@ -12,8 +12,6 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import codechicken.core.TaskProfiler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -36,7 +34,6 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
|
||||
ArrayList<T> runWithProfiling(String profilerSection) {
|
||||
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
|
||||
TemplateRecipeHandler.disableCycledIngredients = true;
|
||||
profiler.start(profilerSection);
|
||||
try {
|
||||
ArrayList<T> handlers = getRecipeHandlersParallel();
|
||||
@@ -50,7 +47,6 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
displayRecipeLookupError();
|
||||
return new ArrayList<>(0);
|
||||
} finally {
|
||||
TemplateRecipeHandler.disableCycledIngredients = false;
|
||||
profiler.end();
|
||||
}
|
||||
}
|
||||
@@ -74,7 +70,8 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
error = true;
|
||||
return null;
|
||||
}
|
||||
}).filter(h -> h != null && !h.isEmpty()).collect(Collectors.toCollection(ArrayList::new));
|
||||
}).filter(h -> h != null && h.numRecipes() > 0 && SearchRecipeHandler.findFirst(h, (recipeIndex) -> true) != -1)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
private ArrayList<T> getHandlersWithRecipes() throws InterruptedException, ExecutionException {
|
||||
@@ -87,12 +84,14 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
error = true;
|
||||
return null;
|
||||
}
|
||||
}).filter(h -> h != null && !h.isEmpty()).collect(Collectors.toCollection(ArrayList::new))).get();
|
||||
}).filter(h -> h != null && h.numRecipes() > 0 && SearchRecipeHandler.findFirst(h, (recipeIndex) -> true) != -1)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get();
|
||||
}
|
||||
|
||||
private boolean isHidden(T handler) {
|
||||
final String handlerId = Objects.firstNonNull(handler.getOverlayIdentifier(), handler.getHandlerId());
|
||||
return NEIClientConfig.hiddenHandlers.stream().anyMatch(h -> h.equals(handlerId));
|
||||
final String handlerName = handler.getHandlerId();
|
||||
final String handlerId = handler.getOverlayIdentifier();
|
||||
return NEIClientConfig.hiddenHandlers.stream().anyMatch(h -> h.equals(handlerId) || h.equals(handlerName));
|
||||
}
|
||||
|
||||
private void printLog(Throwable t) {
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
|
||||
class SearchRecipeHandler<H extends IRecipeHandler> {
|
||||
|
||||
public H original;
|
||||
|
||||
private ArrayList<Integer> filteredRecipes;
|
||||
|
||||
private ArrayList<Integer> searchRecipes;
|
||||
|
||||
public SearchRecipeHandler(H handler) {
|
||||
this.original = handler;
|
||||
|
||||
if (this.original.numRecipes() == 0) {
|
||||
this.filteredRecipes = new ArrayList<>();
|
||||
} else {
|
||||
final Stream<Integer> items = IntStream.range(0, this.original.numRecipes()).boxed();
|
||||
final IRecipeFilter filter = this.searchingAvailable() ? GuiRecipe.getRecipeListFilter() : null;
|
||||
|
||||
if (filter == null) {
|
||||
this.filteredRecipes = items.collect(Collectors.toCollection(ArrayList::new));
|
||||
} else {
|
||||
this.filteredRecipes = items.filter(recipe -> mathRecipe(this.original, recipe, filter))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean mathRecipe(IRecipeHandler handler, int recipe, IRecipeFilter filter) {
|
||||
return filter.matches(
|
||||
handler,
|
||||
handler.getIngredientStacks(recipe),
|
||||
handler.getResultStack(recipe),
|
||||
handler.getOtherStacks(recipe));
|
||||
}
|
||||
|
||||
public boolean searchingAvailable() {
|
||||
return SearchRecipeHandler.searchingAvailable(this.original);
|
||||
}
|
||||
|
||||
private static boolean searchingAvailable(IRecipeHandler handler) {
|
||||
return handler instanceof TemplateRecipeHandler;
|
||||
}
|
||||
|
||||
public static int findFirst(IRecipeHandler handler, Predicate<Integer> predicate) {
|
||||
final IRecipeFilter filter = searchingAvailable(handler) ? GuiRecipe.getRecipeListFilter() : null;
|
||||
int refIndex = -1;
|
||||
|
||||
for (int recipeIndex = 0; recipeIndex < handler.numRecipes(); recipeIndex++) {
|
||||
if (filter == null || mathRecipe(handler, recipeIndex, filter)) {
|
||||
refIndex++;
|
||||
|
||||
if (predicate.test(recipeIndex)) {
|
||||
return refIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getSearchResult(IRecipeFilter filter) {
|
||||
|
||||
if (filteredRecipes.isEmpty() || !this.searchingAvailable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<Integer> filtered = null;
|
||||
final ArrayList<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
try {
|
||||
filtered = ItemList.forkJoinPool.submit(
|
||||
() -> recipes.parallelStream()
|
||||
.filter(recipe -> mathRecipe(this.original, filteredRecipes.get(recipe), filter))
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get();
|
||||
|
||||
filtered.sort((a, b) -> a - b);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public void setSearchIndices(ArrayList<Integer> searchRecipes) {
|
||||
this.searchRecipes = searchRecipes;
|
||||
}
|
||||
|
||||
public int ref(int index) {
|
||||
|
||||
if (searchRecipes != null) {
|
||||
index = searchRecipes.get(index);
|
||||
}
|
||||
|
||||
return filteredRecipes.get(index);
|
||||
}
|
||||
|
||||
public int numRecipes() {
|
||||
|
||||
if (searchRecipes != null) {
|
||||
return searchRecipes.size();
|
||||
}
|
||||
|
||||
return filteredRecipes.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class StackInfo {
|
||||
|
||||
if (nbtTag != null) {
|
||||
nbtTag = (NBTTagCompound) nbtTag.copy();
|
||||
nbtTag.setInteger("Count", Math.max(customCount <= Integer.MAX_VALUE ? (int) customCount : 0, 0));
|
||||
nbtTag.setInteger("Count", (int) Math.max(Math.min(customCount, Integer.MAX_VALUE), 0));
|
||||
return loadFromNBT(nbtTag);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -37,16 +35,17 @@ import com.google.common.base.Stopwatch;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemList.AllMultiItemFilter;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
@@ -199,9 +198,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
protected void randomRenderPermutation(List<PositionedStack> stacks, long cycle) {
|
||||
final ItemFilter filter = new AllMultiItemFilter(
|
||||
ItemList.getItemListFilter(),
|
||||
GuiRecipe.searchField.getFilter());
|
||||
final ItemFilter filter = getItemFilter();
|
||||
final int randCycle = Math.abs(new Random(cycle + offset).nextInt());
|
||||
|
||||
for (PositionedStack stack : stacks) {
|
||||
@@ -217,9 +214,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
protected void jeiStyledRenderPermutation(List<PositionedStack> stacks, long cycle) {
|
||||
final ItemFilter filter = new AllMultiItemFilter(
|
||||
ItemList.getItemListFilter(),
|
||||
GuiRecipe.searchField.getFilter());
|
||||
final ItemFilter filter = getItemFilter();
|
||||
|
||||
for (PositionedStack stack : stacks) {
|
||||
if (stack.items.length <= 1) continue;
|
||||
@@ -428,17 +423,20 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
*/
|
||||
public LinkedList<RecipeTransferRect> transferRects = new LinkedList<>();
|
||||
|
||||
public static boolean disableCycledIngredients = false;
|
||||
|
||||
protected ArrayList<Integer> filteredRecipes;
|
||||
|
||||
protected ArrayList<Integer> searchRecipes;
|
||||
public static boolean disableCycledIngredients = true;
|
||||
|
||||
public TemplateRecipeHandler() {
|
||||
loadTransferRects();
|
||||
RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects);
|
||||
}
|
||||
|
||||
protected static ItemFilter getItemFilter() {
|
||||
return new AllMultiItemFilter(
|
||||
item -> !ItemInfo.hiddenItems.contains(item),
|
||||
LayoutManager.presetsPanel != null ? LayoutManager.presetsPanel.getFilter() : null,
|
||||
GuiRecipe.searchField != null ? GuiRecipe.searchField.getFilter() : null);
|
||||
}
|
||||
|
||||
protected static ArrayList<Integer> getFilteredIngredientAlternatives(PositionedStack stack, ItemFilter filter) {
|
||||
final ArrayList<Integer> filtered = new ArrayList<>();
|
||||
|
||||
@@ -591,7 +589,8 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
public TemplateRecipeHandler newInstance() {
|
||||
try {
|
||||
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads
|
||||
// Use the non parallel version since we might already be using the forkJoinPool
|
||||
// and might have no threads
|
||||
// available
|
||||
// This will ideally have been pre-cached elsewhere and will be a NOOP
|
||||
findFuelsOnce();
|
||||
@@ -644,129 +643,8 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
if (arecipes.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final IRecipeFilter filter = GuiRecipe.getRecipeListFilter(this);
|
||||
|
||||
if (filter == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final boolean disableCycledIngredients = TemplateRecipeHandler.disableCycledIngredients;
|
||||
TemplateRecipeHandler.disableCycledIngredients = true;
|
||||
|
||||
boolean isEmpty = !IntStream.range(0, arecipes.size()).boxed().anyMatch(
|
||||
recipe -> filter.matches(
|
||||
this,
|
||||
arecipes.get(recipe).getIngredients(),
|
||||
arecipes.get(recipe).getResult(),
|
||||
arecipes.get(recipe).getOtherStacks()));
|
||||
|
||||
TemplateRecipeHandler.disableCycledIngredients = disableCycledIngredients;
|
||||
|
||||
return isEmpty;
|
||||
}
|
||||
|
||||
protected synchronized void applyFilter() {
|
||||
|
||||
if (arecipes.isEmpty() && this.filteredRecipes == null) {
|
||||
this.filteredRecipes = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (this.filteredRecipes != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Stream<Integer> items = IntStream.range(0, arecipes.size()).boxed();
|
||||
final IRecipeFilter filter = GuiRecipe.getRecipeListFilter(this);
|
||||
|
||||
if (filter == null) {
|
||||
this.filteredRecipes = items.collect(Collectors.toCollection(ArrayList::new));
|
||||
} else {
|
||||
final boolean disableCycledIngredients = TemplateRecipeHandler.disableCycledIngredients;
|
||||
TemplateRecipeHandler.disableCycledIngredients = true;
|
||||
|
||||
this.filteredRecipes = items
|
||||
.filter(
|
||||
recipe -> filter.matches(
|
||||
this,
|
||||
arecipes.get(recipe).getIngredients(),
|
||||
arecipes.get(recipe).getResult(),
|
||||
arecipes.get(recipe).getOtherStacks()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
TemplateRecipeHandler.disableCycledIngredients = disableCycledIngredients;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void applySearch(ArrayList<Integer> searchRecipes) {
|
||||
this.searchRecipes = searchRecipes;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getSearchResult(IRecipeFilter filter) {
|
||||
if (filteredRecipes == null) {
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
ArrayList<Integer> filtered = null;
|
||||
|
||||
if (!filteredRecipes.isEmpty()) {
|
||||
final ArrayList<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
final boolean disableCycledIngredients = TemplateRecipeHandler.disableCycledIngredients;
|
||||
TemplateRecipeHandler.disableCycledIngredients = true;
|
||||
|
||||
try {
|
||||
filtered = ItemList.forkJoinPool.submit(
|
||||
() -> recipes.parallelStream()
|
||||
.filter(
|
||||
(recipe) -> filter.matches(
|
||||
this,
|
||||
arecipes.get(filteredRecipes.get(recipe)).getIngredients(),
|
||||
arecipes.get(filteredRecipes.get(recipe)).getResult(),
|
||||
arecipes.get(filteredRecipes.get(recipe)).getOtherStacks()))
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get();
|
||||
filtered.sort((a, b) -> a - b);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
TemplateRecipeHandler.disableCycledIngredients = disableCycledIngredients;
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
private int ref(int index) {
|
||||
|
||||
if (filteredRecipes == null) {
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
if (searchRecipes != null) {
|
||||
index = searchRecipes.get(index);
|
||||
}
|
||||
|
||||
return filteredRecipes.get(index);
|
||||
}
|
||||
|
||||
public int numRecipes() {
|
||||
|
||||
if (filteredRecipes == null) {
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
if (searchRecipes != null) {
|
||||
return searchRecipes.size();
|
||||
}
|
||||
|
||||
return filteredRecipes.size();
|
||||
return arecipes.size();
|
||||
}
|
||||
|
||||
public void drawBackground(int recipe) {
|
||||
@@ -783,19 +661,19 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
public List<PositionedStack> getIngredientStacks(int recipe) {
|
||||
return arecipes.get(ref(recipe)).getIngredients();
|
||||
return arecipes.get(recipe).getIngredients();
|
||||
}
|
||||
|
||||
public PositionedStack getResultStack(int recipe) {
|
||||
try {
|
||||
return arecipes.get(ref(recipe)).getResult();
|
||||
return arecipes.get(recipe).getResult();
|
||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PositionedStack> getOtherStacks(int recipe) {
|
||||
return arecipes.get(ref(recipe)).getOtherStacks();
|
||||
return arecipes.get(recipe).getOtherStacks();
|
||||
}
|
||||
|
||||
public void onUpdate() {
|
||||
@@ -871,9 +749,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
final PositionedStack overStack = getIngredientMouseOver(relMouse.x, relMouse.y, recipe);
|
||||
|
||||
if (overStack != null && overStack.items.length > 1) {
|
||||
final ItemFilter filter = new AllMultiItemFilter(
|
||||
ItemList.getItemListFilter(),
|
||||
GuiRecipe.searchField.getFilter());
|
||||
final ItemFilter filter = getItemFilter();
|
||||
|
||||
if (NEIClientConfig.useJEIStyledCycledIngredients()) {
|
||||
ItemStack stack = overStack.item;
|
||||
|
||||
@@ -288,7 +288,6 @@ nei.options.tools.dump.handlers.mode.1=Json
|
||||
|
||||
nei.recipe.page=Page %s/%s
|
||||
nei.recipe.tooltip=Recipes
|
||||
nei.recipe.search.show=Click to Search
|
||||
nei.recipe.shaped=Shaped Crafting
|
||||
nei.recipe.shapeless=Shapeless Crafting
|
||||
nei.recipe.furnace=Smelting
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 34 KiB |
Reference in new issue
Block a user