Compare commits

...
Author SHA1 Message Date
D-Cysteine b4780716ec Add support for custom handler IDs (#154)
* Always show quantity text box

* Increment version

* Properly fix quantity text field

* Add support for custom handler names

* Add overloads
2021-08-25 06:14:34 +02:00
Andrey 52fb89daf6 Add builder for use in NEIRegisterHandlerInfosEvent (#153) 2021-08-22 10:16:15 -07:00
D-Cysteine dd18d2b775 Properly fix NEI quantity text field behavior (#152)
* Always show quantity text box
* Increment version
* Properly fix quantity text field
2021-08-22 10:15:23 -07:00
DreamMasterXXL 1cf8f4c1d2 bump version 2021-08-14 21:44:47 +02:00
D-Cysteine a016795056 Always show quantity text box (#150) 2021-08-14 21:42:11 +02:00
Andrey f8d492e5f5 Added couple of useful events (#149)
* Added some useful events
* 2.1.8
2021-08-13 12:49:00 -07:00
TimeConqueror 8b073543b3 Added shaded libs to dev-jar 2021-08-13 12:48:31 -07:00
18 changed files with 167 additions and 72 deletions

No files matched your search

+6
View File
@@ -145,6 +145,12 @@ task devJar(type: Jar) {
from sourceSets.main.output
getArchiveClassifier().set("dev")
manifest commonManifest
configurations.shade.each { dep ->
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**'
}
}
}
// Tell the artifact system about our extra jars
+1 -1
View File
@@ -2,4 +2,4 @@ mc_version=1.7.10
forge_version=10.13.4.1614-1.7.10
ccl_version=1.1.3.138
ccc_version=1.0.7.+
mod_version=2.1.7-GTNH
mod_version=2.1.11-GTNH
+1 -8
View File
@@ -136,14 +136,7 @@ public class ItemPanel extends Widget {
}
public int getHeight(GuiContainer gui) {
return gui.height - 15 - y + getHightAdjustment();
}
public int getHightAdjustment() {
int hAdj = 0;
if (!canPerformAction("item"))
hAdj += 15;
return hAdj;
return gui.height - 15 - y;
}
public int getWidth(GuiContainer gui) {
+9 -15
View File
@@ -7,30 +7,25 @@ public class ItemQuantityField extends TextField
centered = true;
}
// Find a way to work this this back in
public boolean isValid(String string) {
if (string.equals(""))
return true;
try {
return Integer.parseInt(string) >= 0;
} catch (NumberFormatException nfe) {
return false;
}
}
public int intValue() {
return intValue(text());
}
public int intValue(String s) {
try {
return Integer.parseInt(s);
return Math.max(0, Integer.parseInt(s));
} catch (NumberFormatException nfe) {
return 0;
}
}
@Override
public void gainFocus() {
if (text().equals("0")) {
setText("");
}
}
@Override
public void loseFocus() {
setText(Integer.toString(NEIClientConfig.getItemQuantity()));
@@ -38,7 +33,6 @@ public class ItemQuantityField extends TextField
@Override
public void onTextChange(String oldText) {
if (intValue(oldText) != intValue())//hacky recursion stopper
NEIClientUtils.setItemQuantity(intValue());
NEIClientUtils.setItemQuantity(intValue());
}
}
+5 -22
View File
@@ -423,7 +423,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
LayoutManager.quantity.setText(Integer.toString(quantity));
return true;
}
};
@@ -440,7 +440,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
LayoutManager.quantity.setText(Integer.toString(quantity));
return true;
}
};
@@ -626,8 +626,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
@Override
public void load(GuiContainer gui) {
if (isEnabled()) {
setInputFocused(null);
if(!itemsLoaded) {
ItemList.loadItems.restart();
itemsLoaded = true;
@@ -673,11 +671,9 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
addWidget(itemPanel);
itemPanel.setVisible();
if (canPerformAction("item")) {
addWidget(more);
addWidget(less);
addWidget(quantity);
}
addWidget(more);
addWidget(less);
addWidget(quantity);
}
if (visiblity.showBookmarkPanel) {
@@ -764,19 +760,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
return itemPanel.draggedStack == null;
}
public static Widget getInputFocused() {
return inputFocused;
}
public static void setInputFocused(Widget widget) {
if (inputFocused != null)
inputFocused.loseFocus();
inputFocused = widget;
if (inputFocused != null)
inputFocused.gainFocus();
}
@Override
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
if (overlayRenderer != null)
+4
View File
@@ -24,6 +24,7 @@ import codechicken.nei.config.OptionTextField;
import codechicken.nei.config.OptionToggleButton;
import codechicken.nei.config.OptionToggleButtonBoubs;
import codechicken.nei.config.OptionUtilities;
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.obfuscator.ObfuscationRun;
@@ -33,6 +34,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.storage.SaveFormatComparator;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
@@ -297,6 +299,8 @@ public class NEIClientConfig {
logger.error("Failed to Load " + clazz.getName(), e);
}
}
MinecraftForge.EVENT_BUS.post(new NEIConfigsLoadedEvent());
}
}.start();
ItemSorter.loadConfig();
-1
View File
@@ -352,7 +352,6 @@ public class NEIClientUtils extends NEIServerUtils
public static void setItemQuantity(int i) {
world.nbt.setInteger("quantity", i);
world.saveNBT();
LayoutManager.quantity.setText(Integer.toString(i));
}
public static GuiContainer getGuiContainer() {
+4 -1
View File
@@ -79,6 +79,7 @@ public abstract class TextField extends Widget
if (!focused())
return false;
String oldText = text();
boolean handled = field.textboxKeyTyped(keyChar, keyID);
if(!handled) {
if (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_NUMPADENTER || keyID == Keyboard.KEY_ESCAPE) {
@@ -88,7 +89,7 @@ public abstract class TextField extends Widget
}
if(handled) {
onTextChange(text());
onTextChange(oldText);
}
return handled;
@@ -120,8 +121,10 @@ public abstract class TextField extends Widget
if (focus) {
previousKeyboardRepeatEnabled = Keyboard.areRepeatEventsEnabled();
Keyboard.enableRepeatEvents(true);
gainFocus();
} else {
Keyboard.enableRepeatEvents(previousKeyboardRepeatEnabled);
loseFocus();
}
}
@@ -55,8 +55,11 @@ public class ThreadOperationTimer extends Thread
while (thread.isAlive()) {
synchronized (this) {
if (operation != null && System.currentTimeMillis() - opTime > limit)
thread.stop(new TimeoutException("Operation took too long", operation));
if (operation != null && System.currentTimeMillis() - opTime > limit) {
// Thread.stop(Throwable) is hard-deprecated and IntelliJ complains about it.
//thread.stop(new TimeoutException("Operation took too long", operation));
thread.stop();
}
}
try {
Thread.sleep(50);
@@ -36,7 +36,7 @@ public class HandlerDumper extends DataDumper
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<>();
for (IRecipeHandler handler : GuiUsageRecipe.usagehandlers) {
final String handlerName = handler.toString().split("@")[0];
final String handlerName = handler.getHandlerId();
final String handlerId = Objects.firstNonNull(handler instanceof TemplateRecipeHandler ? ((TemplateRecipeHandler)handler).getOverlayIdentifier() : null, "null");
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, handlerId);
@@ -0,0 +1,15 @@
package codechicken.nei.event;
import codechicken.nei.api.IConfigureNEI;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.common.MinecraftForge;
/**
* Event is posted from <font color=red>NEI Plugin Loader Thread</font> after all {@link IConfigureNEI} were loaded.
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class NEIConfigsLoadedEvent extends Event {
}
@@ -0,0 +1,36 @@
package codechicken.nei.event;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
import codechicken.nei.recipe.IRecipeHandler;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.common.MinecraftForge;
import java.util.function.Consumer;
/**
* Event is posted every time the handler infos got registered or reloaded.
* During it, you can safely register your custom handler info.
*
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class NEIRegisterHandlerInfosEvent extends Event {
public void registerHandlerInfo(String handlerName, String modName, String modId, Consumer<HandlerInfo.Builder> builder) {
HandlerInfo.Builder b = new HandlerInfo.Builder(handlerName, 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 {}", info.getHandlerName());
}
}
public void registerHandlerInfo(Class<? extends IRecipeHandler> handlerClazz, String modName, String modId, Consumer<HandlerInfo.Builder> builder) {
registerHandlerInfo(handlerClazz.getName(), modName, modId, builder);
}
}
@@ -54,12 +54,11 @@ public class GuiCraftingRecipe extends GuiRecipe
}
public static void registerRecipeHandler(ICraftingHandler handler) {
final Class<? extends ICraftingHandler> handlerClass = handler.getClass();
if(craftinghandlers.stream().anyMatch(h -> h.getClass() == handlerClass) || serialCraftingHandlers.stream().anyMatch(h -> h.getClass() == handlerClass))
final String handlerId = handler.getHandlerId();
if(craftinghandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialCraftingHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
return;
final String handlerClassStr = handlerClass.getName();
if(NEIClientConfig.serialHandlers.contains(handlerClassStr))
if(NEIClientConfig.serialHandlers.contains(handlerId))
serialCraftingHandlers.add(handler);
else
craftinghandlers.add(handler);
+1 -3
View File
@@ -299,16 +299,14 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
setRecipePage(--recipetype);
}
public HandlerInfo getHandlerInfo(IRecipeHandler handler) {
final String handlerName = handler.toString().split("@")[0];
final String handlerID;
if(handler instanceof TemplateRecipeHandler) {
handlerID = (((TemplateRecipeHandler)handler).getOverlayIdentifier());
} else {
handlerID = null;
}
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, handlerID);
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handler.getHandlerId(), handlerID);
if (info == null)
return GuiRecipeTab.DEFAULT_HANDLER_INFO;
+5 -3
View File
@@ -5,11 +5,13 @@ import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.Widget;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.event.NEIRegisterHandlerInfosEvent;
import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.Loader;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.MinecraftForge;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
@@ -19,7 +21,6 @@ import org.lwjgl.opengl.GL12;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -59,7 +60,7 @@ public abstract class GuiRecipeTab extends Widget {
this.w = getWidth();
this.h = getHeight();
this.handler = handler;
this.handlerName = handler.toString().split("@")[0];
this.handlerName = handler.getHandlerId();
this.guiRecipe = guiRecipe;
this.selected = false;
@@ -259,9 +260,10 @@ public abstract class GuiRecipeTab extends Widget {
} catch (Exception e) {
NEIClientConfig.logger.info("Error parsing CSV");
e.printStackTrace();
}
NEIClientConfig.logger.info("Sending {}", NEIRegisterHandlerInfosEvent.class.getSimpleName());
MinecraftForge.EVENT_BUS.post(new NEIRegisterHandlerInfosEvent());
}
private static HandlerInfo getDefaultHandlerInfo() {
@@ -54,12 +54,11 @@ public class GuiUsageRecipe extends GuiRecipe
}
public static void registerUsageHandler(IUsageHandler handler) {
final Class<? extends IUsageHandler> handlerClass = handler.getClass();
if(usagehandlers.stream().anyMatch(h -> h.getClass() == handlerClass) || serialUsageHandlers.stream().anyMatch(h -> h.getClass() == handlerClass))
final String handlerId = handler.getHandlerId();
if(usagehandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialUsageHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
return;
final String handlerClassStr = handlerClass.getName();
if(NEIClientConfig.serialHandlers.contains(handlerClassStr))
if(NEIClientConfig.serialHandlers.contains(handlerId))
serialUsageHandlers.add(handler);
else
usagehandlers.add(handler);
+59 -7
View File
@@ -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,56 @@ public class HandlerInfo {
return false;
}
public void setYShift(int yShift) {
this.yShift = yShift;
}
public static class Builder {
private final HandlerInfo info;
public Builder(String handlerName, String modName, String modId) {
this.info = new HandlerInfo(handlerName, modName, modId, true, null);
setMaxRecipesPerPage(Integer.MAX_VALUE);
}
public Builder(Class<? extends IRecipeHandler> handlerClazz, String modName, String modId) {
this(handlerClazz.getName(), modName, modId);
}
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;
}
}
}
@@ -15,6 +15,15 @@ import java.util.List;
*/
public interface IRecipeHandler
{
/**
* For legacy compatibility reasons, this method's default implementation returns the class name.
*
* @return A unique identifier for this handler, used for finding duplicate handlers as well as GUI tab {@link HandlerInfo}.
*/
default String getHandlerId() {
return getClass().getName();
}
/**
*
* @return The name of this inventory.