Compare commits

..
Author SHA1 Message Date
Glease 51ea8bba34 Add final modifiers on those handlers fields
Also added an optional asm transformer to catch potential problems
2022-01-26 20:54:04 -08:00
Glease b0c6f358f7 Use copy on write lists for handler lists 2022-01-26 20:54:04 -08:00
miozune c73edaa72e Use String key for RecipeCatalyst instead of IRecipeHandler.class (#197)
* Use String key for RecipeCatalyst instead of IRecipeHandler.class

* deprecate old methods

* delete commented out code
2022-01-22 23:37:54 +01:00
Jason Mitchell caebccc1fd update buildscript again 2022-01-22 09:45:21 -08:00
Jason Mitchell a0c5ea42b9 update buildscript 2022-01-21 22:49:59 -08:00
Jason Mitchell 23d4be06e8 update buildscript 2022-01-21 21:50:17 -08:00
miozune 1e36822fa4 Add RecipeCatalyst system (#195)
* Add RecipeCatalyst system
2022-01-21 20:16:28 -08:00
Jason Mitchell 3ce702343d update buildscript - publish shaded jars properly 2022-01-17 21:46:41 -08:00
Jason Mitchell a3387f0290 update and pin dependencies 2022-01-17 20:27:25 -08:00
Jason Mitchell 116b96f67b maven publish buildscript update 2022-01-17 20:27:25 -08:00
makamys 60fe49d18c Make item loading timeout configurable 2022-01-17 12:39:11 -08:00
18 changed files with 436 additions and 58 deletions

No files matched your search

+6
View File
@@ -43,3 +43,9 @@ jobs:
prerelease: false
title: "${{ env.RELEASE_VERSION }}"
files: build/libs/*.jar
- name: Publish to Maven
run: ./gradlew publish
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
+3
View File
@@ -0,0 +1,3 @@
# Any Github changes require admin approval
/.github/** @GTNewHorizons/admin
+89 -24
View File
@@ -1,9 +1,9 @@
//version: 8fa7883b6196c1765266f4e6ddf3118d5043aafb
//version: 1642872913
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Please check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle for updates.
Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates.
*/
@@ -32,16 +32,18 @@ buildscript {
}
}
dependencies {
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.4'
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.5'
}
}
plugins {
id 'idea'
id 'eclipse'
id 'scala'
id("org.ajoberstar.grgit") version("3.1.1")
id("com.github.johnrengelman.shadow") version("4.0.4")
id("com.palantir.git-version") version("0.12.3")
id('de.undercouch.download') version('4.1.2')
id("maven-publish")
}
@@ -88,6 +90,7 @@ checkPropertyExists("containsMixinsAndOrCoreModOnly")
checkPropertyExists("usesShadowedDependencies")
checkPropertyExists("developmentEnvironmentUserName")
boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false
String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
@@ -151,12 +154,16 @@ configurations.all {
// Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version
'git config core.fileMode false'.execute()
// Pulls version from git tag
// Pulls version first from the VERSION env and then git tag
String identifiedVersion
try {
version = minecraftVersion + "-" + gitVersion()
String versionOverride = System.getenv("VERSION") ?: null
identifiedVersion = versionOverride == null ? gitVersion() : versionOverride
version = minecraftVersion + "-" + identifiedVersion
}
catch (Exception e) {
throw new IllegalStateException("This mod must be version controlled by Git AND the repository must provide at least one tag!");
throw new IllegalStateException("This mod must be version controlled by Git AND the repository must provide at least one tag, or the VERSION override must be set!");
}
group = modGroup
@@ -223,7 +230,7 @@ dependencies {
annotationProcessor("com.google.code.gson:gson:2.8.6")
annotationProcessor("org.spongepowered:mixin:0.8-SNAPSHOT")
// using 0.8 to workaround a issue in 0.7 which fails mixin application
compile("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
compile("com.github.GTNewHorizons:SpongePoweredMixin:0.7.12-GTNH") {
// Mixin includes a lot of dependencies that are too up-to-date
exclude module: "launchwrapper"
exclude module: "guava"
@@ -231,7 +238,7 @@ dependencies {
exclude module: "commons-io"
exclude module: "log4j-core"
}
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
compile("com.github.GTNewHorizons:SpongeMixins:1.5.0")
}
}
@@ -480,40 +487,63 @@ task apiJar(type: Jar) {
}
artifacts {
archives sourcesJar
if(!noPublishedSources) {
archives sourcesJar
}
archives devJar
if(apiPackage) {
archives apiJar
}
}
// The gradle metadata includes all of the additional deps that we disabled from POM generation (including forgeBin with no groupID),
// and isn't strictly needed with the POM so just disable it.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
// publishing
publishing {
publications {
maven(MavenPublication) {
artifact source: jar
artifact source: sourcesJar, classifier: "src"
artifact source: devJar, classifier: "dev"
from components.java
if(usesShadowedDependencies.toBoolean()) {
artifact source: shadowJar, classifier: ""
}
if(!noPublishedSources) {
artifact source: sourcesJar, classifier: "src"
}
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
if (apiPackage) {
artifact source: apiJar, classifier: "api"
}
groupId = System.getenv("ARTIFACT_GROUP_ID") ?: group
groupId = System.getenv("ARTIFACT_GROUP_ID") ?: "com.github.GTNewHorizons"
artifactId = System.getenv("ARTIFACT_ID") ?: project.name
version = System.getenv("ARTIFACT_VERSION") ?: project.version
// Using the identified version, not project.version as it has the prepended 1.7.10
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
// Remove all non GTNH deps here.
// Original intention was to remove an invalid forgeBin being generated without a groupId (mandatory), but
// it also removes all of the MC deps
pom.withXml {
Node pomNode = asNode()
pomNode.dependencies.'*'.findAll() {
it.groupId.text() != 'com.github.GTNewHorizons'
}.each() {
it.parent().remove(it)
}
}
}
}
repositories {
maven {
String owner = System.getenv("REPOSITORY_OWNER") ?: "Unknown"
String repositoryName = System.getenv("REPOSITORY_NAME") ?: "Unknown"
String githubRepositoryUrl = "https://maven.pkg.github.com/$owner/$repositoryName"
name = "GitHubPackages"
url = githubRepositoryUrl
url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases"
credentials {
username = System.getenv("GITHUB_ACTOR") ?: "NONE"
password = System.getenv("GITHUB_TOKEN") ?: "NONE"
username = System.getenv("MAVEN_USER") ?: "NONE"
password = System.getenv("MAVEN_PASSWORD") ?: "NONE"
}
}
}
@@ -537,7 +567,7 @@ if (isNewBuildScriptVersionAvailable(projectDir.toString())) {
}
static URL availableBuildScriptUrl() {
new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle")
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/main/build.gradle")
}
boolean performBuildScriptUpdate(String projectDir) {
@@ -575,11 +605,46 @@ configure(updateBuildScript) {
description = 'Updates the build script to the latest version'
}
// Deobfuscation
def deobf(String sourceURL, String fileName) {
def bon2File = "$projectDir/deobf/BON2-2.5.0.jar"
def cacheFile = "$projectDir/deobf/out/" + fileName + ".jar"
def deobfFile = "$projectDir/deobf/out/" + fileName + "-deobf.jar"
if(file(deobfFile).exists()) {
return files(deobfFile)
}
download {
src 'https://github.com/GTNewHorizons/BON2/releases/download/2.5.0/BON2-2.5.0.CUSTOM-all.jar'
dest bon2File
quiet true
overwrite false
}
download {
src sourceURL
dest cacheFile
quiet true
overwrite false
}
exec {
commandLine 'java', '-jar', bon2File, '--inputJar', cacheFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch'
workingDir "$projectDir/deobf"
standardOutput = new ByteArrayOutputStream()
}
delete(cacheFile)
return files(deobfFile)
}
// Helper methods
def checkPropertyExists(String propertyName) {
if (project.hasProperty(propertyName) == false) {
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties")
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties")
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Add your dependencies here
dependencies {
compile("com.github.GTNewHorizons:CodeChickenLib:master-SNAPSHOT:dev")
compile("com.github.GTNewHorizons:CodeChickenCore:master-SNAPSHOT:dev")
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.1:dev")
compile("com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev")
shadowImplementation("org.apache.commons:commons-csv:1.5")
}
+4
View File
@@ -2,6 +2,10 @@
repositories {
mavenCentral()
maven {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
url = "https://jitpack.io"
}
+2 -2
View File
@@ -185,13 +185,13 @@ public class ItemList
@SuppressWarnings("unchecked")
public void execute() {
// System.out.println("Executing NEI Item Loading");
ThreadOperationTimer timer = getTimer(500);
ThreadOperationTimer timer = getTimer(NEIClientConfig.getItemLoadingTimeout());
LinkedList<ItemStack> items = new LinkedList<>();
LinkedList<ItemStack> permutations = new LinkedList<>();
ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
timer.setLimit(500);
timer.setLimit(NEIClientConfig.getItemLoadingTimeout());
for (Item item : (Iterable<Item>) Item.itemRegistry) {
if (interrupted()) return;
@@ -168,6 +168,8 @@ public class NEIClientConfig {
return isMouseScrollTransferEnabled();
}
});
tag.getTag("itemLoadingTimeout").getIntValue(500);
tag.getTag("command.creative").setDefaultValue("/gamemode {0} {1}");
API.addOption(new OptionTextField("command.creative"));
@@ -451,6 +453,10 @@ public class NEIClientConfig {
int i = getIntSetting("inventory.itemIDs");
return i == 2 || (i == 1 && isEnabled() && !isHidden());
}
public static int getItemLoadingTimeout() {
return getIntSetting("itemLoadingTimeout");
}
public static void toggleBooleanSetting(String setting) {
ConfigTag tag = getSetting(setting);
+36 -2
View File
@@ -300,7 +300,7 @@ public class API
* @param stack the ingredient that can craft recipes (like a furnace or crafting table)
* @param handler the recipe category handled by the ingredient
*/
public static void addRecipeCatalyst(ItemStack stack, Class<? extends IRecipeHandler> handler) {
public static void addRecipeCatalyst(ItemStack stack, IRecipeHandler handler) {
addRecipeCatalyst(Collections.singletonList(stack), handler);
}
@@ -310,8 +310,42 @@ public class API
* @param stacks the ingredients that can craft recipes (like a furnace or crafting table)
* @param handler the recipe category handled by the ingredient
*/
public static void addRecipeCatalyst(List<ItemStack> stacks, IRecipeHandler handler) {
String handlerID = handler.getOverlayIdentifier();
if (handlerID != null) {
addRecipeCatalyst(stacks, handler.getOverlayIdentifier());
}
else {
NEIClientConfig.logger.warn(String.format("failed to add recipe catalyst, implement IRecipeHandler#getOverlayIdentifier for your handler %s", handler.getClass().getName()));
}
}
/**
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stack the ingredient that can craft recipes (like a furnace or crafting table)
* @param handlerID recipe category identifier (see {@link IRecipeHandler#getOverlayIdentifier()})
*/
public static void addRecipeCatalyst(ItemStack stack, String handlerID) {
addRecipeCatalyst(Collections.singletonList(stack), handlerID);
}
/**
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stacks the ingredients that can craft recipes (like a furnace or crafting table)
* @param handlerID recipe category identifier (see {@link IRecipeHandler#getOverlayIdentifier()})
*/
public static void addRecipeCatalyst(List<ItemStack> stacks, String handlerID) {
RecipeCatalysts.addRecipeCatalyst(stacks, handlerID);
}
@Deprecated
public static void addRecipeCatalyst(ItemStack stack, Class<? extends IRecipeHandler> handler) {
}
@Deprecated
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
RecipeCatalysts.addRecipeCatalyst(stacks, handler);
}
}
@@ -0,0 +1,38 @@
package codechicken.nei.asm;
import codechicken.lib.asm.ASMHelper;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import static org.objectweb.asm.Opcodes.POP;
import static org.objectweb.asm.Opcodes.PUTSTATIC;
public class GuiContainerManagerAPITransformer extends ClassVisitor {
private final String tname;
private boolean changed = false;
public GuiContainerManagerAPITransformer(int api, ClassVisitor cv, String tname) {
super(api, cv);
this.tname = tname;
}
@Override
public MethodVisitor visitMethod(int access, String mname, String mdesc, String signature, String[] exceptions) {
return new MethodVisitor(api, super.visitMethod(access, mname, mdesc, signature, exceptions)) {
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == PUTSTATIC && "codechicken/nei/guihook/GuiContainerManager".equals(owner) && name.endsWith("Handlers") && desc.equals("Ljava/util/LinkedList;")) {
ASMHelper.logger.warn("Found suspicious PUTSTATIC {} in {}#{}{}, replacing with POP!", name, tname, mname, mdesc);
changed = true;
super.visitInsn(POP);
} else {
super.visitFieldInsn(opcode, owner, name, desc);
}
}
};
}
public boolean isChanged() {
return changed;
}
}
@@ -41,6 +41,7 @@ public class NEITransformer implements IClassTransformer
ASMInit.init();
}
private final boolean paranoidMode = Boolean.getBoolean("nei.paranoid");
private final ModularASMTransformer transformer = new ModularASMTransformer();
private final Map<String, ASMBlock> asmblocks = ASMReader.loadResource("/assets/nei/asm/blocks.asm");
@@ -264,6 +265,14 @@ public class NEITransformer implements IClassTransformer
}
bytes = transformSubclasses(name, bytes);
}
if (paranoidMode && !tname.startsWith("codechicken.nei")) {
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(0);
GuiContainerManagerAPITransformer cv = new GuiContainerManagerAPITransformer(ASM5, cw, tname);
cr.accept(cv, ClassReader.SKIP_DEBUG);
if (cv.isChanged())
bytes = cw.toByteArray();
}
bytes = transformer.transform(name, bytes);
} catch (Exception e) {
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Pattern;
import static codechicken.lib.gui.GuiDraw.drawMultilineTip;
@@ -35,11 +36,11 @@ public class GuiContainerManager
public GuiContainer window;
public static RenderItem drawItems = new RenderItem();
public static LinkedList<IContainerTooltipHandler> tooltipHandlers = new LinkedList<>();
public static LinkedList<IContainerInputHandler> inputHandlers = new LinkedList<>();
public static LinkedList<IContainerDrawHandler> drawHandlers = new LinkedList<>();
public static LinkedList<IContainerObjectHandler> objectHandlers = new LinkedList<>();
public static LinkedList<IContainerSlotClickHandler> slotClickHandlers = new LinkedList<>();
public static final LinkedList<IContainerTooltipHandler> tooltipHandlers = new HideousLinkedList<>(new CopyOnWriteArrayList<>());
public static final LinkedList<IContainerInputHandler> inputHandlers = new HideousLinkedList<>(new CopyOnWriteArrayList<>());
public static final LinkedList<IContainerDrawHandler> drawHandlers = new HideousLinkedList<>(new CopyOnWriteArrayList<>());
public static final LinkedList<IContainerObjectHandler> objectHandlers = new HideousLinkedList<>(new CopyOnWriteArrayList<>());
public static final LinkedList<IContainerSlotClickHandler> slotClickHandlers = new HideousLinkedList<>(new CopyOnWriteArrayList<>());
static {
addSlotClickHandler(new DefaultSlotClickHandler());
@@ -0,0 +1,180 @@
package codechicken.nei.guihook;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
/**
* A hideous LinkedList that is backed by an arbitrary list, for alternative characteristics while preserving
* binary compatibility...
* @param <E>
*/
final class HideousLinkedList<E> extends LinkedList<E> {
private final List<E> backing;
HideousLinkedList(List<E> backing) {
this.backing = backing;
}
@Override
public int size() {
return backing.size();
}
@Override
public boolean isEmpty() {
return backing.isEmpty();
}
@Override
public boolean contains(Object o) {
return backing.contains(o);
}
@Override
public Iterator<E> iterator() {
return backing.iterator();
}
@Override
public Object[] toArray() {
return backing.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
return backing.toArray(a);
}
@Override
public boolean add(E e) {
return backing.add(e);
}
@Override
public boolean remove(Object o) {
return backing.remove(o);
}
@Override
public boolean containsAll(Collection<?> c) {
return backing.containsAll(c);
}
@Override
public boolean addAll(Collection<? extends E> c) {
return backing.addAll(c);
}
@Override
public boolean addAll(int index, Collection<? extends E> c) {
return backing.addAll(index, c);
}
@Override
public boolean removeAll(Collection<?> c) {
return backing.removeAll(c);
}
@Override
public boolean retainAll(Collection<?> c) {
return backing.retainAll(c);
}
@Override
public void replaceAll(UnaryOperator<E> operator) {
backing.replaceAll(operator);
}
@Override
public void sort(Comparator<? super E> c) {
backing.sort(c);
}
@Override
public void clear() {
backing.clear();
}
@Override
public boolean equals(Object o) {
return backing.equals(o);
}
@Override
public int hashCode() {
return backing.hashCode();
}
@Override
public E get(int index) {
return backing.get(index);
}
@Override
public E set(int index, E element) {
return backing.set(index, element);
}
@Override
public void add(int index, E element) {
backing.add(index, element);
}
@Override
public E remove(int index) {
return backing.remove(index);
}
@Override
public int indexOf(Object o) {
return backing.indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
return backing.lastIndexOf(o);
}
@Override
public ListIterator<E> listIterator() {
return backing.listIterator();
}
@Override
public ListIterator<E> listIterator(int index) {
return backing.listIterator(index);
}
@Override
public List<E> subList(int fromIndex, int toIndex) {
return backing.subList(fromIndex, toIndex);
}
@Override
public Spliterator<E> spliterator() {
return backing.spliterator();
}
@Override
public boolean removeIf(Predicate<? super E> filter) {
return backing.removeIf(filter);
}
@Override
public Stream<E> stream() {
return backing.stream();
}
@Override
public Stream<E> parallelStream() {
return backing.parallelStream();
}
@Override
public void forEach(Consumer<? super E> action) {
backing.forEach(action);
}
}
@@ -507,7 +507,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
if (result != null)
slotcontainer.addSlot(result, p.x, p.y);
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler.getClass());
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler);
for (PositionedStack catalyst : catalysts) {
int xOffset = -GuiRecipeCatalyst.ingredientSize + 1;
int yOffset = BG_TOP_Y + GuiRecipeCatalyst.fullBorder;
@@ -24,7 +24,7 @@ public class GuiRecipeCatalyst extends INEIGuiAdapter {
public void draw() {
if (guiRecipe == null) return;
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler().getClass()).size();
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
if (catalystsSize == 0) return;
int availableHeight = RecipeCatalysts.getHeight();
@@ -49,7 +49,7 @@ public class GuiRecipeCatalyst extends INEIGuiAdapter {
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
if (!(gui instanceof GuiRecipe)) return false;
guiRecipe = (GuiRecipe) gui;
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler().getClass()).size();
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
if (catalystsSize == 0) return false;
int availableHeight = RecipeCatalysts.getHeight();
@@ -89,6 +89,15 @@ public interface IRecipeHandler
* @return An instance of {@link IOverlayHandler} to be used for rendering the overlay of this specific recipe.
*/
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe);
/**
* Simply works with the {@link codechicken.nei.api.DefaultOverlayRenderer}
* If the current container has been registered with this identifier, the question mark appears and an overlay guide can be drawn.
*
* @return The overlay identifier of this recipe type.
*/
public default String getOverlayIdentifier() {
return null;
}
/**
*
* @return The number of recipes that can fit on a page in the viewer (1 or 2)
@@ -12,39 +12,49 @@ import java.util.List;
import java.util.Map;
public class RecipeCatalysts {
private static final Map<Class<? extends IRecipeHandler>, List<ItemStack>> recipeCatalystMap = new HashMap<>();
private static Map<Class<? extends IRecipeHandler>, List<PositionedStack>> positionedRecipeCatalystMap = new HashMap<>();
private static final Map<String, List<ItemStack>> recipeCatalystMap = new HashMap<>();
private static Map<String, List<PositionedStack>> positionedRecipeCatalystMap = new HashMap<>();
private static int heightCache;
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
if (recipeCatalystMap.containsKey(handler)) {
recipeCatalystMap.get(handler).addAll(stacks);
public static void addRecipeCatalyst(List<ItemStack> stacks, String handlerID) {
if (handlerID == null) return;
if (recipeCatalystMap.containsKey(handlerID)) {
recipeCatalystMap.get(handlerID).addAll(stacks);
} else {
recipeCatalystMap.put(handler, new ArrayList<>(stacks));
// use ArrayList initializer to prevent UOE
recipeCatalystMap.put(handlerID, new ArrayList<>(stacks));
}
}
public static Map<Class<? extends IRecipeHandler>, List<PositionedStack>> getPositionedRecipeCatalystMap() {
public static Map<String, List<PositionedStack>> getPositionedRecipeCatalystMap() {
return positionedRecipeCatalystMap;
}
public static List<PositionedStack> getRecipeCatalysts(Class<? extends IRecipeHandler> handler) {
public static List<PositionedStack> getRecipeCatalysts(IRecipeHandler handler) {
return getRecipeCatalysts(handler.getOverlayIdentifier());
}
public static List<PositionedStack> getRecipeCatalysts(String handlerID) {
if (!NEIClientConfig.areJEIStyleTabsVisible() || !NEIClientConfig.areJEIStyleRecipeCatalystsVisible()) {
return Collections.emptyList();
}
return positionedRecipeCatalystMap.getOrDefault(handler, Collections.emptyList());
return positionedRecipeCatalystMap.getOrDefault(handlerID, Collections.emptyList());
}
public static boolean containsCatalyst(Class<? extends IRecipeHandler> handler, ItemStack candidate) {
return recipeCatalystMap.getOrDefault(handler, Collections.emptyList()).stream()
public static boolean containsCatalyst(IRecipeHandler handler, ItemStack candidate) {
return containsCatalyst(handler.getOverlayIdentifier(), candidate);
}
public static boolean containsCatalyst(String handlerID, ItemStack candidate) {
return recipeCatalystMap.getOrDefault(handlerID, Collections.emptyList()).stream()
.anyMatch(s -> NEIServerUtils.areStacksSameType(s, candidate));
}
public static void updatePosition(int availableHeight) {
if (availableHeight == heightCache) return;
Map<Class<? extends IRecipeHandler>, List<PositionedStack>> newMap = new HashMap<>();
for (Map.Entry<Class<? extends IRecipeHandler>, List<ItemStack>> entry : recipeCatalystMap.entrySet()) {
Map<String, List<PositionedStack>> newMap = new HashMap<>();
for (Map.Entry<String, List<ItemStack>> entry : recipeCatalystMap.entrySet()) {
List<ItemStack> catalysts = entry.getValue();
List<PositionedStack> newStacks = new ArrayList<>();
int rowCount = getRowCount(availableHeight, catalysts.size());
@@ -75,4 +85,18 @@ public class RecipeCatalysts {
return NEIServerUtils.divideCeil(catalystsSize, columnCount);
}
@Deprecated
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
}
@Deprecated
public static List<PositionedStack> getRecipeCatalysts(Class<? extends IRecipeHandler> handler) {
return Collections.emptyList();
}
@Deprecated
public static boolean containsCatalyst(Class<? extends IRecipeHandler> handler, ItemStack candidate) {
return false;
}
}
@@ -123,12 +123,10 @@ public class RecipeInfo
API.registerRecipeHandler(new ProfilerRecipeHandler(true));
API.registerUsageHandler(new ProfilerRecipeHandler(false));
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), ShapedRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), ShapelessRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), FireworkRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), FurnaceRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Items.brewing_stand), BrewingRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), FuelRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), "crafting");
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), new FurnaceRecipeHandler());
API.addRecipeCatalyst(new ItemStack(Items.brewing_stand), new BrewingRecipeHandler());
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), new FuelRecipeHandler());
}
}
@@ -442,6 +442,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
*
* @return The overlay identifier of this recipe type.
*/
@Override
public String getOverlayIdentifier() {
return null;
}
@@ -559,7 +560,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
TemplateRecipeHandler handler = newInstance();
if (inputId.equals("item")) {
ItemStack candidate = (ItemStack) ingredients[0];
if (RecipeCatalysts.containsCatalyst(handler.getClass(), candidate)) {
if (RecipeCatalysts.containsCatalyst(handler, candidate)) {
for (RecipeTransferRect rect : transferRects) {
if (specifyTransferRect() == null || Objects.equals(rect.outputId, specifyTransferRect())) {
handler.loadCraftingRecipes(rect.outputId, rect.results);