Introduce HandlerInfo

* Switch handler info loading from code to CSV
 * Add option to load from config or JAR
 * handlers.csv is still a WIP
This commit is contained in:
Jason Mitchell authored and Jason Mitchell committed 2021-04-12 20:20:36 -07:00
1 parent 509078da35
commit 429f2f36a9
11 files changed
+614 -579

No files matched your search

+136
View File
@@ -0,0 +1,136 @@
package codechicken.nei.recipe;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.ItemStack;
public class HandlerInfo {
public static int DEFAULT_HEIGHT = 65;
public static int DEFAULT_WIDTH = 166;
public static int DEFAULT_MAX_PER_PAGE = 2;
private String handler;
private String modName;
private String modId;
private boolean requiresMod = true;
private String excludedModId;
private String itemId;
private String nbtString;
private int yShift = 0;
private int height = DEFAULT_HEIGHT;
private int width = DEFAULT_WIDTH;
private int maxRecipesPerPage = DEFAULT_MAX_PER_PAGE;
private ItemStack itemStack = null;
private DrawableResource image = null;
public HandlerInfo(String handler, String modName, String modId, boolean requiresMod, String excludedModId) {
this.handler = handler;
this.modName = modName;
this.modId = modId;
this.requiresMod = requiresMod;
this.excludedModId = excludedModId;
}
public void setHandlerDimensions(int height, int width, int maxRecipesPerPage) {
this.height = height;
this.width = width;
this.maxRecipesPerPage = maxRecipesPerPage;
}
public boolean setItem(String itemId, String nbtString) {
if(hasImageOrItem())
return false;
int meta = -1;
if (!itemId.contains(":")) {
NEIClientConfig.logger.info("Item ID missing colon for handler " + handler + " - " + modName);
return false;
}
final String[] split = itemId.split(":");
// ModID:ItemID
String itemLookupId = split[0] + ":" + split[1];
if(split.length >= 3) {
int mIdx = -1;
if (split[2].matches("\\d+")) {
mIdx = 2;
} else {
itemLookupId += ":" + split[2];
if (split.length >= 4) mIdx = 3;
}
if (mIdx != -1) meta = Integer.parseInt(split[mIdx]);
}
if (meta != -1) {
itemStack = GameRegistry.makeItemStack(itemLookupId, meta, 1, nbtString == null ? "" : nbtString);
} else {
itemStack = GameRegistry.findItemStack(split[0], split[1], 1);
}
if (itemStack == null)
NEIClientConfig.logger.info("Couldn't find " + modName + " - " + itemLookupId);
else {
this.itemId = itemId;
this.nbtString = nbtString;
}
return (itemStack != null);
}
public boolean setImage(String resourceLocation, int imageX, int imageY, int imageWidth, int imageHeight) {
if(hasImageOrItem())
return false;
this.image = new DrawableBuilder(resourceLocation, imageX, imageY, imageWidth, imageHeight).build();
return true;
}
public DrawableResource getImage() {
return image;
}
public ItemStack getItemStack() {
return itemStack;
}
public String getModName() {
return modName;
}
public String getModId() {
return modId;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public int getMaxRecipesPerPage() {
return Math.max(maxRecipesPerPage, 1);
}
public int getYShift() {
return yShift;
}
public boolean hasImageOrItem() {
if (image != null) return true;
if (itemStack != null) return true;
return false;
}
public void setYShift(int yShift) {
this.yShift = yShift;
}
}