mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-25 22:44:36 +00:00
Add builder for use in NEIRegisterHandlerInfosEvent (#153)
This commit is contained in:
1 parent
dd18d2b775
commit
52fb89daf6
3 files changed
+69
-15
No files matched your search
+11
-5
@@ -7,6 +7,9 @@ import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Event is posted every time the handler infos got registered or reloaded.
|
||||
* During it, you can safely register your custom handler info.
|
||||
@@ -16,12 +19,15 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public class RegisterHandlerInfosEvent extends Event {
|
||||
public void registerHandlerInfo(Class<? extends IRecipeHandler> handlerClazz, HandlerInfo info) {
|
||||
if (GuiRecipeTab.handlerMap.put(handlerClazz.getName(), info) != null) {
|
||||
NEIClientConfig.logger.info("Replaced handler info for {}", handlerClazz.getName());
|
||||
public class NEIRegisterHandlerInfosEvent extends Event {
|
||||
public void registerHandlerInfo(Class<? extends IRecipeHandler> handlerClazz, String modName, String modId, Consumer<HandlerInfo.Builder> builder) {
|
||||
HandlerInfo.Builder b = new HandlerInfo.Builder(handlerClazz, modName, modId);
|
||||
builder.accept(b);
|
||||
HandlerInfo info = b.build();
|
||||
if (GuiRecipeTab.handlerMap.put(info.getHandlerName(), info) != null) {
|
||||
NEIClientConfig.logger.info("Replaced handler info for {}", info.getHandlerName());
|
||||
} else {
|
||||
NEIClientConfig.logger.info("Added handler info for {}", handlerClazz.getName());
|
||||
NEIClientConfig.logger.info("Added handler info for {}", info.getHandlerName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.Widget;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
import codechicken.nei.event.RegisterHandlerInfosEvent;
|
||||
import codechicken.nei.event.NEIRegisterHandlerInfosEvent;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -262,8 +262,8 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
NEIClientConfig.logger.info("Sending {}", RegisterHandlerInfosEvent.class.getSimpleName());
|
||||
MinecraftForge.EVENT_BUS.post(new RegisterHandlerInfosEvent());
|
||||
NEIClientConfig.logger.info("Sending {}", NEIRegisterHandlerInfosEvent.class.getSimpleName());
|
||||
MinecraftForge.EVENT_BUS.post(new NEIRegisterHandlerInfosEvent());
|
||||
}
|
||||
|
||||
private static HandlerInfo getDefaultHandlerInfo() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
public class HandlerInfo {
|
||||
@@ -17,11 +18,11 @@ public class HandlerInfo {
|
||||
public static int DEFAULT_WIDTH = 166;
|
||||
public static int DEFAULT_MAX_PER_PAGE = 2;
|
||||
|
||||
private String handler;
|
||||
private String handlerName;
|
||||
|
||||
private String modName;
|
||||
private String modId;
|
||||
private boolean requiresMod = true;
|
||||
private boolean requiresMod;
|
||||
private String excludedModId;
|
||||
|
||||
private String itemId;
|
||||
@@ -35,8 +36,8 @@ public class HandlerInfo {
|
||||
private ItemStack itemStack = null;
|
||||
private DrawableResource image = null;
|
||||
|
||||
public HandlerInfo(String handler, String modName, String modId, boolean requiresMod, String excludedModId) {
|
||||
this.handler = handler;
|
||||
public HandlerInfo(String handlerName, String modName, String modId, boolean requiresMod, String excludedModId) {
|
||||
this.handlerName = handlerName;
|
||||
this.modName = modName;
|
||||
this.modId = modId;
|
||||
this.requiresMod = requiresMod;
|
||||
@@ -55,7 +56,7 @@ public class HandlerInfo {
|
||||
|
||||
int meta = -1;
|
||||
if (!itemId.contains(":")) {
|
||||
NEIClientConfig.logger.info("Item ID missing colon for handler " + handler + " - " + modName);
|
||||
NEIClientConfig.logger.info("Item ID missing colon for handler " + handlerName + " - " + modName);
|
||||
return false;
|
||||
}
|
||||
final String[] split = itemId.split(":");
|
||||
@@ -125,7 +126,6 @@ public class HandlerInfo {
|
||||
return modId;
|
||||
}
|
||||
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
@@ -142,6 +142,10 @@ public class HandlerInfo {
|
||||
return yShift;
|
||||
}
|
||||
|
||||
public String getHandlerName() {
|
||||
return handlerName;
|
||||
}
|
||||
|
||||
public boolean hasImageOrItem() {
|
||||
if (image != null) return true;
|
||||
if (itemStack != null) return true;
|
||||
@@ -149,8 +153,52 @@ public class HandlerInfo {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setYShift(int yShift) {
|
||||
this.yShift = yShift;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final HandlerInfo info;
|
||||
|
||||
public Builder(Class<?> handlerClazz, String modName, String modId) {
|
||||
this.info = new HandlerInfo(handlerClazz.getName(), modName, modId, true, null);
|
||||
setMaxRecipesPerPage(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Builder setDisplayStack(ItemStack stack) {
|
||||
info.image = null;
|
||||
info.itemStack = stack;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDisplayImage(ResourceLocation location, int imageX, int imageY, int imageWidth, int imageHeight) {
|
||||
info.itemStack = null;
|
||||
info.setImage(location.toString(), imageX, imageY, imageWidth, imageHeight);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setShiftY(int shiftY) {
|
||||
info.setYShift(shiftY);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setWidth(int width) {
|
||||
info.setHandlerDimensions(info.height, width, info.maxRecipesPerPage);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHeight(int height) {
|
||||
info.setHandlerDimensions(height, info.width, info.maxRecipesPerPage);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMaxRecipesPerPage(int maxRecipesPerPage) {
|
||||
info.setHandlerDimensions(info.height, info.width, maxRecipesPerPage);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HandlerInfo build() {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user