Refactor locationToName method for improved readability and performance and update license

This commit is contained in:
HoosierTransfer 2024-06-21 18:14:26 -04:00
parent a8347a5126
commit aaa11a11ac
9 changed files with 44412 additions and 44615 deletions

1034
LICENSE

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

BIN
javascript/update.cert Normal file

Binary file not shown.

View File

@ -20,14 +20,21 @@ import org.apache.commons.lang3.StringUtils;
/** /**
* Copyright (c) 2024 lax1dude. All Rights Reserved. * Copyright (c) 2024 lax1dude. All Rights Reserved.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * DISCLAIMED.
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * DIRECT,
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
@ -63,7 +70,8 @@ public class GuiUpdateCheckerOverlay extends Gui {
this.mc = mc; this.mc = mc;
this.width = w; this.width = w;
this.height = h; this.height = h;
checkForUpdatesButton = new GuiButton(0, 0, 0, 150, 20, I18n.format("update.button") + " " + I18n.format(mc.gameSettings.enableUpdateSvc ? "gui.yes" : "gui.no")); checkForUpdatesButton = new GuiButton(0, 0, 0, 150, 20, I18n.format("update.button") + " "
+ I18n.format(mc.gameSettings.enableUpdateSvc ? "gui.yes" : "gui.no"));
startDownloadButton = new GuiButton(1, 1, 0, 115, 20, I18n.format("update.startDownload")); startDownloadButton = new GuiButton(1, 1, 0, 115, 20, I18n.format("update.startDownload"));
viewAllUpdatesButton = new GuiButton(2, 1, 0, 115, 20, I18n.format("update.viewAll", 0)); viewAllUpdatesButton = new GuiButton(2, 1, 0, 115, 20, I18n.format("update.viewAll", 0));
dismissUpdatesButton = new GuiButton(3, 1, 0, 115, 20, I18n.format("update.dismiss")); dismissUpdatesButton = new GuiButton(3, 1, 0, 115, 20, I18n.format("update.dismiss"));
@ -73,6 +81,7 @@ public class GuiUpdateCheckerOverlay extends Gui {
if (!UpdateService.supported()) { if (!UpdateService.supported()) {
return; return;
} }
UpdateProgressStruct progressState = UpdateService.getUpdatingStatus(); UpdateProgressStruct progressState = UpdateService.getUpdatingStatus();
if (progressState.isBusy) { if (progressState.isBusy) {
drawScreenBusy(mx, my, partialTicks, progressState); drawScreenBusy(mx, my, partialTicks, progressState);
@ -90,6 +99,7 @@ public class GuiUpdateCheckerOverlay extends Gui {
checkForUpdatesButton.visible &= shownSP; checkForUpdatesButton.visible &= shownSP;
if (mc.gameSettings.enableUpdateSvc) { if (mc.gameSettings.enableUpdateSvc) {
String str; String str;
UpdateCertificate cert = UpdateService.getLatestUpdateFound(); UpdateCertificate cert = UpdateService.getLatestUpdateFound();
if (cert != null) { if (cert != null) {
@ -104,7 +114,8 @@ public class GuiUpdateCheckerOverlay extends Gui {
int embedWidth = 115; int embedWidth = 115;
int embedWidth2 = (int) (embedWidth / 0.75f); int embedWidth2 = (int) (embedWidth / 0.75f);
List<String> lst = cert.bundleVersionComment.length() == 0 ? null : mc.fontRendererObj.listFormattedStringToWidth(cert.bundleVersionComment, embedWidth2 - 14); List<String> lst = cert.bundleVersionComment.length() == 0 ? null
: mc.fontRendererObj.listFormattedStringToWidth(cert.bundleVersionComment, embedWidth2 - 14);
int embedHeight = 44; int embedHeight = 44;
if (lst != null) { if (lst != null) {
@ -133,7 +144,9 @@ public class GuiUpdateCheckerOverlay extends Gui {
GlStateManager.popMatrix(); GlStateManager.popMatrix();
mc.fontRendererObj.drawString(EnumChatFormatting.UNDERLINE + cert.bundleDisplayName, 45, 11, 0x000000); mc.fontRendererObj.drawString(EnumChatFormatting.UNDERLINE + cert.bundleDisplayName, 45, 11, 0x000000);
mc.fontRendererObj.drawString(I18n.format("update.update") + " " + EnumChatFormatting.DARK_RED + cert.bundleDisplayVersion, 45, 25, 0x000000); mc.fontRendererObj.drawString(
I18n.format("update.update") + " " + EnumChatFormatting.DARK_RED + cert.bundleDisplayVersion,
45, 25, 0x000000);
if (lst != null) { if (lst != null) {
for (int j = 0, l = lst.size(); j < l; ++j) { for (int j = 0, l = lst.size(); j < l; ++j) {
@ -141,7 +154,8 @@ public class GuiUpdateCheckerOverlay extends Gui {
} }
} }
mc.fontRendererObj.drawString(I18n.format("update.author") + " " + cert.bundleAuthorName, 5, 44 + (lst == null ? 0 : (3 + lst.size() * 8)), 0x777777); mc.fontRendererObj.drawString(I18n.format("update.author") + " " + cert.bundleAuthorName, 5,
44 + (lst == null ? 0 : (3 + lst.size() * 8)), 0x777777);
startDownloadButton.yPosition = embedHeight + embedY + 5; startDownloadButton.yPosition = embedHeight + embedY + 5;
viewAllUpdatesButton.yPosition = startDownloadButton.yPosition + 22; viewAllUpdatesButton.yPosition = startDownloadButton.yPosition + 22;
@ -214,7 +228,8 @@ public class GuiUpdateCheckerOverlay extends Gui {
GlStateManager.translate(0.0f, progY2 + 2, 0.0f); GlStateManager.translate(0.0f, progY2 + 2, 0.0f);
GlStateManager.scale(0.66f, 0.66f, 0.66f); GlStateManager.scale(0.66f, 0.66f, 0.66f);
str = progressState.statusString3; str = progressState.statusString3;
List<String> wrappedURL = mc.fontRendererObj.listFormattedStringToWidth(str, (int)((progX2 - progX1) * 1.5f)); List<String> wrappedURL = mc.fontRendererObj.listFormattedStringToWidth(str,
(int) ((progX2 - progX1) * 1.5f));
for (int i = 0, l = wrappedURL.size(); i < l; ++i) { for (int i = 0, l = wrappedURL.size(); i < l; ++i) {
str = wrappedURL.get(i); str = wrappedURL.get(i);
mc.fontRendererObj.drawStringWithShadow(str, 5, i * 11, cc); mc.fontRendererObj.drawStringWithShadow(str, 5, i * 11, cc);
@ -233,7 +248,8 @@ public class GuiUpdateCheckerOverlay extends Gui {
if (checkForUpdatesButton.mousePressed(mc, mx, my)) { if (checkForUpdatesButton.mousePressed(mc, mx, my)) {
mc.gameSettings.enableUpdateSvc = !mc.gameSettings.enableUpdateSvc; mc.gameSettings.enableUpdateSvc = !mc.gameSettings.enableUpdateSvc;
mc.gameSettings.saveOptions(); mc.gameSettings.saveOptions();
checkForUpdatesButton.displayString = I18n.format("update.button") + " " + I18n.format(mc.gameSettings.enableUpdateSvc ? "gui.yes" : "gui.no"); checkForUpdatesButton.displayString = I18n.format("update.button") + " "
+ I18n.format(mc.gameSettings.enableUpdateSvc ? "gui.yes" : "gui.no");
} }
if (startDownloadButton.mousePressed(mc, mx, my)) { if (startDownloadButton.mousePressed(mc, mx, my)) {
if (!UpdateService.getUpdatingStatus().isBusy) { if (!UpdateService.getUpdatingStatus().isBusy) {

View File

@ -109,6 +109,7 @@ public class UpdateService {
} }
byte[] latestUpdate = PlatformApplication.getLocalStorage(EaglercraftVersion.updateLatestLocalStorageKey, byte[] latestUpdate = PlatformApplication.getLocalStorage(EaglercraftVersion.updateLatestLocalStorageKey,
false); false);
if (latestUpdate != null) { if (latestUpdate != null) {
addCertificateToSet(latestUpdate, false); addCertificateToSet(latestUpdate, false);
} }

View File

@ -56,8 +56,13 @@ public abstract class AbstractResourcePack implements IResourcePack {
} }
private static String locationToName(ResourceLocation location) { private static String locationToName(ResourceLocation location) {
return HString.format("%s/%s/%s", String namespace = location.getResourceDomain();
new Object[] { "assets", location.getResourceDomain(), location.getResourcePath() }); String path = location.getResourcePath();
// uses a StringBuilder internally
return "assets/" +
namespace +
'/' +
path;
} }
public InputStream getInputStream(ResourceLocation location) throws IOException { public InputStream getInputStream(ResourceLocation location) throws IOException {