Compare commits

...
12 Commits
Author SHA1 Message Date
D-Cysteine 4fc368135d Fix height hack and add ordering config (#165)
* Fix height hack and add ordering config

* Use AutoCloseable for height hack

* Address comments
2021-10-16 19:31:43 +02:00
D-Cysteine 58117fa368 Some changes to NEI that are needed by NEI Custom Diagram (#163)
* Add IRecipeHandler support for handling mouse scrollwheel
* Add accessors for handler and recipe indices
* Make Shift+R not be handled as U
* Clean up redundant code
2021-09-30 21:17:14 -07:00
Prometheus0000 db339e94f4 Add yshifts 2021-09-30 21:14:57 -07:00
Jason Mitchell 7126a6d3b0 Bump mod version 2021-09-24 16:46:02 -07:00
D-Cysteine b00f4d1514 Add back in removed unused public methods, which were actually used by some NEI add-ons (#162)
* Fix compatibility with add-ons by re-adding unused public methods
2021-09-24 06:50:34 -07:00
GlodBlock 5b3a255be9 attampt to fix imc (#161)
* attampt to fix imc
2021-09-22 23:38:53 -07:00
Glease 65710c959a Prevent the load of client only classes on dedicated servers 2021-09-15 21:49:58 -07:00
makamys 95ee685b93 Preserve BossStatus#hasColorModifier when rendering spawners
Fixes wither spawner dimming screen (https://github.com/Chicken-Bones/NotEnoughItems/issues/80)
2021-09-14 12:01:36 -07:00
Glease 888f86f2da Remove IMC hack 2021-08-26 12:21:46 -07:00
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
21 changed files with 464 additions and 196 deletions

No files matched your search

+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.9-GTNH
mod_version=2.1.14-GTNH
+7 -7
View File
@@ -22,14 +22,14 @@ WayofTime.alchemicalWizardry.client.nei.NEIAltarRecipeHandler,Blood Magic,AWWayo
WayofTime.alchemicalWizardry.client.nei.NEIBindingRitualHandler,Blood Magic,AWWayofTime:sacrificialKnife,,AWWayofTime,TRUE,,,50,,6,,,,,,
WayofTime.alchemicalWizardry.client.nei.NEIBloodOrbShapedHandler,Blood Magic,AWWayofTime:AlchemicalWizardrybloodRune:3,,AWWayofTime,TRUE,,,65,,5,,,,,,
WayofTime.alchemicalWizardry.client.nei.NEIBloodOrbShapelessHandler,Blood Magic,AWWayofTime:AlchemicalWizardrybloodRune:4,,AWWayofTime,TRUE,,,65,,5,,,,,,
bw.fuels.acidgens,BartWorks,gregtech:gt.blockmachines:12726,,bartworks,TRUE,,,145,,2,,,,,,
bw.recipe.cal,BartWorks,gregtech:gt.blockmachines:12735,,bartworks,TRUE,,,135,,2,,,,,,
bw.fuels.acidgens,BartWorks,gregtech:gt.blockmachines:12726,,bartworks,TRUE,,6,145,,2,,,,,,
bw.recipe.cal,BartWorks,gregtech:gt.blockmachines:12735,,bartworks,TRUE,,6,135,,2,,,,,,
gg.recipe.naquadah_reactor,Good Generator,gregtech:gt.blockmachines:12732,,GoodGenerator,TRUE,,,145,,1,,,,,,
gg.recipe.naquadah_fuel_refine_factory,Good Generator,gregtech:gt.blockmachines:16999,,GoodGenerator,TRUE,,,145,,1,,,,,,
com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioLabHandler,BartWorks,gregtech:gt.blockmachines:12699,,bartworks,TRUE,,,145,,2,,,,,,
com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioVatHandler,BartWorks,gregtech:gt.blockmachines:12712,,bartworks,TRUE,,,140,,2,,,,,,
com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioLabHandler,BartWorks,gregtech:gt.blockmachines:12699,,bartworks,TRUE,,6,145,,2,,,,,,
com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioVatHandler,BartWorks,gregtech:gt.blockmachines:12712,,bartworks,TRUE,,6,140,,2,,,,,,
com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_OreHandler,BartWorks,bartworks:bw.blockores.01:89,,bartworks,TRUE,,,135,,2,,,,,,
gt.recipe.electricimplosioncompressor,BartWorks,gregtech:gt.blockmachines:12734,,bartworks,TRUE,,,135,,2,,,,,,
gt.recipe.electricimplosioncompressor,BartWorks,gregtech:gt.blockmachines:12734,,bartworks,TRUE,,6,135,,2,,,,,,
net.bdew.neiaddons.botany.flowers.FlowerBreedingHandler,Botany,Botany:flower,,Botany,TRUE,,,65,,5,,,,,,
buildcraft.compat.nei.RecipeHandlerRefinery,BuildCraft,BuildCraft|Factory:refineryBlock,,BuildCraft|Factory,TRUE,,,60,,5,,,,,,There's only 2 recipes though
buildcraft.compat.nei.RecipeHandlerAssemblyTable,BuildCraft,BuildCraft|Silicon:laserTableBlock,,BuildCraft|Silicon,TRUE,,,100,,3,,,,,,
@@ -170,7 +170,7 @@ ic2.neiIntegration.core.recipehandler.BlockCutterRecipeHandler,IndustrialCraft 2
ic2.neiIntegration.core.recipehandler.CentrifugeRecipeHandler,IndustrialCraft 2,IC2:blockMachine2:3,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.CompressorRecipeHandler,IndustrialCraft 2,IC2:blockMachine:5,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.ExtractorRecipeHandler,IndustrialCraft 2,IC2:blockMachine:4,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler,IndustrialCraft 2,IC2:blockMachine:6,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler,IndustrialCraft 2,IC2:blockMachine:6,,IC2,TRUE,,,75,,4,,,,,,
ic2.neiIntegration.core.recipehandler.LatheRecipeHandler,IndustrialCraft 2,IC2:blockMachine3:8,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.MaceratorRecipeHandler,IndustrialCraft 2,IC2:blockMachine:3,,IC2,TRUE,,,65,,5,,,,,,
ic2.neiIntegration.core.recipehandler.MetalFormerRecipeHandlerCutting,IndustrialCraft 2,IC2:blockMachine2:4,,IC2,TRUE,,,55,,6,,,,,,
@@ -448,4 +448,4 @@ neresources.nei.NEIDungeonHandler,Not Enough Resources,minecraft:chest,,neresour
neresources.nei.NEIEnchantmentHandler,Not Enough Resources,minecraft:anvil,,neresources,TRUE,,,130,166,2,,,,,,
neresources.nei.NEIMobHandler,Not Enough Resources,minecraft:skull:4,,neresources,TRUE,,,130,166,2,,,,,,
neresources.nei.NEIOreHandler,Not Enough Resources,minecraft:diamond_ore,,neresources,TRUE,,,65,166,5,,,,,,
neresources.nei.NEIPlantHandler,Not Enough Resources,minecraft:wheat,,neresources,TRUE,,,130,166,2,,,,,,
neresources.nei.NEIPlantHandler,Not Enough Resources,minecraft:wheat,,neresources,TRUE,,,130,166,2,,,,,,
1 handler modName itemName nbtInfo modId modRequired excludedModId yShift handlerHeight handlerWidth maxRecipesPerPage imageResource imageX imageY imageWidth imageHeight itemNotes
22 WayofTime.alchemicalWizardry.client.nei.NEIBindingRitualHandler Blood Magic AWWayofTime:sacrificialKnife AWWayofTime TRUE 50 6
23 WayofTime.alchemicalWizardry.client.nei.NEIBloodOrbShapedHandler Blood Magic AWWayofTime:AlchemicalWizardrybloodRune:3 AWWayofTime TRUE 65 5
24 WayofTime.alchemicalWizardry.client.nei.NEIBloodOrbShapelessHandler Blood Magic AWWayofTime:AlchemicalWizardrybloodRune:4 AWWayofTime TRUE 65 5
25 bw.fuels.acidgens BartWorks gregtech:gt.blockmachines:12726 bartworks TRUE 6 145 2
26 bw.recipe.cal BartWorks gregtech:gt.blockmachines:12735 bartworks TRUE 6 135 2
27 gg.recipe.naquadah_reactor Good Generator gregtech:gt.blockmachines:12732 GoodGenerator TRUE 145 1
28 gg.recipe.naquadah_fuel_refine_factory Good Generator gregtech:gt.blockmachines:16999 GoodGenerator TRUE 145 1
29 com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioLabHandler BartWorks gregtech:gt.blockmachines:12699 bartworks TRUE 6 145 2
30 com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_BioVatHandler BartWorks gregtech:gt.blockmachines:12712 bartworks TRUE 6 140 2
31 com.github.bartimaeusnek.bartworks.neiHandler.BW_NEI_OreHandler BartWorks bartworks:bw.blockores.01:89 bartworks TRUE 135 2
32 gt.recipe.electricimplosioncompressor BartWorks gregtech:gt.blockmachines:12734 bartworks TRUE 6 135 2
33 net.bdew.neiaddons.botany.flowers.FlowerBreedingHandler Botany Botany:flower Botany TRUE 65 5
34 buildcraft.compat.nei.RecipeHandlerRefinery BuildCraft BuildCraft|Factory:refineryBlock BuildCraft|Factory TRUE 60 5 There's only 2 recipes though
35 buildcraft.compat.nei.RecipeHandlerAssemblyTable BuildCraft BuildCraft|Silicon:laserTableBlock BuildCraft|Silicon TRUE 100 3
170 ic2.neiIntegration.core.recipehandler.CentrifugeRecipeHandler IndustrialCraft 2 IC2:blockMachine2:3 IC2 TRUE 65 5
171 ic2.neiIntegration.core.recipehandler.CompressorRecipeHandler IndustrialCraft 2 IC2:blockMachine:5 IC2 TRUE 65 5
172 ic2.neiIntegration.core.recipehandler.ExtractorRecipeHandler IndustrialCraft 2 IC2:blockMachine:4 IC2 TRUE 65 5
173 ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler IndustrialCraft 2 IC2:blockMachine:6 IC2 TRUE 65 75 5 4
174 ic2.neiIntegration.core.recipehandler.LatheRecipeHandler IndustrialCraft 2 IC2:blockMachine3:8 IC2 TRUE 65 5
175 ic2.neiIntegration.core.recipehandler.MaceratorRecipeHandler IndustrialCraft 2 IC2:blockMachine:3 IC2 TRUE 65 5
176 ic2.neiIntegration.core.recipehandler.MetalFormerRecipeHandlerCutting IndustrialCraft 2 IC2:blockMachine2:4 IC2 TRUE 55 6
448 neresources.nei.NEIEnchantmentHandler Not Enough Resources minecraft:anvil neresources TRUE 130 166 2
449 neresources.nei.NEIMobHandler Not Enough Resources minecraft:skull:4 neresources TRUE 130 166 2
450 neresources.nei.NEIOreHandler Not Enough Resources minecraft:diamond_ore neresources TRUE 65 166 5
451 neresources.nei.NEIPlantHandler Not Enough Resources minecraft:wheat neresources TRUE 130 166 2
+97 -1
View File
@@ -5,6 +5,8 @@ import codechicken.core.GuiModListScroll;
import codechicken.lib.packet.PacketCustom;
import codechicken.nei.api.API;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.GuiRecipeTab;
import com.google.common.collect.Lists;
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@@ -24,12 +26,19 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.io.IOUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -43,6 +52,21 @@ public class ClientHandler
private static String[] defaultSerialHandlers = {
"WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler"
};
private static String[] defaultHeightHackHandlers = {
"ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler",
"tconstruct.plugins.nei.RecipeHandlerAlloying",
"tconstruct.plugins.nei.RecipeHandlerCastingBasin",
"tconstruct.plugins.nei.RecipeHandlerCastingTable",
"tconstruct.plugins.nei.RecipeHandlerMelting",
};
private static String[] defaultHandlerOrdering = {
"# Each line in this file should either be a comment (starts with '#') or an ordering.",
"# Ordering lines are <handler ID>,<ordering number>.",
"# Handlers will be sorted in order of number ascending, so smaller numbers first.",
"# Any handlers that are missing from this file will be assigned to 0.",
"# Negative numbers are fine.",
"# If you delete this file, it will be regenerated with all registered handler IDs.",
};
private static ClientHandler instance;
private ArrayList<EntityItem> SMPmagneticItems = new ArrayList<>();
@@ -128,6 +152,7 @@ public class ClientHandler
public static void preInit() {
loadSerialHandlers();
loadHeightHackHandlers();
ItemInfo.preInit();
}
@@ -148,7 +173,26 @@ public class ClientHandler
} catch (IOException e) {
NEIClientConfig.logger.error("Failed to load serial handlers from file {}", file, e);
}
}
public static void loadHeightHackHandlers() {
File file = NEIClientConfig.heightHackHandlersFile;
if (!file.exists()) {
try (FileWriter writer = new FileWriter(file)) {
NEIClientConfig.logger.info("Creating default height hack handlers list {}", file);
Collection<String> toSave = Loader.isModLoaded("dreamcraft") ? Collections.singletonList("") : Arrays.asList(defaultHeightHackHandlers);
IOUtils.writeLines(toSave, "\n", writer);
} catch (IOException e) {
NEIClientConfig.logger.error("Failed to save default height hack handlers list to file {}", file, e);
}
}
try (FileReader reader = new FileReader(file)) {
NEIClientConfig.logger.info("Loading height hack handlers from file {}", file);
NEIClientConfig.heightHackHandlers = new HashSet<>(IOUtils.readLines(reader));
} catch (IOException e) {
NEIClientConfig.logger.error("Failed to load height hack handlers from file {}", file, e);
}
}
public static void load() {
@@ -164,6 +208,58 @@ public class ClientHandler
WorldOverlayRenderer.load();
}
public static void postInit() {
loadHandlerOrdering();
}
public static void loadHandlerOrdering() {
File file = NEIClientConfig.handlerOrderingFile;
if (!file.exists()) {
try (FileWriter writer = new FileWriter(file)) {
NEIClientConfig.logger.info("Creating default handler ordering CSV {}", file);
List<String> toWrite = Lists.newArrayList(defaultHandlerOrdering);
GuiRecipeTab.handlerMap.keySet().stream()
.sorted()
.forEach(handlerId -> toWrite.add(String.format("%s,0", handlerId)));
IOUtils.writeLines(toWrite, "\n", writer);
} catch (IOException e) {
NEIClientConfig.logger.error("Failed to save default handler ordering to file {}", file, e);
}
}
URL url;
try {
url = file.toURI().toURL();
} catch (MalformedURLException e) {
NEIClientConfig.logger.info("Invalid URL for handler ordering CSV.");
e.printStackTrace();
return;
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
NEIClientConfig.logger.info("Loading handler ordering from file {}", file);
CSVParser csvParser = CSVFormat.EXCEL.withCommentMarker('#').parse(reader);
for (CSVRecord record : csvParser) {
final String handlerId = record.get(0);
int ordering;
try {
ordering = Integer.parseInt(record.get(1));
} catch (NumberFormatException e) {
NEIClientConfig.logger.error("Error parsing CSV record {}: {}", record, e);
continue;
}
NEIClientConfig.handlerOrdering.put(handlerId, ordering);
}
} catch (Exception e) {
NEIClientConfig.logger.info("Error parsing CSV");
e.printStackTrace();
}
}
@SubscribeEvent
public void tickEvent(TickEvent.ClientTickEvent event) {
if(event.phase == Phase.END)
+9 -15
View File
@@ -7,30 +7,25 @@ public class ItemQuantityField extends TextField
centered = true;
}
// Find a way to work 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());
}
}
+6 -2
View File
@@ -73,7 +73,9 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
{
private static LayoutManager instance;
/** Note: this variable isn't actually used by this mod, but NEI add-ons might need it. */
private static Widget inputFocused;
/**
* Sorted bottom first
*/
@@ -423,7 +425,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
LayoutManager.quantity.setText(Integer.toString(quantity));
return true;
}
};
@@ -440,7 +442,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
if (quantity < 0)
quantity = 0;
setItemQuantity(quantity);
LayoutManager.quantity.setText(Integer.toString(quantity));
return true;
}
};
@@ -762,10 +764,12 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
return itemPanel.draggedStack == null;
}
/** Note: this method isn't actually used by this mod, but NEI add-ons might need it. */
public static Widget getInputFocused() {
return inputFocused;
}
/** Note: this method isn't actually used by this mod, but NEI add-ons might need it. */
public static void setInputFocused(Widget widget) {
if (inputFocused != null)
inputFocused.loseFocus();
+33 -2
View File
@@ -26,8 +26,11 @@ import codechicken.nei.config.OptionToggleButtonBoubs;
import codechicken.nei.config.OptionUtilities;
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import codechicken.obfuscator.ObfuscationRun;
import com.google.common.base.Objects;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
@@ -40,8 +43,11 @@ import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import java.io.File;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
public class NEIClientConfig {
private static boolean configLoaded;
@@ -56,10 +62,35 @@ public class NEIClientConfig {
public static final File bookmarkFile = new File(configDir, "bookmarks.ini");
public static final File handlerFile = new File(configDir, "handlers.csv");
public static final File serialHandlersFile = new File(configDir, "serialhandlers.cfg");
public static final File heightHackHandlersFile = new File(configDir, "heighthackhandlers.cfg");
public static final File handlerOrderingFile = new File(configDir, "handlerordering.csv");
// Set of handlers that need to be run in serial
public static HashSet<String> serialHandlers = new HashSet<>();
public static HashSet<String> serialHandlers = new HashSet<>();
// Set of handler ID of handlers that need the hack in GuiRecipe.startHeightHack().
public static HashSet<String> heightHackHandlers = new HashSet<>();
// Map of handler ID to sort order.
// Handlers will be sorted in ascending order, so smaller numbers show up earlier.
// Any handler not in the map will be assigned to 0, and negative numbers are fine.
public static HashMap<String, Integer> handlerOrdering = new HashMap<>();
// Function that extracts the handler ID from a handler, with special logic for
// TemplateRecipeHandler: prefer using the overlay ID if it exists.
public static final Function<IRecipeHandler, String> HANDLER_ID_FUNCTION =
handler -> handler instanceof TemplateRecipeHandler
? Objects.firstNonNull(
((TemplateRecipeHandler) handler).getOverlayIdentifier(),
handler.getHandlerId())
: handler.getHandlerId();
// Comparator that compares handlers using the handlerOrdering map.
public static final Comparator<IRecipeHandler> HANDLER_COMPARATOR =
Comparator.comparingInt(
handler -> handlerOrdering.getOrDefault(
HANDLER_ID_FUNCTION.apply(handler), 0));
public static ItemStack[] creativeInv;
-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() {
+6 -18
View File
@@ -6,8 +6,6 @@ import codechicken.nei.api.IConfigureNEI;
import codechicken.nei.asm.NEICorePlugin;
import codechicken.nei.config.IMCHandler;
import codechicken.nei.recipe.GuiRecipeTab;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.client.FMLFileResourcePack;
@@ -18,15 +16,14 @@ import cpw.mods.fml.common.MetadataCollection;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.VersionParser;
import cpw.mods.fml.common.versioning.VersionRange;
import net.minecraft.util.EnumChatFormatting;
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -102,24 +99,15 @@ public class NEIModContainer extends DummyModContainer
public void postInit(FMLPostInitializationEvent event) {
if (CommonUtils.isClient())
GuiRecipeTab.loadHandlerInfo();
handleIMCMessages();
ClientHandler.postInit();
}
@SuppressWarnings("unchecked")
private void handleIMCMessages() {
try {
/* Pay no attention to these unholy hacks:
* NEI Apparently doesn't have a registered mod container, so let's use some reflection to simulate what `fetchRuntimeMessages` does
*/
Field modMessagesField = FMLInterModComms.class.getDeclaredField("modMessages");
modMessagesField.setAccessible(true);
IMCHandler.processIMC(ImmutableList.copyOf(((ArrayListMultimap<String, FMLInterModComms.IMCMessage>)modMessagesField.get(FMLInterModComms.class)).removeAll("NotEnoughItems")));
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
@Subscribe
public void handleIMCMessages(FMLInterModComms.IMCEvent event) {
IMCHandler.processIMC(event.getMessages());
}
@Override
public VersionRange acceptableMinecraftVersionRange() {
return VersionParser.parseRange(CodeChickenCorePlugin.mcVersion);
+2
View File
@@ -33,6 +33,7 @@ public class SpawnerRenderer implements IItemRenderer
String bossName = BossStatus.bossName;
int bossTimeout = BossStatus.statusBarTime;
boolean bossHasColorModifier = BossStatus.hasColorModifier;
try
{
World world = NEIClientUtils.mc().theWorld;
@@ -66,6 +67,7 @@ public class SpawnerRenderer implements IItemRenderer
}
BossStatus.bossName = bossName;
BossStatus.statusBarTime = bossTimeout;
BossStatus.hasColorModifier = bossHasColorModifier;
}
@SuppressWarnings("incomplete-switch")
+2
View File
@@ -121,8 +121,10 @@ public abstract class TextField extends Widget
if (focus) {
previousKeyboardRepeatEnabled = Keyboard.areRepeatEventsEnabled();
Keyboard.enableRepeatEvents(true);
gainFocus();
} else {
Keyboard.enableRepeatEvents(previousKeyboardRepeatEnabled);
loseFocus();
}
}
@@ -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);
+68 -57
View File
@@ -1,11 +1,13 @@
package codechicken.nei.config;
import codechicken.core.CommonUtils;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
@@ -17,69 +19,78 @@ public class IMCHandler {
for (FMLInterModComms.IMCMessage message : messages) {
String type = message.key;
if (type == null || type.isEmpty()) continue;
if(type.equals("registerHandlerInfo")) {
if (!message.isNBTMessage()) {
logInvalidMessage(message, "NBT");
continue;
if (CommonUtils.isClient()) {
if (type.equals("registerHandlerInfo")) {
handleRegisterHandlerInfo(message);
} else if (type.equals("removeHandlerInfo")) {
handleRemoveHandlerInfo(message);
}
final NBTTagCompound tag = message.getNBTValue();
final String handler = tag.getString("handler");
NEIClientConfig.logger.info("Processing registerHandlerInfo `" + handler + "` from " + message.getSender());
final String modName = tag.getString("modName");
final String modId = tag.getString("modId");
final boolean requiresMod = tag.getBoolean("modRequired");
final String excludedModId = tag.hasKey("excludedModId") ? tag.getString("excludedModId") : null;
if(handler.equals("") || modName.equals("") || modId.equals("")) {
NEIClientConfig.logger.warn("Missing relevant information to registerHandlerInfo!");
continue;
}
if (requiresMod && !Loader.isModLoaded(modId)) continue;
if (excludedModId != null && Loader.isModLoaded(excludedModId)) continue;
HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId);
final String imageResource = tag.hasKey("imageResource") ? tag.getString("imageResource") : null;
if(imageResource != null && !imageResource.equals("")) {
info.setImage(imageResource, tag.getInteger("imageX"), tag.getInteger("imageY"), tag.getInteger("imageWidth"), tag.getInteger("imageHeight"));
}
if(!info.hasImageOrItem()) {
final String itemName = tag.getString("itemName");
if (itemName != null && !itemName.equals("")) {
info.setItem(itemName, tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null);
}
}
final int yShift = tag.hasKey("yShift") ? tag.getInteger("yShift") : 0;
info.setYShift(yShift);
try {
final int imageHeight = tag.hasKey("handlerHeight") ? tag.getInteger("handlerHeight") : HandlerInfo.DEFAULT_HEIGHT;
final int imageWidth = tag.hasKey("handlerWidth") ? tag.getInteger("handlerWidth") : HandlerInfo.DEFAULT_WIDTH;
final int maxRecipesPerPage = tag.hasKey("maxRecipesPerPage") ? tag.getInteger("maxRecipesPerPage") : HandlerInfo.DEFAULT_MAX_PER_PAGE;
info.setHandlerDimensions(imageHeight, imageWidth, maxRecipesPerPage);
} catch (NumberFormatException ignored) {
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
}
GuiRecipeTab.handlerMap.remove(handler);
GuiRecipeTab.handlerMap.put(handler, info);
} else if(type.equals("removeHandlerInfo")) {
if (!message.isNBTMessage()) {
logInvalidMessage(message, "NBT");
continue;
}
final NBTTagCompound tag = message.getNBTValue();
final String handler = tag.getString("handler");
NEIClientConfig.logger.info("Processing removeHandlerInfo `" + handler + "` from " + message.getSender());
GuiRecipeTab.handlerMap.remove(handler);
}
}
}
private static void handleRegisterHandlerInfo(IMCMessage message) {
if (!message.isNBTMessage()) {
logInvalidMessage(message, "NBT");
return;
}
final NBTTagCompound tag = message.getNBTValue();
final String handler = tag.getString("handler");
NEIClientConfig.logger.info("Processing registerHandlerInfo `" + handler + "` from " + message.getSender());
final String modName = tag.getString("modName");
final String modId = tag.getString("modId");
final boolean requiresMod = tag.getBoolean("modRequired");
final String excludedModId = tag.hasKey("excludedModId") ? tag.getString("excludedModId") : null;
if(handler.equals("") || modName.equals("") || modId.equals("")) {
NEIClientConfig.logger.warn("Missing relevant information to registerHandlerInfo!");
return;
}
if (requiresMod && !Loader.isModLoaded(modId)) return;
if (excludedModId != null && Loader.isModLoaded(excludedModId)) return;
HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId);
final String imageResource = tag.hasKey("imageResource") ? tag.getString("imageResource") : null;
if(imageResource != null && !imageResource.equals("")) {
info.setImage(imageResource, tag.getInteger("imageX"), tag.getInteger("imageY"), tag.getInteger("imageWidth"), tag.getInteger("imageHeight"));
}
if(!info.hasImageOrItem()) {
final String itemName = tag.getString("itemName");
if (itemName != null && !itemName.equals("")) {
info.setItem(itemName, tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null);
}
}
final int yShift = tag.hasKey("yShift") ? tag.getInteger("yShift") : 0;
info.setYShift(yShift);
try {
final int imageHeight = tag.hasKey("handlerHeight") ? tag.getInteger("handlerHeight") : HandlerInfo.DEFAULT_HEIGHT;
final int imageWidth = tag.hasKey("handlerWidth") ? tag.getInteger("handlerWidth") : HandlerInfo.DEFAULT_WIDTH;
final int maxRecipesPerPage = tag.hasKey("maxRecipesPerPage") ? tag.getInteger("maxRecipesPerPage") : HandlerInfo.DEFAULT_MAX_PER_PAGE;
info.setHandlerDimensions(imageHeight, imageWidth, maxRecipesPerPage);
} catch (NumberFormatException ignored) {
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
}
GuiRecipeTab.handlerAdderFromIMC.remove(handler);
GuiRecipeTab.handlerAdderFromIMC.put(handler, info);
}
private static void handleRemoveHandlerInfo(IMCMessage message) {
if (!message.isNBTMessage()) {
logInvalidMessage(message, "NBT");
return;
}
final NBTTagCompound tag = message.getNBTValue();
final String handler = tag.getString("handler");
NEIClientConfig.logger.info("Processing removeHandlerInfo `" + handler + "` from " + message.getSender());
GuiRecipeTab.handlerRemoverFromIMC.add(handler);
}
private static void logInvalidMessage(FMLInterModComms.IMCMessage message, String type) {
FMLLog.bigWarning(String.format("Received invalid IMC '%s' from %s. Not a %s Message.", message.key, message.getSender(), type));
@@ -7,6 +7,8 @@ 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.
@@ -16,12 +18,19 @@ 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(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 {}", handlerClazz.getName());
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);
}
}
@@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
@@ -44,6 +43,8 @@ public class GuiCraftingRecipe extends GuiRecipe
if (handlers.isEmpty())
return false;
handlers.sort(NEIClientConfig.HANDLER_COMPARATOR);
mc.displayGuiScreen(new GuiCraftingRecipe(prevscreen, handlers));
return true;
}
@@ -54,12 +55,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);
+106 -55
View File
@@ -36,6 +36,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOverlay, IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler {
// Background image calculations
@@ -93,6 +94,42 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
}
/**
* Many old mods assumed a fixed NEI window height of {@code 166} pixels. Now that this is no
* longer the case, their fluid mouseover handling is broken. This helper class fixes these old
* mods by hacking the {@link #height} property's value so that these old mods' calculations
* return the correct value for the new height.
*
* <p>This class is an {@link AutoCloseable} so that it can be used with try-with-resources,
* which will ensure that {@link #height} is returned to the correct value afterwards.
*/
private class HeightHack implements AutoCloseable {
private final int trueHeight;
private HeightHack() {
trueHeight = height;
if (NEIClientConfig.heightHackHandlers.contains(handler.getHandlerId())) {
// The old mods use the calculation ((height - 166) / 2) to compute the y-value of
// the top edge of the NEI window.
// guiTop is exactly that: the y-value of the top edge of the NEI window.
// So we set height to be equal to the inverse of this calculation, applied to
// guiTop, so that old mods get the right result back when they use this calculation.
height = (2 * guiTop) + 166;
// For reference, in case we ever need to modify width as well:
// the legacy calculation used for width is ((width - 176) / 2), which should
// evaluate to be equal to guiWidth (the x-value of the left edge of the NEI window).
// So if we wanted to override width as well, we'd do this:
// width = (2 * guiWidth) + 176;
}
}
@Override
public void close() {
height = trueHeight;
}
}
@Override
@SuppressWarnings("unchecked")
@@ -128,8 +165,6 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
recipeTabs.initLayout();
refreshPage();
}
@SuppressWarnings("unchecked")
@@ -172,6 +207,18 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
initOverlayButtons();
}
public IRecipeHandler getHandler() {
return handler;
}
public List<Integer> getRecipeIndices() {
final int recipesPerPage = getRecipesPerPage();
int minIndex = page * recipesPerPage;
int maxIndex = Math.min(handler.numRecipes(), (page + 1) * recipesPerPage);
return IntStream.range(minIndex, maxIndex).boxed().collect(Collectors.toList());
}
@Override
public void keyTyped(char c, int i) {
@@ -183,10 +230,11 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
if (GuiContainerManager.getManager(this).lastKeyTyped(i, c))
return;
final int recipesPerPage = getRecipesPerPage();
for (int recipe = page * recipesPerPage; recipe < handler.numRecipes() && recipe < (page + 1) * recipesPerPage; recipe++)
if (handler.keyTyped(this, c, i, recipe))
return;
try (HeightHack heightHack = new HeightHack()) {
for (int recipe : getRecipeIndices())
if (handler.keyTyped(this, c, i, recipe))
return;
}
if (i == mc.gameSettings.keyBindInventory.getKeyCode())
mc.displayGuiScreen(firstGui);
@@ -205,19 +253,38 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
@Override
protected void mouseClicked(int x, int y, int button) {
final int recipesPerPage = getRecipesPerPage();
for (int recipe = page * recipesPerPage; recipe < handler.numRecipes() && recipe < (page + 1) * recipesPerPage; recipe++)
if (handler.mouseClicked(this, button, recipe))
return;
try (HeightHack heightHack = new HeightHack()) {
for (int recipe : getRecipeIndices())
if (handler.mouseClicked(this, button, recipe))
return;
}
if (recipeTabs.mouseClicked(x, y, button))
return;
super.mouseClicked(x, y, button);
}
@Override
public void mouseScrolled(int i) {
// Height hacking is not necessary here since mouse scrolling is a new feature, added in
// GTNH NEI. So no old mods will use this. Though not hacking the height here does mean that
// the value of the height field will be different from in other mouseover methods, which
// could be confusing...
for (int recipe : getRecipeIndices())
if (handler.mouseScrolled(this, i, recipe))
return;
if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) {
if (i > 0) prevPage();
else nextPage();
}
}
@Override
protected void actionPerformed(GuiButton guibutton) {
super.actionPerformed(guibutton);
final int recipesPerPage = getRecipesPerPage();
switch (guibutton.id) {
case 0:
prevType();
@@ -233,7 +300,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
return;
}
if (overlayButtons != null && guibutton.id >= OVERLAY_BUTTON_ID_START && guibutton.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) {
overlayRecipe(page * recipesPerPage + guibutton.id - OVERLAY_BUTTON_ID_START);
overlayRecipe(page * getRecipesPerPage() + guibutton.id - OVERLAY_BUTTON_ID_START);
}
}
@@ -246,31 +313,19 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
@Override
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
final int recipesPerPage = getRecipesPerPage();
/*
* Several mods try to figure out the relative mouse position for fluid tooltips. This worked fine
* when it was a static 166.. however now that we're scaling it this no longer works. Rather than
* patching the individual mods (so that we can be as compatible as possible), we'll just fake
* the height for their tooltip rendering.
*/
// Begin Hax
final int oldHeight = this.height;
this.height = 166 + handlerInfo.getHeight() + 18 + (guiTop - 44) * 2;
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
currenttip = handler.handleTooltip(this, currenttip, i);
try (HeightHack heightHack = new HeightHack()) {
for (int i : getRecipeIndices())
currenttip = handler.handleTooltip(this, currenttip, i);
}
recipeTabs.handleTooltip(mousex, mousey, currenttip);
this.height = oldHeight;
// End Hax
return currenttip;
}
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack stack, int mousex, int mousey, List<String> currenttip) {
final int recipesPerPage = getRecipesPerPage();
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++)
// Height hacking is probably not needed as it doesn't look like any mods check mouse
// position for this method.
for (int i : getRecipeIndices())
currenttip = handler.handleItemTooltip(this, stack, currenttip, i);
return currenttip;
@@ -306,7 +361,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
} else {
handlerID = null;
}
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handler.getClass().getName(), handlerID);
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handler.getHandlerId(), handlerID);
if (info == null)
return GuiRecipeTab.DEFAULT_HANDLER_INFO;
@@ -417,21 +472,23 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
GL11.glPushMatrix();
GL11.glTranslatef(5, 32 + yShift, 0);
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
handler.drawForeground(i);
if (drawItemPresence && isMouseOverOverlayButton(i - page * recipesPerPage)
&& firstGui.inventorySlots != null) {
List<PositionedStack> ingredients = handler.getIngredientStacks(i);
if (itemPresenceCacheRecipe != i || itemPresenceCacheSlots == null || itemPresenceCacheSlots.size() != ingredients.size()) {
updateItemPresenceCache(i);
}
for (int j = 0; j < ingredients.size(); j++) {
PositionedStack stack = ingredients.get(j);
boolean isPresent = itemPresenceCacheSlots.get(j);
LayoutManager.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent);
try (HeightHack heightHack = new HeightHack()) {
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
handler.drawForeground(i);
if (drawItemPresence && isMouseOverOverlayButton(i - page * recipesPerPage)
&& firstGui.inventorySlots != null) {
List<PositionedStack> ingredients = handler.getIngredientStacks(i);
if (itemPresenceCacheRecipe != i || itemPresenceCacheSlots == null || itemPresenceCacheSlots.size() != ingredients.size()) {
updateItemPresenceCache(i);
}
for (int j = 0; j < ingredients.size(); j++) {
PositionedStack stack = ingredients.get(j);
boolean isPresent = itemPresenceCacheSlots.get(j);
LayoutManager.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent);
}
}
GL11.glTranslatef(0, handlerInfo.getHeight(), 0);
}
GL11.glTranslatef(0, handlerInfo.getHeight(), 0);
}
GL11.glPopMatrix();
}
@@ -465,9 +522,11 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
GL11.glPushMatrix();
GL11.glTranslatef(j + 5, k + 32 + yShift, 0);
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
handler.drawBackground(i);
GL11.glTranslatef(0, handlerInfo.getHeight(), 0);
try (HeightHack heightHack = new HeightHack()) {
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
handler.drawBackground(i);
GL11.glTranslatef(0, handlerInfo.getHeight(), 0);
}
}
GL11.glPopMatrix();
}
@@ -532,14 +591,6 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
return new Point(5, 32 + yShift + ((recipe % getRecipesPerPage()) * handlerInfo.getHeight()));
}
@Override
public void mouseScrolled(int i) {
if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) {
if (i > 0) prevPage();
else nextPage();
}
}
public abstract ArrayList<? extends IRecipeHandler> getCurrentRecipeHandlers();
@Override
+13 -10
View File
@@ -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;
@@ -29,12 +29,13 @@ import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.HashMap;
import java.util.List;
import java.util.*;
public abstract class GuiRecipeTab extends Widget {
public static HandlerInfo DEFAULT_HANDLER_INFO = getDefaultHandlerInfo();
public static HashMap<String, HandlerInfo> handlerMap = new HashMap<>();
public static HashMap<String, HandlerInfo> handlerAdderFromIMC = new HashMap<>();
public static Set<String> handlerRemoverFromIMC = new HashSet<>();
private final GuiRecipe guiRecipe;
private final IRecipeHandler handler;
@@ -60,7 +61,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;
@@ -177,7 +178,7 @@ public abstract class GuiRecipeTab extends Widget {
NEIClientConfig.logger.info("Loading handler info from " + (fromJar ? "JAR" : "Config"));
handlerMap.clear();
URL handlerUrl = Thread.currentThread().getContextClassLoader().getResource("assets/nei/csv/handlers.csv");
URL url;
if (fromJar) {
url = handlerUrl;
@@ -208,9 +209,8 @@ public abstract class GuiRecipeTab extends Widget {
return;
}
}
try {
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(input);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(reader);
for (CSVRecord record : csvParser) {
final String handler = record.get("handler");
final String modName = record.get("modName");
@@ -262,8 +262,11 @@ public abstract class GuiRecipeTab extends Widget {
e.printStackTrace();
}
NEIClientConfig.logger.info("Sending {}", RegisterHandlerInfosEvent.class.getSimpleName());
MinecraftForge.EVENT_BUS.post(new RegisterHandlerInfosEvent());
handlerMap.keySet().removeAll(handlerRemoverFromIMC);
handlerMap.putAll(handlerAdderFromIMC);
NEIClientConfig.logger.info("Sending {}", NEIRegisterHandlerInfosEvent.class.getSimpleName());
MinecraftForge.EVENT_BUS.post(new NEIRegisterHandlerInfosEvent());
}
private static HandlerInfo getDefaultHandlerInfo() {
@@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
@@ -44,6 +43,8 @@ public class GuiUsageRecipe extends GuiRecipe
if (handlers.isEmpty())
return false;
handlers.sort(NEIClientConfig.HANDLER_COMPARATOR);
mc.displayGuiScreen(new GuiUsageRecipe(prevscreen, handlers));
return true;
}
@@ -54,12 +55,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.
@@ -111,6 +120,7 @@ public interface IRecipeHandler
* @return true to terminate further processing of this event.
*/
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe);
/**
*
* @param gui An instance of the currentscreen
@@ -118,4 +128,15 @@ public interface IRecipeHandler
* @return true to terminate further processing of this event.
*/
public boolean mouseClicked(GuiRecipe gui, int button, int recipe);
/**
* For legacy compatibility reasons, this method has a do-nothing default implementation.
*
* @param gui An instance of the currentscreen
* @param scroll The scroll direction, {> 0 = Up, < 0 = Down}
* @return true to terminate further processing of this event.
*/
default boolean mouseScrolled(GuiRecipe gui, int scroll, int recipe) {
return false;
}
}
@@ -16,13 +16,13 @@ public class RecipeItemInputHandler implements IContainerInputHandler
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
if(stackover == null)
return false;
if(keyCode == NEIClientConfig.getKeyBinding("gui.usage") || (keyCode == NEIClientConfig.getKeyBinding("gui.recipe") && NEIClientUtils.shiftKey()))
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
if(keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
if(keyCode == NEIClientConfig.getKeyBinding("gui.bookmark")) {
NEIClientConfig.logger.debug("Adding or removing {} from bookmarks", stackover.getDisplayName());
ItemPanels.bookmarkPanel.addOrRemoveItem(stackover.copy());
@@ -639,6 +639,11 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
return false;
}
@Override
public boolean mouseScrolled(GuiRecipe gui, int scroll, int recipe) {
return false;
}
private boolean transferRect(GuiRecipe gui, int recipe, boolean usage) {
Point offset = gui.getRecipePosition(recipe);
return transferRect(gui, transferRects, offset.x, offset.y, usage);