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 {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
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;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
private String handlerName;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
private String modName;
|
|
|
|
|
private String modId;
|
2021-08-22 20:16:15 +03:00
|
|
|
private boolean requiresMod;
|
2021-03-28 00:12:17 -07:00
|
|
|
private String excludedModId;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
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;
|
2025-07-29 09:37:37 -04:00
|
|
|
private boolean showFavoritesButton = true;
|
|
|
|
|
private boolean showOverlayButton = true;
|
2026-04-04 21:12:05 +03:00
|
|
|
private boolean showBadge = false;
|
2025-10-12 19:39:21 +03:00
|
|
|
private boolean useCustomScroll = false;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
private ItemStack itemStack = null;
|
|
|
|
|
private DrawableResource image = null;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
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;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
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) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasImageOrItem()) return false;
|
2021-03-28 00:12:17 -07:00
|
|
|
|
2025-10-12 19:39:21 +03: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
|
|
|
}
|
2025-10-12 19:39:21 +03:00
|
|
|
|
|
|
|
|
return this.itemStack != null;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public boolean setImage(String resourceLocation, int imageX, int imageY, int imageWidth, int imageHeight) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (hasImageOrItem()) return false;
|
|
|
|
|
|
|
|
|
|
this.image = new DrawableBuilder(resourceLocation, imageX, imageY, imageWidth, imageHeight).build();
|
2021-03-28 00:12:17 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public DrawableResource getImage() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.image;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public ItemStack getItemStack() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.itemStack;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public String getModName() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.modName;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getModId() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.modId;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHeight() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.height;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidth() {
|
2025-10-12 19:39:21 +03:00
|
|
|
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
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public int getYShift() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.yShift;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
public String getHandlerName() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.handlerName;
|
2021-08-22 20:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
2021-03-28 00:12:17 -07:00
|
|
|
public boolean hasImageOrItem() {
|
2025-10-12 19:39:21 +03:00
|
|
|
return this.image != null || this.itemStack != null;
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setYShift(int yShift) {
|
|
|
|
|
this.yShift = yShift;
|
|
|
|
|
}
|
2021-08-22 20:16:15 +03:00
|
|
|
|
2025-07-29 09:37:37 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public boolean getUseCustomScroll() {
|
|
|
|
|
return this.useCustomScroll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUseCustomScroll(boolean useCustomScroll) {
|
|
|
|
|
this.useCustomScroll = useCustomScroll;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
public static class Builder {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
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);
|
2021-08-22 20:16:15 +03:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
public Builder setDisplayStack(ItemStack stack) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.image = null;
|
|
|
|
|
this.info.itemStack = stack;
|
2021-08-22 20:16:15 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
2023-11-08 18:03:42 +09:00
|
|
|
|
|
|
|
|
public Builder setDisplayImage(DrawableResource drawable) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.itemStack = null;
|
|
|
|
|
this.info.image = drawable;
|
2023-11-08 18:03:42 +09:00
|
|
|
return this;
|
|
|
|
|
}
|
2021-08-22 20:16:15 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
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);
|
2021-08-22 20:16:15 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public Builder setUseCustomScroll(boolean useCustomScroll) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.setUseCustomScroll(useCustomScroll);
|
2025-10-12 19:39:21 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 20:16:15 +03:00
|
|
|
public Builder setShiftY(int shiftY) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.setYShift(shiftY);
|
2021-08-22 20:16:15 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setWidth(int width) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.width = width;
|
2021-08-22 20:16:15 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setHeight(int height) {
|
2025-11-05 19:00:09 +02:00
|
|
|
this.info.height = height;
|
2021-08-22 20:16:15 +03:00
|
|
|
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
|
2021-08-22 20:16:15 +03:00
|
|
|
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;
|
2021-08-22 20:16:15 +03:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HandlerInfo build() {
|
2025-11-05 19:00:09 +02:00
|
|
|
return this.info;
|
2021-08-22 20:16:15 +03:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-28 00:12:17 -07:00
|
|
|
}
|