Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.9.62:dev")
api("com.github.GTNewHorizons:GTNHLib:0.10.3:dev")
implementation("io.github.legacymoddingmc:unimixins:0.3.1:dev")

shadowImplementation("org.yaml:snakeyaml:1.33") { transitive = false }
shadowImplementation("io.methvin:directory-watcher:0.17.1")
shadowImplementation("org.apache.lucene:lucene-core:8.11.4")
shadowImplementation("org.apache.lucene:lucene-analyzers-common:8.11.4")
shadowImplementation("org.apache.lucene:lucene-queryparser:8.11.4")
shadowImplementation("org.apache.lucene:lucene-highlighter:8.11.4")
shadowImplementation("org.apache.commons:commons-lang3:3.3.2") { transitive = false }
shadowImplementation("com.google.flatbuffers:flatbuffers-java:23.5.26") { transitive = false }
shadowImplementation("org.scilab.forge:jlatexmath:1.0.7") { transitive = false }

Expand Down Expand Up @@ -41,6 +41,8 @@ dependencies {
compileOnlyApi("ganymedes01.etfuturum:Et-Futurum-Requiem:2.6.2.21-GTNH-daily") { transitive = false }
compileOnlyApi("com.github.DarkShadow44:DistantHorizonsStandalone:9.9.9:dev") { transitive = false }

// jvmDowngrader
compileOnly("javax.xml.bind:jaxb-api:2.3.1")
compileOnly("org.jetbrains:annotations:26.0.1")
compileOnly("org.projectlombok:lombok:1.18.42") { transitive = false }
annotationProcessor("org.projectlombok:lombok:1.18.42")
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ developmentEnvironmentUserName = Huan_F
# - jabel: Jabel syntax-only support, compiles to J8 bytecode
# - jvmDowngrader: Full modern Java via JVM Downgrader (syntax + stdlib APIs)
# - modern: Native modern Java bytecode, no downgrading
enableModernJavaSyntax = jabel
enableModernJavaSyntax = jvmDowngrader

# If set, ignores the above setting and compiles with the given toolchain. This may cause unexpected issues,
# and should *not* be used in most situations. -1 disables this.
# forceToolchainVersion = -1

# Target JVM version for JVM Downgrader bytecode downgrading.
# Only used when enableModernJavaSyntax = jvmDowngrader
# downgradeTargetVersion = 8
downgradeTargetVersion = 8

# Comma-separated list of Java versions for multi-release jar support (JVM Downgrader only).
# Classes will be available in META-INF/versions/N/ for each version N in this list.
# Default: "21,25" (J25+ gets native classes, J21-24 gets partial downgrade, J8-20 gets full downgrade).
# jvmDowngraderMultiReleaseVersions = 21,25
jvmDowngraderMultiReleaseVersions = 17,21,25

# Specifies how JVM Downgrader API stubs are provided. Options:
# - shade: Shade minimized stubs into the jar
# - gtnhlib: GTNHLib provides stubs at runtime (adds version constraint)
# - external: Another dependency provides stubs (no constraint, no warning)
# - (empty): Warning reminding you to configure stubs
# Note: 'shade' option requires you to verify license compliance, see: https://github.com/unimined/JvmDowngrader/blob/main/LICENSE.md
# jvmDowngraderStubsProvider =
jvmDowngraderStubsProvider = gtnhlib

# 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.
Expand Down Expand Up @@ -101,7 +101,7 @@ apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
accessTransformersFile =
accessTransformersFile = guidenh_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = true
Expand Down
22 changes: 11 additions & 11 deletions gradle/gradle-daemon-jvm.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#This file is generated by updateDaemonJvm
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/e1118b4c7c2858d28154d086dbff010e/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/59a9771cad43219260d9aac9a8ec4d6a/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/832229f0f6f0be60ed817c5a5e5848eb/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/b96cb7670c095245220e7d01d5927b58/redirect
toolchainVersion=25
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect
toolchainVersion=25
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jetbrains.annotations.NotNull;

import com.hfstudio.guidenh.GuideNH;
import com.hfstudio.guidenh.bridge.preview.ItemPreviewCache;
import com.hfstudio.guidenh.bridge.preview.ItemPreviewSearchService;
Expand Down Expand Up @@ -158,7 +160,7 @@ public static class RuntimeBridgeThreadFactory implements ThreadFactory {
private int nextThreadId;

@Override
public Thread newThread(Runnable runnable) {
public Thread newThread(@NotNull Runnable runnable) {
Thread thread = new Thread(runnable, "GuideNH-RuntimeBridge-" + nextThreadId++);
thread.setDaemon(true);
return thread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ItemPreviewCache {

public ItemPreviewCache(int maxEntries) {
this.maxEntries = Math.max(1, maxEntries);
this.cache = new LinkedHashMap<ItemPreviewCacheKey, ItemPreviewPayload>(16, 0.75f, true) {
this.cache = new LinkedHashMap<>(16, 0.75f, true) {

@Override
protected boolean removeEldestEntry(Map.Entry<ItemPreviewCacheKey, ItemPreviewPayload> eldest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ItemPreviewCacheKey)) {
if (!(other instanceof ItemPreviewCacheKey that)) {
return false;
}
ItemPreviewCacheKey that = (ItemPreviewCacheKey) other;
return meta == that.meta && count == that.count
&& Objects.equals(capability, that.capability)
&& Objects.equals(id, that.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ItemPreviewPayload {
Expand All @@ -27,8 +25,7 @@ public ItemPreviewPayload(String previewKey, String id, String displayName, Stri
this.meta = meta;
this.count = count;
this.nbt = nbt == null ? "" : nbt;
this.tooltipLines = tooltipLines == null ? Collections.emptyList()
: Collections.unmodifiableList(new ArrayList<>(tooltipLines));
this.tooltipLines = tooltipLines == null ? List.of() : List.copyOf(tooltipLines);
this.iconPngBase64 = iconPngBase64 == null ? "" : iconPngBase64;
this.pixelWidth = pixelWidth;
this.pixelHeight = pixelHeight;
Expand All @@ -41,8 +38,8 @@ public PreviewResolveResult toResult(String capability) {
id,
displayName,
detail,
Integer.valueOf(meta),
Integer.valueOf(count),
meta,
count,
nbt,
tooltipLines,
iconPngBase64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,52 +151,32 @@ private int scoreEntry(String id, String label, String detail, String prefix) {
}

private boolean isShortPrefix(String prefix) {
return prefix.indexOf(':') < 0 && prefix.length() > 0 && prefix.length() <= 4;
return prefix.indexOf(':') < 0 && !prefix.isEmpty() && prefix.length() <= 4;
}

private String describeMatchKind(int score) {
switch (score) {
case 0:
return "label-exact";
case 1:
return "id-exact";
case 2:
return "namespace-prefix";
case 3:
return "label-prefix";
case 4:
return "label-token";
case 5:
return "id-prefix";
case 6:
return "path-prefix";
case 7:
return "path-token";
case 8:
return "detail-prefix";
case 9:
return "path-structured";
case 10:
return "path-acronym";
case 11:
return "id-compact";
case 12:
return "path-compact";
case 13:
return "label-acronym";
case 14:
return "label-compact";
case 15:
return "detail-compact";
case 16:
return "id-contains";
case 17:
return "label-contains";
case 18:
return "detail-contains";
default:
return "runtime";
}
return switch (score) {
case 0 -> "label-exact";
case 1 -> "id-exact";
case 2 -> "namespace-prefix";
case 3 -> "label-prefix";
case 4 -> "label-token";
case 5 -> "id-prefix";
case 6 -> "path-prefix";
case 7 -> "path-token";
case 8 -> "detail-prefix";
case 9 -> "path-structured";
case 10 -> "path-acronym";
case 11 -> "id-compact";
case 12 -> "path-compact";
case 13 -> "label-acronym";
case 14 -> "label-compact";
case 15 -> "detail-compact";
case 16 -> "id-contains";
case 17 -> "label-contains";
case 18 -> "detail-contains";
default -> "runtime";
};
}

private String buildPreviewKey(String id) {
Expand Down Expand Up @@ -268,7 +248,7 @@ private boolean matchesStructuredPathAbbreviation(String path, String compactPre
if (nonEmptyTokens.size() < 2) {
return false;
}
String firstToken = nonEmptyTokens.get(0);
String firstToken = nonEmptyTokens.getFirst();
if (!compactPrefix.startsWith(firstToken) || compactPrefix.length() <= firstToken.length()) {
return false;
}
Expand Down Expand Up @@ -371,7 +351,7 @@ private int computeStructuredMatchSpecificity(String path, String compactPrefix,
if (nonEmptyTokens.size() < 2) {
return 0;
}
String firstToken = nonEmptyTokens.get(0);
String firstToken = nonEmptyTokens.getFirst();
if (!compactPrefix.startsWith(firstToken) || compactPrefix.length() <= firstToken.length()) {
return 0;
}
Expand All @@ -397,14 +377,14 @@ private Map<String, Integer> buildFamilySizes(List<Map<String, String>> semantic
continue;
}
String familyKey = toFamilyKey(id);
familySizes.put(familyKey, familySizes.getOrDefault(familyKey, Integer.valueOf(0)) + 1);
familySizes.put(familyKey, familySizes.getOrDefault(familyKey, 0) + 1);
}
return familySizes;
}

private int resolveFamilySize(Map<String, Integer> familySizes, String id) {
Integer value = familySizes.get(toFamilyKey(id));
return value == null ? 0 : value.intValue();
return value == null ? 0 : value;
}

private String toFamilyKey(String id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -50,16 +49,16 @@ public static Map<String, String> readStringMap(JsonObject payload, String name)
if (payload == null || !payload.has(name)
|| !payload.get(name)
.isJsonObject()) {
return Collections.emptyMap();
return Map.of();
}
Map<String, String> values = new LinkedHashMap<>();
var values = new LinkedHashMap<String, String>();
JsonObject object = payload.getAsJsonObject(name);
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
JsonElement value = entry.getValue();
if (value != null && value.isJsonPrimitive()) {
values.put(entry.getKey(), value.getAsString());
}
}
return values;
return values.isEmpty() ? Map.of() : Map.copyOf(values);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -20,8 +19,7 @@ public PreviewResolveQuery(String capability, String id, int count, String nbt,
this.count = count;
this.nbt = nbt == null ? "" : nbt;
this.renderVariant = renderVariant == null ? "default" : renderVariant;
this.filters = filters == null ? Collections.emptyMap()
: Collections.unmodifiableMap(new LinkedHashMap<>(filters));
this.filters = filters == null || filters.isEmpty() ? Map.of() : Map.copyOf(new LinkedHashMap<>(filters));
}

public String getCapability() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PreviewResolveResult {
Expand Down Expand Up @@ -30,8 +28,7 @@ public PreviewResolveResult(String capability, String previewKey, String id, Str
this.meta = meta;
this.count = count;
this.nbt = nbt;
this.tooltipLines = tooltipLines == null ? Collections.emptyList()
: Collections.unmodifiableList(new ArrayList<>(tooltipLines));
this.tooltipLines = tooltipLines == null ? List.of() : List.copyOf(tooltipLines);
this.iconPngBase64 = iconPngBase64 == null ? "" : iconPngBase64;
this.pixelWidth = pixelWidth;
this.pixelHeight = pixelHeight;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -17,8 +16,7 @@ public PreviewSearchQuery(String capability, String cursor, int limit, String pr
this.cursor = cursor == null ? "" : cursor;
this.limit = limit;
this.prefix = prefix == null ? "" : prefix;
this.filters = filters == null ? Collections.emptyMap()
: Collections.unmodifiableMap(new LinkedHashMap<>(filters));
this.filters = filters == null || filters.isEmpty() ? Map.of() : Map.copyOf(new LinkedHashMap<>(filters));
}

public String getCapability() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.hfstudio.guidenh.bridge.preview;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PreviewSearchResult {
Expand All @@ -14,22 +12,21 @@ public class PreviewSearchResult {
public PreviewSearchResult(String capability, int version, List<PreviewSearchEntry> entries, String nextCursor) {
this.capability = capability == null ? "" : capability;
this.version = version;
this.entries = entries == null ? Collections.emptyList()
: Collections.unmodifiableList(new ArrayList<>(entries));
this.entries = entries == null ? List.of() : List.copyOf(entries);
this.nextCursor = nextCursor;
}

public static PreviewSearchResult page(String capability, List<PreviewSearchEntry> entries, String cursor,
int limit) {
List<PreviewSearchEntry> safeEntries = entries == null ? Collections.emptyList() : entries;
List<PreviewSearchEntry> safeEntries = entries == null ? List.of() : entries;
int start = parseCursor(cursor, safeEntries.size());
int safeLimit = limit > 0 ? limit : safeEntries.size();
int end = Math.min(safeEntries.size(), start + safeLimit);
String nextCursor = end < safeEntries.size() ? Integer.toString(end) : null;
return new PreviewSearchResult(
capability,
computeVersion(safeEntries),
new ArrayList<>(safeEntries.subList(start, end)),
List.copyOf(safeEntries.subList(start, end)),
nextCursor);
}

Expand Down
Loading