Files
NotEnoughItems/src/main/java/codechicken/nei/recipe/HandlerInfo.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

248 lines
6.9 KiB
Java
Raw Normal View History

2021-03-28 00:12:17 -07:00
package codechicken.nei.recipe;
2023-09-25 00:35:24 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
2021-03-28 00:12:17 -07:00
import codechicken.nei.NEIClientConfig;
2022-01-31 01:01:12 +09:00
import codechicken.nei.NEIServerUtils;
2021-03-28 00:12:17 -07:00
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
public class HandlerInfo {
2021-03-28 00:12:17 -07:00
public static int DEFAULT_HEIGHT = 65;
public static int DEFAULT_WIDTH = 166;
2025-11-05 19:00:09 +02:00
@Deprecated
2021-11-29 21:33:11 -08:00
public static int DEFAULT_MAX_PER_PAGE = 1;
private String handlerName;
2021-03-28 00:12:17 -07:00
private String modName;
private String modId;
private boolean requiresMod;
2021-03-28 00:12:17 -07:00
private String excludedModId;
2021-03-28 00:12:17 -07:00
private int yShift = 0;
private int height = DEFAULT_HEIGHT;
private int width = DEFAULT_WIDTH;
2025-11-05 19:00:09 +02:00
private boolean multipleWidgetsAllowed = false;
private boolean showFavoritesButton = true;
private boolean showOverlayButton = true;
2026-04-04 21:12:05 +03:00
private boolean showBadge = false;
private boolean useCustomScroll = false;
2021-03-28 00:12:17 -07:00
private ItemStack itemStack = null;
private DrawableResource image = null;
public HandlerInfo(String handlerName, String modName, String modId, boolean requiresMod, String excludedModId) {
this.handlerName = handlerName;
2021-03-28 00:12:17 -07:00
this.modName = modName;
this.modId = modId;
this.requiresMod = requiresMod;
this.excludedModId = excludedModId;
}
2025-11-05 19:00:09 +02:00
@Deprecated
2021-03-28 00:12:17 -07:00
public void setHandlerDimensions(int height, int width, int maxRecipesPerPage) {
2026-03-22 14:10:10 +02:00
setHandlerDimensions(width, height);
setMultipleWidgetsAllowed(maxRecipesPerPage > 1);
2025-11-05 19:00:09 +02:00
}
2026-03-22 14:10:10 +02:00
public void setHandlerDimensions(int width, int height) {
2021-03-28 00:12:17 -07:00
this.height = height;
this.width = width;
}
public boolean setItem(String itemId, String nbtString) {
if (hasImageOrItem()) return false;
2021-03-28 00:12:17 -07:00
this.itemStack = NEIServerUtils.getModdedItem(itemId, nbtString);
if (this.itemStack == null) {
NEIClientConfig.logger.info("Couldn't find " + this.modName + " - " + itemId);
2021-03-28 00:12:17 -07:00
}
return this.itemStack != null;
2021-03-28 00:12:17 -07:00
}
2021-03-28 00:12:17 -07:00
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();
2021-03-28 00:12:17 -07:00
return true;
}
2021-03-28 00:12:17 -07:00
public DrawableResource getImage() {
return this.image;
2021-03-28 00:12:17 -07:00
}
2021-03-28 00:12:17 -07:00
public ItemStack getItemStack() {
return this.itemStack;
2021-03-28 00:12:17 -07:00
}
2021-03-28 00:12:17 -07:00
public String getModName() {
return this.modName;
2021-03-28 00:12:17 -07:00
}
public String getModId() {
return this.modId;
2021-03-28 00:12:17 -07:00
}
public int getHeight() {
return this.height;
2021-03-28 00:12:17 -07:00
}
public int getWidth() {
return this.width;
2021-03-28 00:12:17 -07:00
}
2025-11-05 19:00:09 +02:00
@Deprecated
2021-03-28 00:12:17 -07:00
public int getMaxRecipesPerPage() {
2025-11-05 19:00:09 +02:00
return this.multipleWidgetsAllowed ? Integer.MAX_VALUE : 1;
}
2026-03-22 14:10:10 +02:00
public void setMultipleWidgetsAllowed(boolean multipleWidgetsAllowed) {
this.multipleWidgetsAllowed = multipleWidgetsAllowed;
}
2025-11-05 19:00:09 +02:00
public boolean isMultipleWidgetsAllowed() {
return this.multipleWidgetsAllowed;
2021-03-28 00:12:17 -07:00
}
2021-03-28 00:12:17 -07:00
public int getYShift() {
return this.yShift;
2021-03-28 00:12:17 -07:00
}
public String getHandlerName() {
return this.handlerName;
}
2021-03-28 00:12:17 -07:00
public boolean hasImageOrItem() {
return this.image != null || this.itemStack != null;
2021-03-28 00:12:17 -07:00
}
public void setYShift(int yShift) {
this.yShift = yShift;
}
public boolean getShowFavoritesButton() {
return this.showFavoritesButton;
}
public void setShowFavoritesButton(boolean showFavoritesButton) {
this.showFavoritesButton = showFavoritesButton;
}
public boolean getShowOverlayButton() {
return this.showOverlayButton;
}
public void setShowOverlayButton(boolean showOverlayButton) {
this.showOverlayButton = showOverlayButton;
}
2026-04-04 00:03:15 +03:00
public boolean getShowBadge() {
return this.showBadge;
2026-03-31 20:47:23 +03:00
}
2026-04-04 00:03:15 +03:00
public void setShowBadge(boolean showBadge) {
this.showBadge = showBadge;
2026-03-31 20:47:23 +03:00
}
public boolean getUseCustomScroll() {
return this.useCustomScroll;
}
public void setUseCustomScroll(boolean useCustomScroll) {
this.useCustomScroll = useCustomScroll;
}
public static class Builder {
private final HandlerInfo info;
2021-08-24 22:14:34 -06:00
public Builder(String handlerName, String modName, String modId) {
this.info = new HandlerInfo(handlerName, modName, modId, true, null);
setMaxRecipesPerPage(Integer.MAX_VALUE);
}
2021-08-24 22:14:34 -06:00
public Builder(Class<? extends IRecipeHandler> handlerClazz, String modName, String modId) {
this(handlerClazz.getName(), modName, modId);
}
2025-11-08 23:54:35 +02:00
public Builder setDisplayStack(String itemId, String nbtString) {
return setDisplayStack(NEIServerUtils.getModdedItem(itemId, nbtString));
}
public Builder setDisplayStack(ItemStack stack) {
2025-11-05 19:00:09 +02:00
this.info.image = null;
this.info.itemStack = stack;
return this;
}
public Builder setDisplayImage(DrawableResource drawable) {
2025-11-05 19:00:09 +02:00
this.info.itemStack = null;
this.info.image = drawable;
return this;
}
public Builder setDisplayImage(ResourceLocation location, int imageX, int imageY, int imageWidth,
int imageHeight) {
2025-11-05 19:00:09 +02:00
this.info.itemStack = null;
this.info.setImage(location.toString(), imageX, imageY, imageWidth, imageHeight);
return this;
}
public Builder setUseCustomScroll(boolean useCustomScroll) {
2025-11-05 19:00:09 +02:00
this.info.setUseCustomScroll(useCustomScroll);
return this;
}
public Builder setShiftY(int shiftY) {
2025-11-05 19:00:09 +02:00
this.info.setYShift(shiftY);
return this;
}
public Builder setWidth(int width) {
2025-11-05 19:00:09 +02:00
this.info.width = width;
return this;
}
public Builder setHeight(int height) {
2025-11-05 19:00:09 +02:00
this.info.height = height;
return this;
}
2025-11-08 23:54:35 +02:00
public Builder setShowOverlayButton(boolean showOverlayButton) {
this.info.showOverlayButton = showOverlayButton;
return this;
}
public Builder setShowFavoritesButton(boolean showFavoritesButton) {
this.info.showFavoritesButton = showFavoritesButton;
return this;
}
2026-04-04 00:03:15 +03:00
public Builder setShowBadge(boolean showBadge) {
this.info.showBadge = showBadge;
2026-03-31 20:47:23 +03:00
return this;
}
2025-11-05 19:00:09 +02:00
@Deprecated
public Builder setMaxRecipesPerPage(int maxRecipesPerPage) {
2025-11-05 19:00:09 +02:00
this.info.multipleWidgetsAllowed = maxRecipesPerPage > 1;
return this;
}
public Builder setMultipleWidgetsAllowed(boolean multipleWidgetsAllowed) {
this.info.multipleWidgetsAllowed = multipleWidgetsAllowed;
return this;
}
public HandlerInfo build() {
2025-11-05 19:00:09 +02:00
return this.info;
}
}
2021-03-28 00:12:17 -07:00
}