Compare commits

..
Author SHA1 Message Date
slprimeandslprime 65652e5896 Small fixes & changes (#523)
* fix hotkeys

* code cleanup

* fix recipe tooltip overlay

* search item by original name

* overlay button refactoring

* fix subset filter

* change keyname; issue 524

* cleanup code

* move overlayformat logic

---------

Co-authored-by: slprime <[email protected]>
2024-09-01 22:19:12 +02:00
slprimeandslprime bd5e991a84 NEI Optimization (#519)
* NEI Optimization

* save setting after death

---------

Co-authored-by: slprime <[email protected]>
2024-08-29 22:14:52 +02:00
glowredman 165afa2910 Small Cleanup (#518)
* Deobfuscate parameters

* Fix generics

* Replace deprecated methods

* Add `serialVersionUID`s

* Fix static access

* Add default switch case

* Close OutputStreams

* Fix wrong variable usage

* Explicitly declare exceptions
2024-08-29 20:07:14 +02:00
glowredman 2507634196 Allow any Character to be used as Search-Prefix (#522)
* Allow any character to be used as prefix

* Enable Jabel

* Add back search mode settings and add ingame setting for prefixes

* Implement prefix redefinitions
2024-08-29 08:17:00 +02:00
37 changed files with 207 additions and 157 deletions

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ enableModernJavaSyntax = true
# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true
# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
@@ -1294,8 +1294,7 @@ public class BookmarkPanel extends PanelWidget {
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_DEPTH_TEST);
@SuppressWarnings("unchecked")
List<Slot> slots = (List<Slot>) this.gui.slotcontainer.inventorySlots;
List<Slot> slots = this.gui.slotcontainer.inventorySlots;
for (Slot slot : slots) {
if (slot != null && slot.getStack() != null) {
@@ -2501,20 +2500,19 @@ public class BookmarkPanel extends PanelWidget {
translate("bookmark.group.toggle_crafting_chain.key"),
translate("bookmark.group.toggle_crafting_chain"));
String keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.remove_recipe"), true);
String keyName = NEIClientConfig.getKeyName("gui.remove_recipe");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.remove_recipe"));
}
if (BookmarkContainerInfo.getBookmarkContainerHandler(gui) != null) {
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_pull_items"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_pull_items");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.pull_items"));
}
keyName = NEIClientConfig
.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_pull_items_ingredients"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_pull_items_ingredients");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.pull_items_ingredients"));
}
@@ -2537,20 +2535,19 @@ public class BookmarkPanel extends PanelWidget {
hotkeys.put(translate("bookmark.group.sorting.key"), translate("bookmark.group.sorting"));
}
String keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.remove_recipe"), true);
String keyName = NEIClientConfig.getKeyName("gui.remove_recipe");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.remove_recipe"));
}
if (BookmarkContainerInfo.getBookmarkContainerHandler(gui) != null) {
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_pull_items"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_pull_items");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.pull_items"));
}
keyName = NEIClientConfig
.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_pull_items_ingredients"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_pull_items_ingredients");
if (keyName != null) {
hotkeys.put(keyName, translate("bookmark.group.pull_items_ingredients"));
}
@@ -235,7 +235,6 @@ public class ClientHandler {
public static void postInit() {
loadHandlerOrdering();
loadPluginsList();
GuiContainerManager.registerReloadResourceListener();
}
@@ -358,9 +357,10 @@ public class ClientHandler {
}
};
@SuppressWarnings("serial")
CustomModLoadingErrorDisplayException e = new CustomModLoadingErrorDisplayException() {
private static final long serialVersionUID = -5593387489666663375L;
@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
Minecraft.getMinecraft().displayGuiScreen(errorGui);
@@ -116,7 +116,6 @@ public class ContainerPotionCreator extends ContainerExtended {
if (!player.worldObj.isRemote) InventoryUtils.dropOnClose(player, potionInv);
}
@SuppressWarnings("unchecked")
@Override
public void handleServerPacket(PacketCustom packet) {
ItemStack potion = potionInv.getStackInSlot(0);
@@ -60,13 +60,13 @@ public class GuiExtendedCreativeInv extends GuiContainer implements INEIGuiHandl
}
@Override
protected void handleMouseClick(Slot p_146984_1_, int p_146984_2_, int p_146984_3_, int p_146984_4_) {
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
// Hack for armor slots, because they are outside the container
if (p_146984_1_ != null && p_146984_4_ == 4 && p_146984_1_.xDisplayPosition < 0) {
p_146984_4_ = 0;
if (slotIn != null && clickType == 4 && slotIn.xDisplayPosition < 0) {
clickType = 0;
}
super.handleMouseClick(p_146984_1_, p_146984_2_, p_146984_3_, p_146984_4_);
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
}
}
+13 -2
View File
@@ -91,7 +91,19 @@ public class ItemList {
@Override
public boolean matches(ItemStack item) {
String displayName = EnumChatFormatting.getTextWithoutFormattingCodes(item.getDisplayName());
return !displayName.isEmpty() && pattern.matcher(displayName).find();
if (!displayName.isEmpty() && pattern.matcher(displayName).find()) {
return true;
}
if (item.hasDisplayName()) {
displayName = EnumChatFormatting
.getTextWithoutFormattingCodes(item.getItem().getItemStackDisplayName(item));
return !displayName.isEmpty() && pattern.matcher(displayName).find();
}
return false;
}
}
@@ -210,7 +222,6 @@ public class ItemList {
}
}
@SuppressWarnings("unchecked")
private String getTooltip(ItemStack stack) {
try {
return String.join("\n", stack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
@@ -66,7 +66,7 @@ public class ItemMobSpawner extends ItemBlock {
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List<String> list, boolean par4) {
setDefaultTag(itemstack);
int meta = itemstack.getItemDamage();
if (meta == 0) {
@@ -106,9 +106,10 @@ public class ItemMobSpawner extends ItemBlock {
public static void loadSpawners(World world) {
if (loaded) return;
loaded = true;
HashMap<Class<Entity>, String> classToStringMapping = (HashMap<Class<Entity>, String>) EntityList.classToStringMapping;
HashMap<Class<Entity>, Integer> classToIDMapping = (HashMap<Class<Entity>, Integer>) EntityList.classToIDMapping;
for (Class<Entity> eclass : classToStringMapping.keySet()) {
Map<Class<? extends Entity>, String> classToStringMapping = EntityList.classToStringMapping;
@SuppressWarnings("unchecked")
Map<Class<? extends Entity>, Integer> classToIDMapping = (Map<Class<? extends Entity>, Integer>) EntityList.classToIDMapping;
for (Class<? extends Entity> eclass : classToStringMapping.keySet()) {
if (!EntityLiving.class.isAssignableFrom(eclass)) continue;
try {
EntityLiving entityliving = (EntityLiving) eclass.getConstructor(new Class[] { World.class })
@@ -131,7 +132,7 @@ public class ItemMobSpawner extends ItemBlock {
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
if (!NEIClientConfig.hasSMPCounterPart()) list.add(new ItemStack(item));
else for (int i : IDtoNameMap.keySet()) list.add(new ItemStack(item, 1, i));
}
+3 -5
View File
@@ -73,12 +73,10 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
if (NEIClientConfig.getBooleanSetting("inventory.itemzoom.enabled")
&& NEIClientConfig.getBooleanSetting("inventory.itemzoom.helpText")) {
int key = NEIClientConfig.getKeyBinding("gui.itemzoom_toggle");
String keyName = NEIClientConfig.getKeyName("gui.itemzoom_toggle");
if (key > 0) {
String helpText = NEIClientUtils
.translate("itemzoom.toggle", NEIClientConfig.getKeyName(key, true));
@SuppressWarnings("unchecked")
if (keyName != null) {
String helpText = NEIClientUtils.translate("itemzoom.toggle", keyName);
List<String> lines = fontRenderer.listFormattedStringToWidth(helpText, this.availableAreaWidth);
for (String line : lines) {
@@ -227,7 +227,7 @@ public class NEIClientConfig {
});
tag.getTag("inventory.search.subsetsSearchMode").setComment("Search mode for Item Subsets (prefix: %)")
.getIntValue(2);
.getIntValue(1);
API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) {
@Override
@@ -631,34 +631,14 @@ public class NEIClientConfig {
return hash != Keyboard.CHAR_NONE && hash == NEIClientUtils.getKeyHash();
}
public static String getKeyName(int keyBind, boolean useHash) {
return getKeyName(keyBind, useHash, false);
}
public static String getKeyName(String keyBind) {
final int hash = getKeyBinding(keyBind);
public static String getKeyName(int keyBind, boolean useHash, boolean showOnlyHash) {
String keyText = "";
if (useHash) {
final String DELIMITER = " + ";
if ((keyBind & NEIClientUtils.CTRL_HASH) != 0) {
keyText += NEIClientUtils.translate(Minecraft.isRunningOnMac ? "key.ctrl.mac" : "key.ctrl") + DELIMITER;
}
if ((keyBind & NEIClientUtils.SHIFT_HASH) != 0) {
keyText += "SHIFT" + DELIMITER;
}
if ((keyBind & NEIClientUtils.ALT_HASH) != 0) {
keyText += "ALT" + DELIMITER;
}
if (hash == Keyboard.CHAR_NONE) {
return null;
}
if (!showOnlyHash) {
keyText += Keyboard.getKeyName(unHashKey(keyBind));
}
return keyText;
}
public static int unHashKey(int keyBind) {
return keyBind & ~(NEIClientUtils.CTRL_HASH | NEIClientUtils.SHIFT_HASH | NEIClientUtils.ALT_HASH);
return NEIClientUtils.getKeyName(hash);
}
public static void bootNEI(World world) {
@@ -681,11 +661,11 @@ public class NEIClientConfig {
NEIClientConfig.pluginsList.parallelStream().forEach(clazz -> {
try {
IConfigureNEI config = (IConfigureNEI) clazz.newInstance();
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
config.loadConfig();
NEIModContainer.plugins.add(config);
logger.debug("Loaded {}", clazz.getName());
} catch (Exception e) {
} catch (Throwable e) {
logger.error("Failed to Load {}", clazz.getName(), e);
}
});
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
@@ -450,6 +451,44 @@ public class NEIClientUtils extends NEIServerUtils {
return Keyboard.CHAR_NONE;
}
public static String getKeyHashName(int keyBind) {
StringJoiner keyText = new StringJoiner(" + ");
if ((keyBind & CTRL_HASH) != 0) {
keyText.add(translate(Minecraft.isRunningOnMac ? "key.ctrl.mac" : "key.ctrl"));
}
if ((keyBind & SHIFT_HASH) != 0) {
keyText.add(translate("key.shift"));
}
if ((keyBind & ALT_HASH) != 0) {
keyText.add(translate("key.alt"));
}
return keyText.toString();
}
public static String getKeyName(int keyBind) {
StringJoiner keyText = new StringJoiner(" + ");
String hashText = getKeyHashName(keyBind);
int keyID = unHashKey(keyBind);
if (!hashText.isEmpty()) {
keyText.add(hashText);
}
if (keyID != Keyboard.CHAR_NONE || hashText.isEmpty()) {
keyText.add(Keyboard.getKeyName(keyID));
}
return keyText.toString();
}
public static int unHashKey(int keyBind) {
return keyBind & ~(CTRL_HASH | SHIFT_HASH | ALT_HASH);
}
public static void playClickSound() {
mc().getSoundHandler()
.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
@@ -127,6 +127,7 @@ public class NEIModContainer extends DummyModContainer {
public void loadComplete(FMLLoadCompleteEvent event) {
if (CommonUtils.isClient()) {
GuiRecipeTab.loadHandlerInfo();
ClientHandler.loadPluginsList();
}
}
@@ -89,9 +89,8 @@ public class NEIServerUtils {
else return player.inventory.getStackInSlot(slot);
}
@SuppressWarnings("unchecked")
public static void deleteAllItems(EntityPlayerMP player) {
for (Slot slot : (List<Slot>) player.openContainer.inventorySlots) slot.putStack(null);
for (Slot slot : player.openContainer.inventorySlots) slot.putStack(null);
player.sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
@@ -243,18 +243,18 @@ public class SearchField extends TextField implements ItemFilterProvider {
search = search.substring(2, search.length() - 1);
} else {
final Matcher matcher = Pattern.compile("(\\?|\\*)").matcher(search);
String cleanedString = "";
StringBuilder cleanedString = new StringBuilder();
int lastEndIndex = 0;
while (matcher.find()) {
cleanedString += Pattern.quote(search.substring(lastEndIndex, matcher.start()));
cleanedString.append(Pattern.quote(search.substring(lastEndIndex, matcher.start())));
switch (matcher.group(0).charAt(0)) {
case '?':
cleanedString += ".";
cleanedString.append(".");
break;
case '*':
cleanedString += ".+?";
cleanedString.append(".+?");
break;
default:
break;
@@ -266,6 +266,8 @@ public class SearchField extends TextField implements ItemFilterProvider {
search = cleanedString + Pattern.quote(search.substring(lastEndIndex, search.length()));
}
break;
default:
break;
}
if (!search.isEmpty()) {
@@ -300,6 +302,8 @@ public class SearchField extends TextField implements ItemFilterProvider {
case 2:
text = text.replaceAll("[{}()\\[\\].+*?^$\\\\|]", "\\\\$0");
break;
default:
break;
}
if (text.contains(" ") && NEIClientConfig.getBooleanSetting("inventory.search.quoteDropItemName")) {
@@ -43,7 +43,6 @@ public class SearchTokenParser {
public ItemFilter getFilter(String searchText);
@SuppressWarnings("unchecked")
public static List<Language> getAllLanguages() {
return new ArrayList<>(Minecraft.getMinecraft().getLanguageManager().getLanguages());
}
@@ -64,7 +64,6 @@ public class SpawnerRenderer implements IItemRenderer {
BossStatus.hasColorModifier = bossHasColorModifier;
}
@SuppressWarnings("incomplete-switch")
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
switch (type) {
@@ -75,6 +74,8 @@ public class SpawnerRenderer implements IItemRenderer {
case ENTITY:
renderInventoryItem((RenderBlocks) data[0], item);
break;
default:
break;
}
}
@@ -1,6 +1,5 @@
package codechicken.nei;
import static codechicken.nei.LayoutManager.searchField;
import static codechicken.nei.NEIClientUtils.translate;
import java.awt.Point;
@@ -72,7 +71,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
if (slot < sorted.size()) {
SubsetTag tag = sorted.get(slot);
if (NEIClientUtils.shiftKey()) {
searchField.setText("%" + tag.fullname.replace(" ", ""));
LayoutManager.searchField.setText("%" + tag.fullname.replaceAll("\\s+", ""));
} else if (button == 0 && count >= 2) {
SubsetWidget.showOnly(tag);
} else {
@@ -176,7 +175,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
private SubsetTag getTag(String name) {
int idx = name.indexOf('.');
String childname = idx > 0 ? name.substring(0, idx) : name;
SubsetTag child = children.get(childname.replaceAll(" ", "").toLowerCase());
SubsetTag child = children.get(childname.replaceAll("\\s+", "").toLowerCase());
if (child == null) return null;
return idx > 0 ? child.getTag(name.substring(idx + 1)) : child;
@@ -193,7 +192,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
int idx = name.indexOf('.');
if (idx < 0) { // add or replace tag
SubsetTag prev = children.put(name.replaceAll(" ", "").toLowerCase(), tag);
SubsetTag prev = children.put(name.replaceAll("\\s+", "").toLowerCase(), tag);
if (prev != null) { // replaced, load children
tag.children = prev.children;
tag.sorted = prev.sorted;
@@ -201,10 +200,10 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
recacheChildren();
} else {
String childname = name.substring(0, idx);
SubsetTag child = children.get(childname.replaceAll(" ", "").toLowerCase());
SubsetTag child = children.get(childname.replaceAll("\\s+", "").toLowerCase());
if (child == null) {
children.put(
childname.replaceAll(" ", "").toLowerCase(),
childname.replaceAll("\\s+", "").toLowerCase(),
child = new SubsetTag(fullname == null ? childname : fullname + '.' + childname));
}
recacheChildren();
@@ -6,9 +6,9 @@ import cpw.mods.fml.common.FMLCommonHandler;
public class ThreadOperationTimer extends Thread {
@SuppressWarnings("serial")
public static class TimeoutException extends RuntimeException {
private static final long serialVersionUID = -8621458005263888185L;
public final Object operation;
public TimeoutException(String msg, Object op) {
@@ -6,21 +6,20 @@ import java.util.Optional;
import java.util.stream.Collectors;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.IRecipeHandler;
public interface IOverlayHandler {
void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift);
default List<Boolean> presenceOverlay(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
final List<Boolean> itemPresenceSlots = new ArrayList<>();
default List<ItemOverlayState> presenceOverlay(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
@SuppressWarnings("unchecked")
final List<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots).stream()
final List<ItemStack> invStacks = firstGui.inventorySlots.inventorySlots.stream()
.filter(
s -> s != null && s.getStack() != null
&& s.getStack().stackSize > 0
@@ -30,9 +29,9 @@ public interface IOverlayHandler {
for (PositionedStack stack : ingredients) {
Optional<ItemStack> used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is))
.findFirst();
.findAny();
itemPresenceSlots.add(used.isPresent());
itemPresenceSlots.add(new ItemOverlayState(stack, used.isPresent()));
if (used.isPresent()) {
ItemStack is = used.get();
@@ -191,7 +191,7 @@ public class ItemInfo {
public String[] dump(Block block, int id, String name) {
final Item item = Item.getItemFromBlock(block);
return new String[] { name, Integer.toString(id), Boolean.toString(item != null),
ItemInfo.itemOwners.get(block), block.getClass().getCanonicalName(),
ItemInfo.itemOwners.get(item), block.getClass().getCanonicalName(),
item != null ? EnumChatFormatting.getTextWithoutFormattingCodes(
GuiContainerManager.itemDisplayNameShort(new ItemStack(item))) : "null" };
}
@@ -442,7 +442,6 @@ public class ItemInfo {
addEntityEgg(EntityIronGolem.class, 0xC5C2C1, 0xffe1cc);
}
@SuppressWarnings("unchecked")
private static void addEntityEgg(Class<?> entity, int i, int j) {
int id = (Integer) EntityList.classToIDMapping.get(entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, i, j));
@@ -7,7 +7,6 @@ import java.awt.Rectangle;
import org.lwjgl.input.Keyboard;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
public class OptionKeyBind extends OptionButton {
@@ -122,8 +121,12 @@ public class OptionKeyBind extends OptionButton {
@Override
public String getButtonText() {
final int metahash = Math.max(editing ? NEIClientUtils.getMetaHash() : getValue(), 0);
return NEIClientConfig.getKeyName(metahash, useHash, editing);
if (editing) {
return NEIClientUtils.getKeyHashName(NEIClientUtils.getMetaHash());
}
return NEIClientUtils.getKeyName(Math.max(getValue(), 0));
}
@Override
@@ -10,6 +10,7 @@ public abstract class RegistryDumper<T> extends DataDumper {
super(name);
}
@SuppressWarnings("unchecked")
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<>();
@@ -17,7 +17,6 @@ import cpw.mods.fml.common.eventhandler.Event;
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@SuppressWarnings("unused")
public class NEIRegisterHandlerInfosEvent extends Event {
public void registerHandlerInfo(HandlerInfo info) {
@@ -149,7 +149,6 @@ public class GuiContainerManager {
* @param includeHandlers If true tooltip handlers will add to the item tip
* @return A list of Strings representing the text to be displayed on each line of the tool tip.
*/
@SuppressWarnings("unchecked")
public static List<String> itemDisplayNameMultiline(ItemStack stack, GuiContainer gui, boolean includeHandlers) {
List<String> namelist = null;
try {
@@ -239,7 +238,6 @@ public class GuiContainerManager {
public static String itemDisplayNameShort(ItemStack itemstack) {
try {
@SuppressWarnings("unchecked")
List<String> namelist = itemstack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
if (!namelist.isEmpty() && !"".equals(namelist.get(0))) {
@@ -570,7 +568,7 @@ public class GuiContainerManager {
}
}
if (tooltip.size() > 0) tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); // add space after 'title'
if (!tooltip.isEmpty()) tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); // add space after 'title'
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
@@ -579,25 +577,27 @@ public class GuiContainerManager {
}
if (!hotkeys.isEmpty()) {
List<String> hotkeystips = new ArrayList<>();
if (!NEIClientUtils.altKey()) {
tooltip.add(
1,
EnumChatFormatting.GRAY + translate(
"showHotkeys",
"" + EnumChatFormatting.GOLD + "ALT" + EnumChatFormatting.GRAY));
hotkeystips.add(
EnumChatFormatting.GRAY
+ translate("showHotkeys", EnumChatFormatting.GOLD + "ALT" + EnumChatFormatting.GRAY));
} else {
List<String> hotkeystips = new LinkedList<>();
for (String key : hotkeys.keySet()) {
hotkeystips.add(getHotkeyTip(key, hotkeys.get(key)));
for (Map.Entry<String, String> entry : hotkeys.entrySet()) {
hotkeystips.add(getHotkeyTip(entry.getKey(), entry.getValue()));
}
hotkeystips.sort((a, b) -> Integer.compare(a.indexOf(" - "), b.indexOf(" - ")));
hotkeystips.set(
hotkeystips.size() - 1,
hotkeystips.get(hotkeystips.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
}
if (tooltip.isEmpty()) {
tooltip.addAll(hotkeystips);
} else {
tooltip.addAll(1, hotkeystips);
}
}
@@ -625,7 +625,7 @@ public class GuiContainerManager {
"inventory.tooltip.page",
tooltipPage + 1,
tooltips.size(),
NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.next_tooltip"), true)));
NEIClientConfig.getKeyName("gui.next_tooltip")));
}
drawMultilineTip(font, x, y, tooltips.get(tooltipPage));
}
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
*/
final class HideousLinkedList<E> extends LinkedList<E> {
private static final long serialVersionUID = -8504433551965776915L;
private final List<E> backing;
HideousLinkedList(List<E> backing) {
@@ -17,10 +17,9 @@ import codechicken.nei.FastTransferManager;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
@SuppressWarnings("rawtypes, unchecked")
public class DefaultOverlayHandler implements IOverlayHandler {
public static Class gtItem;
public static Class<?> gtItem;
static {
try {
@@ -85,7 +84,6 @@ public class DefaultOverlayHandler implements IOverlayHandler {
if (quantity != 0) moveIngredients(gui, assignedIngredients, quantity);
}
@SuppressWarnings("unchecked")
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
for (PositionedStack pstack : ingreds) for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
@@ -98,7 +96,6 @@ public class DefaultOverlayHandler implements IOverlayHandler {
return true;
}
@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
for (IngredientDistribution distrib : assignedIngredients) {
if (distrib.slots.length == 0) continue;
@@ -245,7 +242,6 @@ public class DefaultOverlayHandler implements IOverlayHandler {
return assignedIngredients;
}
@SuppressWarnings("unchecked")
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) /* work out how much we have to go round */ {
if (slot.getHasStack() && canMoveFrom(slot, gui)) {
@@ -272,7 +268,6 @@ public class DefaultOverlayHandler implements IOverlayHandler {
return slot.inventory instanceof InventoryPlayer;
}
@SuppressWarnings("unchecked")
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients) {
Slot[][] recipeSlotList = new Slot[ingredients.size()][];
for (int i = 0; i < ingredients.size(); i++) /* identify slots */ {
@@ -51,7 +51,6 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler {
return NEIClientUtils.translate("recipe.fuel");
}
@SuppressWarnings("unchecked")
private void loadAllSmelting() {
// Note: Not safe as written for parallelStream
final Map<ItemStack, ItemStack> smeltingRecipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting()
@@ -9,7 +9,6 @@ import java.util.Optional;
import java.util.stream.Collectors;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.GuiScreenEvent;
@@ -63,7 +62,44 @@ public class GuiOverlayButton extends GuiNEIButton {
}
}
private final static int OVERLAY_BUTTON_ID_START = 4;
public enum ItemOverlayFormat {
BACKGROUND,
ICON;
public static ItemOverlayFormat from(int overlay) {
return overlay == 2 ? ItemOverlayFormat.BACKGROUND : ItemOverlayFormat.ICON;
}
}
public static class ItemOverlayState {
protected PositionedStack slot;
protected boolean isPresent;
public ItemOverlayState(PositionedStack slot, boolean isPresent) {
this.slot = slot;
this.isPresent = isPresent;
}
public boolean isPresent() {
return this.isPresent;
}
public PositionedStack getSlot() {
return this.slot;
}
public void draw(ItemOverlayFormat format) {
LayoutManager.drawItemPresenceOverlay(
this.slot.relx,
this.slot.rely,
this.isPresent,
format == ItemOverlayFormat.BACKGROUND);
}
}
private static final int OVERLAY_BUTTON_ID_START = 4;
public final GuiContainer firstGui;
public final IRecipeHandler handler;
@@ -72,7 +108,7 @@ public class GuiOverlayButton extends GuiNEIButton {
protected ItemsTooltipLineHandler missedMaterialsTooltipLineHandler;
protected final IOverlayHandler overlayHandler;
protected final List<Boolean> itemPresenceCache = new ArrayList<>();
protected final List<ItemOverlayState> itemPresenceCache = new ArrayList<>();
protected boolean requireShiftForOverlayRecipe = true;
protected boolean useOverlayRenderer = false;
protected boolean hasOverlay = false;
@@ -114,26 +150,26 @@ public class GuiOverlayButton extends GuiNEIButton {
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
if (this.requireShiftForOverlayRecipe) {
if (this.requireShiftForOverlayRecipe && this.useOverlayRenderer) {
hotkeys.put(translate("recipe.overlay.fillCraftingGrid.key"), translate("recipe.overlay.fillCraftingGrid"));
}
String keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark"), true);
String keyName = NEIClientConfig.getKeyName("gui.bookmark");
if (keyName != null) {
hotkeys.put(keyName, translate("recipe.overlay.bookmark"));
}
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_recipe"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe");
if (keyName != null) {
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipe"));
}
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_count"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_count");
if (keyName != null) {
hotkeys.put(keyName, translate("recipe.overlay.bookmarkAmount"));
}
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_recipe_count"), true);
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe_count");
if (keyName != null) {
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipeAndAmount"));
}
@@ -152,20 +188,16 @@ public class GuiOverlayButton extends GuiNEIButton {
public void drawItemPresenceOverlay() {
final int presenceOverlay = NEIClientConfig.itemPresenceOverlay();
final boolean highlightPresentItem = NEIClientConfig.isSlotHighlightPresent();
final List<PositionedStack> ingredients = this.handler.getIngredientStacks(recipeIndex);
final List<Boolean> itemPresenceCache = ingredientsOverlay();
final ItemOverlayFormat format = ItemOverlayFormat.from(presenceOverlay);
for (int j = 0; j < ingredients.size(); j++) {
PositionedStack stack = ingredients.get(j);
Boolean isPresent = j < itemPresenceCache.size() ? itemPresenceCache.get(j) : null;
if (isPresent != null && (highlightPresentItem || !isPresent)) {
LayoutManager.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent, presenceOverlay == 2);
for (ItemOverlayState overlay : ingredientsOverlay()) {
if (highlightPresentItem || !overlay.isPresent()) {
overlay.draw(format);
}
}
}
protected List<Boolean> ingredientsOverlay() {
protected List<ItemOverlayState> ingredientsOverlay() {
List<PositionedStack> ingredients = this.handler.getIngredientStacks(recipeIndex);
if (this.itemPresenceCache.size() != ingredients.size()) {
@@ -178,13 +210,8 @@ public class GuiOverlayButton extends GuiNEIButton {
this.itemPresenceCache.addAll(presenceOverlay(ingredients));
}
List<ItemStack> items = new ArrayList<>();
for (int j = 0; j < ingredients.size(); j++) {
if (j >= this.itemPresenceCache.size() || !this.itemPresenceCache.get(j)) {
items.add(ingredients.get(j).item);
}
}
List<ItemStack> items = this.itemPresenceCache.stream().filter(state -> !state.isPresent())
.map(state -> state.getSlot().item).collect(Collectors.toCollection(ArrayList::new));
if (!items.isEmpty()) {
this.missedMaterialsTooltipLineHandler = new ItemsTooltipLineHandler(
@@ -221,10 +248,9 @@ public class GuiOverlayButton extends GuiNEIButton {
return this.hasOverlay;
}
private List<Boolean> presenceOverlay(List<PositionedStack> ingredients) {
final List<Boolean> itemPresenceSlots = new ArrayList<>();
@SuppressWarnings("unchecked")
final List<ItemStack> invStacks = ((List<Slot>) this.firstGui.inventorySlots.inventorySlots).stream()
private List<ItemOverlayState> presenceOverlay(List<PositionedStack> ingredients) {
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
final List<ItemStack> invStacks = this.firstGui.inventorySlots.inventorySlots.stream()
.filter(
s -> s != null && s.getStack() != null
&& s.getStack().stackSize > 0
@@ -234,9 +260,9 @@ public class GuiOverlayButton extends GuiNEIButton {
for (PositionedStack stack : ingredients) {
Optional<ItemStack> used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is))
.findFirst();
.findAny();
itemPresenceSlots.add(used.isPresent());
itemPresenceSlots.add(new ItemOverlayState(stack, used.isPresent()));
if (used.isPresent()) {
ItemStack is = used.get();
@@ -402,7 +402,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
}
}
@SuppressWarnings("unchecked")
public void initGui() {
xSize = 176;
ySize = Math.min(Math.max(height - 68, 166), 370);
@@ -478,7 +477,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
refreshPage();
}
@SuppressWarnings("unchecked")
private void updateOverlayButtons() {
final List<Integer> indices = getRecipeIndices();
@@ -1100,8 +1098,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
.filter(b -> b.recipeIndex == recipeIndex).findAny().orElse(null);
if (overlayButton != null && overlayButton.enabled) {
final String overlayKeyName = NEIClientConfig
.getKeyName(NEIClientConfig.getKeyBinding("gui.overlay_use"), true);
final String overlayKeyName = NEIClientConfig.getKeyName("gui.overlay_use");
if (overlayKeyName != null) {
fontRendererObj.drawStringWithShadow(
@@ -1110,6 +1107,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
handlerInfo.getHeight() - fontRendererObj.FONT_HEIGHT,
0xffffff);
}
overlayButton.drawItemPresenceOverlay();
}
}
@@ -213,10 +213,9 @@ public abstract class GuiRecipeTab extends Widget {
File handlerFile = NEIClientConfig.handlerFile;
if (!handlerFile.exists()) {
NEIClientConfig.logger.info("Config file doesn't exist, creating");
try {
try (FileOutputStream fileOutputStream = new FileOutputStream(handlerFile.getAbsoluteFile())) {
assert handlerUrl != null;
ReadableByteChannel readableByteChannel = Channels.newChannel(handlerUrl.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(handlerFile.getAbsoluteFile());
FileChannel fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
} catch (IOException e) {
@@ -233,7 +232,7 @@ public abstract class GuiRecipeTab extends Widget {
}
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(reader);
CSVParser csvParser = CSVFormat.EXCEL.builder().setHeader().setSkipHeaderRecord(true).build().parse(reader);
for (CSVRecord record : csvParser) {
final String handler = record.get("handler");
final String modName = record.get("modName");
@@ -70,12 +70,12 @@ class ItemsHistoryHandler implements ICraftingHandler, IUsageHandler {
}
@Override
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) {
public boolean keyTyped(GuiRecipe<?> gui, char keyChar, int keyCode, int recipe) {
return false;
}
@Override
public boolean mouseClicked(GuiRecipe gui, int button, int recipe) {
public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {
return true;
}
@@ -145,10 +145,9 @@ public class RecipeCatalysts {
File catalystFile = NEIClientConfig.catalystFile;
if (!catalystFile.exists()) {
NEIClientConfig.logger.info("Config file doesn't exist, creating");
try {
try (FileOutputStream fileOutputStream = new FileOutputStream(catalystFile.getAbsoluteFile())) {
assert handlerUrl != null;
ReadableByteChannel readableByteChannel = Channels.newChannel(handlerUrl.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(catalystFile.getAbsoluteFile());
FileChannel fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
} catch (IOException e) {
@@ -165,7 +164,7 @@ public class RecipeCatalysts {
}
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(reader);
CSVParser csvParser = CSVFormat.EXCEL.builder().setHeader().setSkipHeaderRecord(true).build().parse(reader);
for (CSVRecord record : csvParser) {
final String handler = record.get("handler");
final String modId = record.get("modId");
@@ -194,7 +193,7 @@ public class RecipeCatalysts {
try {
// gently handling copy&paste from handlers.csv
Class<?> clazz = Class.forName(handler);
Object object = clazz.newInstance();
Object object = clazz.getConstructor().newInstance();
if (object instanceof IRecipeHandler) {
if (forceClassName) {
forceClassNameList.add(handler);
@@ -24,7 +24,9 @@ public class StackInfo {
public static final ArrayList<IStackStringifyHandler> stackStringifyHandlers = new ArrayList<>();
private static final HashMap<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
private static final LinkedHashMap<ItemStack, FluidStack> fluidcache = new LinkedHashMap<ItemStack, FluidStack>() {
private static final LinkedHashMap<ItemStack, FluidStack> fluidcache = new LinkedHashMap<>() {
private static final long serialVersionUID = 1042213947848622164L;
@Override
protected boolean removeEldestEntry(Map.Entry<ItemStack, FluidStack> eldest) {
@@ -594,7 +594,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
// available
// This will ideally have been pre-cached elsewhere and will be a NOOP
findFuelsOnce();
return getClass().newInstance();
return getClass().getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -1,7 +1,5 @@
package codechicken.nei.util;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTBase;
@@ -34,8 +32,7 @@ public class NBTHelper {
private static boolean matchTagCompound(NBTTagCompound template, NBTTagCompound target) {
if (template.tagMap.size() > target.tagMap.size()) return false;
// noinspection unchecked
for (String key : (Set<String>) template.func_150296_c()) {
for (String key : template.func_150296_c()) {
if (!matchTag(template.getTag(key), target.getTag(key))) return false;
}
@@ -1,5 +1,6 @@
package codechicken.nei.util;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -216,8 +217,9 @@ public class NBTJson {
if (obj.has("__custom_type")) {
try {
final String className = obj.get("__custom_type").getAsString();
return (NBTBase) Class.forName(className).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException th) {}
return (NBTBase) Class.forName(className).getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException
| SecurityException | ClassNotFoundException th) {}
}
return null;
@@ -31,7 +31,7 @@ public class TextHistory {
}
public Optional<String> get(Direction direction, String currentText) {
if (direction == direction.NEXT) {
if (direction == Direction.NEXT) {
return getNext(currentText);
} else {
return getPrevious(currentText);
@@ -3,6 +3,8 @@ nei.save=Save
# PC/Linux Control Key
nei.key.ctrl=CTRL
nei.key.shift=SHIFT
nei.key.alt=ALT
# Mac Command Key
nei.key.ctrl.mac=CMD
nei.showHotkeys=Hold %s for hotkeys