Compare commits

...
Author SHA1 Message Date
Glease 64a747e4bd prevent empty pages from being produced (#615) 2025-03-25 15:06:45 +01:00
Martin Robertz 4f60928b61 update 2025-03-24 16:05:00 +01:00
8dba2ff4c1 Add option to adjust FPS rendering of items (#612)
Co-authored-by: slprime <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
2025-03-24 15:01:41 +00:00
eb40e3b112 Add Hotkeys Widget Settings (#613)
Co-authored-by: slprime <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
2025-03-24 15:48:11 +01:00
Martin Robertz 98c8981f05 update 2025-03-19 16:45:47 +01:00
Spacebuilder2020 1ed35c8357 Implement Forge Essentials Permission Checking (#611) 2025-03-18 08:15:30 -07:00
15 changed files with 163 additions and 64 deletions

No files matched your search

+3 -1
View File
@@ -2,7 +2,9 @@
dependencies {
api('com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.14:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.16:dev')
shadowImplementation('org.apache.commons:commons-csv:1.10.0')
compileOnly 'maven.modrinth:forge-essentials:7.5.1'
}
+4
View File
@@ -1,4 +1,8 @@
// Add any additional repositiroes for your dependencies here
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
@@ -4,6 +4,7 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
@@ -102,6 +103,39 @@ public class FormattedTextField extends GuiTextField {
this.editable = p_146184_1_;
}
@Override
public void writeText(String p_146191_1_) {
String newText = "";
String substr = ChatAllowedCharacters.filerAllowedCharacters(p_146191_1_);
int cursorPosition = getCursorPosition();
int maxStringLength = getMaxStringLength();
String text = getText();
if (text.isEmpty()) {
newText = substr.substring(0, Math.min(maxStringLength, substr.length()));
cursorPosition = newText.length();
} else {
int selectionEnd = getSelectionEnd();
String textStart = text.substring(0, Math.min(cursorPosition, selectionEnd));
String textEnd = text.substring(Math.max(cursorPosition, selectionEnd));
newText = textStart + substr + textEnd;
if (newText.length() > maxStringLength) {
newText = newText.substring(0, maxStringLength);
}
cursorPosition = Math.min(textStart.length() + substr.length(), newText.length());
}
setText(newText);
setCursorPosition(cursorPosition);
}
@Override
public int getNthWordFromPos(int p_146183_1_, int p_146183_2_) {
return this.func_146197_a(p_146183_1_, p_146183_2_, true);
}
@Override
public void drawTextBox() {
if (this.getVisible()) {
@@ -234,8 +234,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
return true;
}
if (NEIClientConfig.isKeyHashDown("gui.next_tooltip")) {
GuiContainerManager.incrementTooltipPage();
if (NEIClientConfig.isKeyHashDown("gui.next_tooltip") && GuiContainerManager.incrementTooltipPage()) {
return true;
}
@@ -184,7 +184,7 @@ public class LayoutStyleMinecraft extends LayoutStyle {
final Rectangle4i area = new Rectangle4i(0, 0, 0, BUTTON_SIZE);
if (NEIClientConfig.isSearchWidgetCentered()) {
area.w = gui.xSize - MARGIN * 2;
area.w = Math.min(gui.xSize, 176) - MARGIN * 2;
area.x = (gui.width - area.w) / 2;
area.y = gui.height - BUTTON_SIZE - MARGIN;
} else if (NEIClientConfig.showItemQuantityWidget()) {
@@ -46,7 +46,6 @@ import codechicken.nei.config.GuiHighlightTips;
import codechicken.nei.config.GuiNEIOptionList;
import codechicken.nei.config.GuiOptionList;
import codechicken.nei.config.GuiPanelSettings;
import codechicken.nei.config.OptionButton;
import codechicken.nei.config.OptionCycled;
import codechicken.nei.config.OptionGamemodes;
import codechicken.nei.config.OptionIntegerField;
@@ -289,19 +288,6 @@ public class NEIClientConfig {
0,
OptionIntegerField.UNSIGNED_INT_MAX));
API.addOption(
new OptionButton(
"inventory.collapsibleItems.reloadLabel",
"inventory.collapsibleItems.reloadButton",
"inventory.collapsibleItems.reloadTip") {
@Override
public boolean onClick(int button) {
LayoutManager.markItemsDirty();
return super.onClick(button);
}
});
tag.getTag("inventory.itemzoom.enabled").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.itemzoom.enabled", true));
@@ -369,6 +355,18 @@ public class NEIClientConfig {
tag.getTag("inventory.gridRenderingCacheMode").getIntValue(0);
API.addOption(new OptionCycled("inventory.gridRenderingCacheMode", 3, true));
tag.getTag("inventory.gridRenderingCacheFPS").getIntValue(8);
API.addOption(new OptionIntegerField("inventory.gridRenderingCacheFPS", 1, 144) {
@Override
public boolean isEnabled() {
return OpenGlHelper.framebufferSupported && getIntSetting("inventory.gridRenderingCacheMode") == 1;
}
});
tag.getTag("inventory.hotkeysHelpText").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.hotkeysHelpText", true));
tag.getTag("loadPluginsInParallel").getBooleanValue(true);
tag.getTag("itemLoadingTimeout").getIntValue(500);
@@ -21,6 +21,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.permission.PermissionLevel;
import net.minecraftforge.permission.PermissionManager;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@@ -44,6 +46,8 @@ public class NEIServerConfig {
public static HashMap<String, PlayerSave> playerSaves = new HashMap<>();
public static ItemStackMap<Set<String>> bannedItems = new ItemStackMap<>();
private static boolean doesPermAPIExist = false;
public static void load(World world) {
if (MinecraftServer.getServer() != server) {
logger.debug("Loading NEI Server");
@@ -53,6 +57,16 @@ public class NEIServerConfig {
dimTags.clear();
loadConfig();
loadBannedItems();
try {
Class.forName("net.minecraftforge.permission.PermissionManager");
doesPermAPIExist = true;
NEIActions.baseActions().forEach(
action -> {
PermissionManager.registerPermission("nei.permissions." + action, PermissionLevel.OP);
});
} catch (ClassNotFoundException ignored) {}
}
loadWorld(world);
}
@@ -121,7 +135,12 @@ public class NEIServerConfig {
}
public static boolean canPlayerPerformAction(String playername, String name) {
return isPlayerInList(playername, getPlayerList("permissions." + NEIActions.base(name)), true);
String node = "permissions." + NEIActions.base(name);
boolean hasPerm = doesPermAPIExist
? PermissionManager.checkPermission(ServerUtils.getPlayer(playername), "nei." + node)
: false;
return hasPerm || isPlayerInList(playername, getPlayerList(node), true);
}
public static boolean isPlayerInList(String playername, Set<String> list, boolean allowCards) {
@@ -8,7 +8,7 @@ import codechicken.nei.TextField;
public class OptionTextField extends Option {
protected final TextField textField = new TextField("test") {
protected final TextField textField = new TextField("option-text-field") {
{
this.h = 20;
@@ -19,6 +19,7 @@ public class OptionTextField extends Option {
// don't override global if text hasn't changed
if (focused() && isValidValue(text()) && (!defaulting() || !text().equals(getTag().getValue()))) {
getTag().setValue(text());
OptionTextField.this.onTextChange(text());
}
}
@@ -27,12 +28,20 @@ public class OptionTextField extends Option {
if (!focus && !isValidValue(text())) setText(renderTag().getValue());
super.setFocus(focus);
}
@Override
public void draw(int mousex, int mousey) {
this.field.setEnabled(isEnabled());
super.draw(mousex, mousey);
}
};
public OptionTextField(String name) {
super(name);
}
public void onTextChange(String text) {}
@Override
public void update() {
textField.update();
@@ -47,6 +56,10 @@ public class OptionTextField extends Option {
return slot.slotWidth();
}
public boolean isEnabled() {
return true;
}
@Override
public void draw(int mousex, int mousey, float frame) {
GuiDraw.drawString(getPrefix(), 10, 6, -1);
@@ -59,12 +72,14 @@ public class OptionTextField extends Option {
@Override
public void keyTyped(char c, int keycode) {
textField.handleKeyPress(keycode, c);
if (isEnabled()) {
textField.handleKeyPress(keycode, c);
}
}
@Override
public void mouseClicked(int mousex, int mousey, int button) {
if (textField.contains(mousex, mousey)) textField.handleClick(mousex, mousey, button);
if (isEnabled() && textField.contains(mousex, mousey)) textField.handleClick(mousex, mousey, button);
}
@Override
@@ -74,7 +89,7 @@ public class OptionTextField extends Option {
@Override
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip) {
if (new Rectangle4i(10, 0, textField.x - 10, 20).contains(mousex, mousey)) {
if (isEnabled() && new Rectangle4i(10, 0, textField.x - 10, 20).contains(mousex, mousey)) {
String tip = translateN(name + ".tip");
if (!tip.equals(namespaced(name + ".tip"))) currenttip.add(tip);
}
@@ -554,7 +554,8 @@ public class GuiContainerManager {
}
ItemStack stack = getStackMouseOver(window);
if (tooltip.isEmpty() && shouldShowTooltip(window)) { // mouseover tip, not holding an item
boolean showTooltip = shouldShowTooltip(window);
if (tooltip.isEmpty() && showTooltip) { // mouseover tip, not holding an item
font = getFontRenderer(stack);
if (stack != null) {
tooltip = itemDisplayNameMultiline(stack, window, true);
@@ -569,7 +570,7 @@ public class GuiContainerManager {
if (!tooltip.isEmpty()) tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); // add space after 'title'
if (shouldShowTooltip(window)) {
if (showTooltip) {
List<String> hotkeystips = collectHotkeyTips(mousex, mousey);
if (!hotkeystips.isEmpty()) {
@@ -615,23 +616,19 @@ public class GuiContainerManager {
}
private List<String> collectHotkeyTips(int mousex, int mousey) {
Map<String, String> hotkeys = new HashMap<>();
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
hotkeys = handler.handleHotkeys(window, mousex, mousey, hotkeys);
if (NEIClientUtils.altKey()) {
Map<String, String> hotkeys = new HashMap<>();
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
hotkeys = handler.handleHotkeys(window, mousex, mousey, hotkeys);
}
}
}
if (!hotkeys.isEmpty()) {
List<String> hotkeystips = new ArrayList<>();
if (!hotkeys.isEmpty()) {
List<String> hotkeystips = new ArrayList<>();
if (!NEIClientUtils.altKey()) {
hotkeystips.add(
EnumChatFormatting.GRAY + translate(
"showHotkeys",
EnumChatFormatting.GOLD + translate("key.alt") + EnumChatFormatting.GRAY));
} else {
Map<String, List<String>> messages = new HashMap<>();
hotkeys.remove(null);
hotkeys.remove("");
@@ -664,9 +661,28 @@ public class GuiContainerManager {
hotkeystips.set(
hotkeystips.size() - 1,
hotkeystips.get(hotkeystips.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
return hotkeystips;
}
return hotkeystips;
} else if (NEIClientConfig.getBooleanSetting("inventory.hotkeysHelpText")) {
boolean existsHotkeys = false;
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
if (!handler.handleHotkeys(window, mousex, mousey, new HashMap<>()).isEmpty()) {
existsHotkeys = true;
break;
}
}
}
if (existsHotkeys) {
return Collections.singletonList(
EnumChatFormatting.GRAY + translate(
"showHotkeys",
EnumChatFormatting.GOLD + translate("key.alt") + EnumChatFormatting.GRAY));
}
}
return Collections.emptyList();
@@ -675,39 +691,50 @@ public class GuiContainerManager {
private String getHotkeyTip(List<String> keys, String message) {
return EnumChatFormatting.GOLD
+ String.join(EnumChatFormatting.DARK_GRAY + " / " + EnumChatFormatting.GOLD, keys)
+ EnumChatFormatting.GRAY
+ EnumChatFormatting.DARK_GRAY
+ " - "
+ EnumChatFormatting.GRAY
+ message
+ EnumChatFormatting.RESET;
}
private static int tooltipPage;
private static int maxTooltipPage;
public static void drawPagedTooltip(FontRenderer font, int x, int y, List<String> list) {
if (list.isEmpty()) return;
List<List<String>> tooltips = splitTooltipByPage(list);
tooltipPage = tooltipPage < tooltips.size() ? tooltipPage : 0;
if (tooltips.size() > 1) {
tooltips.get(tooltipPage).add(
EnumChatFormatting.ITALIC + NEIClientUtils.translate(
"inventory.tooltip.page",
tooltipPage + 1,
tooltips.size(),
NEIClientConfig.getKeyName("gui.next_tooltip")));
maxTooltipPage = tooltips.size();
tooltipPage = tooltipPage < maxTooltipPage ? tooltipPage : 0;
final List<String> currentTooltip = tooltips.get(tooltipPage);
if (maxTooltipPage > 1) {
final String pageTooltip = EnumChatFormatting.ITALIC + NEIClientUtils.translate(
"inventory.tooltip.page",
tooltipPage + 1,
maxTooltipPage,
NEIClientConfig.getKeyName("gui.next_tooltip"));
currentTooltip.set(
currentTooltip.size() - 1,
currentTooltip.get(currentTooltip.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
currentTooltip.add(pageTooltip);
}
if (NEIModContainer.isGTNHLibLoaded()) {
drawMultilineTip(
font,
x,
y,
tooltips.get(tooltipPage),
currentTooltip,
RenderTooltipEventHelper.getBackgroundStart(),
RenderTooltipEventHelper.getBackgroundEnd(),
RenderTooltipEventHelper.getBorderStart(),
RenderTooltipEventHelper.getBorderEnd());
return;
} else {
drawMultilineTip(font, x, y, currentTooltip);
}
drawMultilineTip(font, x, y, tooltips.get(tooltipPage));
}
public static List<List<String>> splitTooltipByPage(List<String> list) {
@@ -719,8 +746,9 @@ public class GuiContainerManager {
GuiDraw.ITooltipLineHandler line = GuiDraw.getTipLine(text);
int lineHeight = line != null ? line.getSize().height
: text.endsWith(GuiDraw.TOOLTIP_LINESPACE) && i + 1 < list.size() ? 12 : 10;
if (height + lineHeight <= GuiDraw.displaySize().height - 8 * 2 - 10) {
if (height + lineHeight <= GuiDraw.displaySize().height - 8 * 2 - 10 || tmp.isEmpty()) {
// top & bottom 8px + last line for showing page
// and at least include one line per page
height += lineHeight;
} else {
ret.add(new ArrayList<>(tmp));
@@ -752,8 +780,8 @@ public class GuiContainerManager {
}
}
public static void incrementTooltipPage() {
tooltipPage++;
public static boolean incrementTooltipPage() {
return tooltipPage != Math.min(tooltipPage++, maxTooltipPage);
}
public void renderSlotUnderlay(Slot slot) {
@@ -86,7 +86,7 @@ public class StackInfo {
}
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
if (stackA == null || stackB == null || !stackA.isItemEqual(stackB)) {
if (stackA == null || stackB == null || stackA.getItem() != stackB.getItem()) {
return false;
}
@@ -24,7 +24,7 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
nbTag.setInteger("Count", saveStackSize ? stack.stackSize : 1);
nbTag.setShort("Damage", (short) stack.getItemDamage());
if (stack.hasTagCompound()) {
if (stack.hasTagCompound() && !stack.getTagCompound().hasNoTags()) {
nbTag.setTag("tag", stack.getTagCompound());
}
@@ -38,13 +38,13 @@ public class NEIMouseUtils {
if (mouseBind >= 0) {
int button = unhash(mouseBind);
switch (button) {
case 0:
case MOUSE_BTN_LMB:
mouseText.add(NEIClientUtils.translate("mouse.left"));
break;
case 1:
case MOUSE_BTN_RMB:
mouseText.add(NEIClientUtils.translate("mouse.right"));
break;
case 2:
case MOUSE_BTN_MMB:
mouseText.add(NEIClientUtils.translate("mouse.middle"));
break;
default:
@@ -24,7 +24,7 @@ public enum ReadableNumberConverter {
/**
* String representation of the sorted postfixes
*/
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
private static final char[] ENCODED_POSTFIXES = "kMGTPE".toCharArray();
private final Format format;
@@ -198,6 +198,9 @@ nei.options.inventory.bookmarks.ignorePotionOverlap.false=No
nei.options.inventory.bookmarks.worldSpecific=World Specific Bookmarks
nei.options.inventory.bookmarks.worldSpecific.true=Yes
nei.options.inventory.bookmarks.worldSpecific.false=No
nei.options.inventory.hotkeysHelpText=Show Hotkeys Help Text
nei.options.inventory.hotkeysHelpText.true=Yes
nei.options.inventory.hotkeysHelpText.false=No
nei.options.inventory.guirecipe=Recipes GUI
nei.options.inventory.guirecipe.jeiStyleTabs=JEI Style Tabs
nei.options.inventory.guirecipe.jeiStyleTabs.true=Yes
@@ -317,6 +320,7 @@ nei.options.inventory.gridRenderingCacheMode=Grid Rendering Cache Mode
nei.options.inventory.gridRenderingCacheMode.0=Off
nei.options.inventory.gridRenderingCacheMode.1=Low FPS
nei.options.inventory.gridRenderingCacheMode.2=Freeze
nei.options.inventory.gridRenderingCacheFPS=Grid Rendering Cache FPS
nei.options.inventory.collapsibleItems=Collapsible Items
nei.options.inventory.collapsibleItems.enabled=Collapsible Items
nei.options.inventory.collapsibleItems.enabled.true=Enabled
@@ -326,8 +330,6 @@ nei.options.inventory.collapsibleItems.customName.true=Yes
nei.options.inventory.collapsibleItems.customName.false=No
nei.options.inventory.collapsibleItems.expandedColor=Expanded Color
nei.options.inventory.collapsibleItems.collapsedColor=Collapsed Color
nei.options.inventory.collapsibleItems.reloadLabel=Reload
nei.options.inventory.collapsibleItems.reloadButton=Run
nei.options.inventory.history=History Panel
nei.options.inventory.history.enabled=History Panel Visibility
nei.options.inventory.history.enabled.true=Enabled
@@ -301,8 +301,6 @@ nei.options.inventory.collapsibleItems.customName.true=Да
nei.options.inventory.collapsibleItems.customName.false=Нет
nei.options.inventory.collapsibleItems.expandedColor=Цвет развернутого
nei.options.inventory.collapsibleItems.collapsedColor=Цвет свернутого
nei.options.inventory.collapsibleItems.reloadLabel=Перезагрузить
nei.options.inventory.collapsibleItems.reloadButton=Запустить
nei.options.inventory.history=Панель истории
nei.options.inventory.history.enabled=Видимость панели истории
nei.options.inventory.history.enabled.true=Включено