From 5ae5d90a73bd397ca5a69d1a603a6c68ffd8ad4d Mon Sep 17 00:00:00 2001 From: radmanplays <95340057+radmanplays@users.noreply.github.com> Date: Sat, 8 Jun 2024 19:02:55 +0330 Subject: [PATCH] add make storing mods on vfs and modgui made in java --- .../client/gui/GuiIngameMenu.edit.java | 7 +- .../client/gui/GuiMainMenu.edit.java | 7 +- .../client/gui/ScreenChatOptions.edit.java | 2 + .../java/net/eaglerforge/gui/GuiMods.java | 208 ++++++++++++++++++ .../vfs2/VFSFilenameIteratorImpl.java | 1 - 5 files changed, 218 insertions(+), 7 deletions(-) create mode 100644 sources/main/java/net/eaglerforge/gui/GuiMods.java diff --git a/patches/minecraft/net/minecraft/client/gui/GuiIngameMenu.edit.java b/patches/minecraft/net/minecraft/client/gui/GuiIngameMenu.edit.java index 2f77141..edfa3a3 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiIngameMenu.edit.java +++ b/patches/minecraft/net/minecraft/client/gui/GuiIngameMenu.edit.java @@ -20,11 +20,12 @@ ~ import net.minecraft.client.Minecraft; ~ import net.minecraft.client.audio.PositionedSoundRecord; -> CHANGE 4 : 8 @ 4 : 5 +> CHANGE 4 : 9 @ 4 : 5 ~ import net.minecraft.util.ChatComponentText; ~ import net.minecraft.util.EnumChatFormatting; ~ import net.minecraft.util.ResourceLocation; +~ import net.eaglerforge.gui.GuiMods; ~ import net.eaglerforge.gui.ModGUI; > DELETE 2 @ 2 : 4 @@ -86,8 +87,8 @@ > INSERT 9 : 13 @ 9 + case 69420: -+ // this.mc.displayGuiScreen(new GuiMods(this)); -+ ModGUI.displayGui(); ++ this.mc.displayGuiScreen(new GuiMods(this)); ++ // ModGUI.displayGui(); + break; > CHANGE 7 : 21 @ 7 : 8 diff --git a/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.edit.java b/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.edit.java index 57d89cc..299c6f9 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.edit.java +++ b/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.edit.java @@ -13,9 +13,10 @@ + import java.util.Arrays; -> CHANGE 2 : 30 @ 2 : 4 +> CHANGE 2 : 31 @ 2 : 4 ~ +~ import net.eaglerforge.gui.GuiMods; ~ import net.eaglerforge.gui.ModGUI; ~ import net.lax1dude.eaglercraft.v1_8.EagRuntime; ~ import net.lax1dude.eaglercraft.v1_8.EaglerInputStream; @@ -212,8 +213,8 @@ > CHANGE 5 : 8 @ 5 : 8 ~ if (parGuiButton.id == 69420) { -~ // this.mc.displayGuiScreen(new WIP_GuiMods(this)); -~ ModGUI.displayGui(); +~ this.mc.displayGuiScreen(new GuiMods(this)); +~ // ModGUI.displayGui(); > CHANGE 3 : 4 @ 3 : 4 diff --git a/patches/minecraft/net/minecraft/client/gui/ScreenChatOptions.edit.java b/patches/minecraft/net/minecraft/client/gui/ScreenChatOptions.edit.java index 7a83650..fcbee88 100644 --- a/patches/minecraft/net/minecraft/client/gui/ScreenChatOptions.edit.java +++ b/patches/minecraft/net/minecraft/client/gui/ScreenChatOptions.edit.java @@ -16,4 +16,6 @@ ~ protected void actionPerformed(GuiButton parGuiButton) { +> DELETE 11 @ 11 : 12 + > EOF diff --git a/sources/main/java/net/eaglerforge/gui/GuiMods.java b/sources/main/java/net/eaglerforge/gui/GuiMods.java new file mode 100644 index 0000000..69421b2 --- /dev/null +++ b/sources/main/java/net/eaglerforge/gui/GuiMods.java @@ -0,0 +1,208 @@ +package net.eaglerforge.gui; + +// WIP -radmanplays + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.google.common.collect.Lists; + +import net.lax1dude.eaglercraft.v1_8.EagRuntime; +import net.lax1dude.eaglercraft.v1_8.internal.FileChooserResult; +import net.lax1dude.eaglercraft.v1_8.internal.vfs2.VFile2; +import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; +import net.lax1dude.eaglercraft.v1_8.log4j.Logger; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiListExtended; +import net.minecraft.client.gui.GuiOptionButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiSelectWorld; +import net.minecraft.client.gui.GuiSlot; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.resources.I18n; + +public class GuiMods extends GuiScreen { + private static final Logger logger = LogManager.getLogger(); + private final GuiScreen parentScreen; + public ArrayList modList; + public int selectedModIdx = -1; + private GuiModList rows; + public Minecraft mc = Minecraft.getMinecraft(); + private GuiButton deleteButton; + + public void updateModsList() { + // what is this 'vfs' thing! doesn't even have ability to index a directory!! + try { + VFile2 modListData = new VFile2("mods.txt"); + modList = new ArrayList(); + if (modListData.getAllChars() == null) { + modListData.setAllChars(""); + } + String[] filenames = modListData.getAllChars().split("\\|"); + System.out.println(filenames.toString()); + for (int i = 0; i < filenames.length; i++) { + if (filenames[i] != "") { + modList.add(new VFile2("mods", filenames[i])); + } + } + } catch (Exception e) { + // TODO: handle exception + } + } + + public GuiMods(GuiScreen parentScreenIn) { + this.parentScreen = parentScreenIn; + updateModsList(); + } + + /** + * + + * Adds the buttons (and other controls) to the screen in + * question. Called when the GUI is displayed and when the + * window resizes, the buttonList is cleared beforehand. + */ + public void initGui() { + GuiButton btn; + this.buttonList.add(btn = new GuiOptionButton(1, this.width / 2 - 154, this.height - 24, + I18n.format("eaglerforge.menu.mods.addmod" + + "", new Object[0]))); + this.buttonList.add(btn = new GuiOptionButton(2, this.width / 2, this.height - 24, + I18n.format("gui.done" + + "", new Object[0]))); + this.buttonList.add(deleteButton = new GuiOptionButton(3, this.width / 2 - 154, this.height - 48, + I18n.format("selectWorld.delete" + + "", new Object[0]))); + deleteButton.enabled = false; + rows = new GuiModList(Minecraft.getMinecraft(), this.width, this.height, 48, this.height - 56, 14, this); + rows.registerScrollButtons(4, 5); + } + + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + this.rows.handleMouseInput(); + } + + /** + * + + * Called by the controls from the buttonList when activated. + * (Mouse pressed for buttons) + */ + protected void actionPerformed(GuiButton parGuiButton) { + if (parGuiButton.enabled) { + if (parGuiButton.id == 2) { + Minecraft.getMinecraft().displayGuiScreen(parentScreen); + } else if (parGuiButton.id == 1) { + EagRuntime.displayFileChooser("text/javascript", "js"); + } else if (parGuiButton.id == 3) { + VFile2 modListData = new VFile2("mods.txt"); + String[] mods = modListData.getAllChars().split("\\|"); + String[] mods_new = new String[mods.length - 1]; + + for (int i = 0, k = 0; i < mods.length; i++) { + if (i != selectedModIdx) { + mods_new[k] = mods[i]; + k++; + } + } + modListData.setAllChars(String.join("|", mods_new)); + modList.get(selectedModIdx).delete(); + updateModsList(); + } else { + rows.actionPerformed(parGuiButton); + } + } else { + rows.actionPerformed(parGuiButton); + } + } + + /** + * + + * Draws the screen and all the components in it. Args : mouseX, + * mouseY, renderPartialTicks + */ + public void drawScreen(int i, int j, float f) { + this.drawBackground(0); + this.rows.drawScreen(i, j, f); + this.drawCenteredString(this.fontRendererObj, I18n.format("eaglerforge.menu.mods", new Object[0]), + this.width / 2, + 8, 0xFFFFFF); + mc.fontRendererObj.drawSplitString( + "Warning: malicious mods can download files to your device, potentially giving you a virus. They can also ip-grab you and wipe all saved Eaglercraft data.", + 0, 24, this.width - 20, 0xFF2200); // I18n.format("eaglerforge.menu.mods.info", new Object[0]) Don't + // know where + // to change this, so hardcoded for now :P + super.drawScreen(i, j, f); + } + + public void updateScreen() { + FileChooserResult modFile = null; + if (EagRuntime.fileChooserHasResult()) { + modFile = EagRuntime.getFileChooserResult(); + VFile2 idbModFile = new VFile2("mods", modFile.fileName); + idbModFile.setAllBytes(modFile.fileData); + + VFile2 modListData = new VFile2("mods.txt"); + String[] mods = modListData.getAllChars().split("\\|"); + String[] mods_new = new String[mods.length + 1]; + + for (int i = 0; i < mods.length; i++) { + mods_new[i] = mods[i]; + } + mods_new[mods.length] = modFile.fileName; + + modListData.setAllChars(String.join("|", mods_new)); + updateModsList(); + } + } + + private class GuiModList extends GuiSlot { + private GuiMods parentGui; + private int slotHeight; + + public GuiModList(Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn, + GuiMods parent) { + super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn); + parentGui = parent; + slotHeight = slotHeightIn; + setEnabled(true); + } + + @Override + protected int getContentHeight() { + return parentGui.modList.size() * slotHeight; + } + + @Override + protected int getSize() { + return parentGui.modList.size(); + } + + @Override + protected void elementClicked(int index, boolean isDoubleClick, int mouseX, int mouseY) { + // Handle the event when an element is clicked + parentGui.selectedModIdx = index; + parentGui.deleteButton.enabled = true; + } + + @Override + protected boolean isSelected(int index) { + // Return true if the specified element is selected + return parentGui.selectedModIdx == index; + } + + @Override + protected void drawBackground() { + // Draw the background for the list elements + } + + @Override + protected void drawSlot(int entryID, int x, int y, int mouseXIn, int mouseYIn, + int var6) { + mc.fontRendererObj.drawStringWithShadow(modList.get(entryID).getName(), x, y, 0xFFFFFF); + } + } +} \ No newline at end of file diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/vfs2/VFSFilenameIteratorImpl.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/vfs2/VFSFilenameIteratorImpl.java index 0311f15..8c56426 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/vfs2/VFSFilenameIteratorImpl.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/vfs2/VFSFilenameIteratorImpl.java @@ -29,5 +29,4 @@ class VFSFilenameIteratorImpl implements VFSFilenameIterator { public void next(String entry) { itr.next(new VFile2(entry)); } - }