9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 09:29:33 +00:00

添加自定义生成资源包路径

This commit is contained in:
XiaoMoMi
2025-10-13 17:07:37 +08:00
parent 884e7cd4e4
commit 28d6640779
5 changed files with 22 additions and 7 deletions

View File

@@ -10,6 +10,9 @@ forced-locale: ''
filter-configuration-phase-disconnect: false
resource-pack:
# This option determines the location of the generated resource pack
# You can use either an absolute path or a relative path here
path: "./generated/resource_pack.zip"
# Should those images in minecraft:default font also work in minecraft:uniform
override-uniform-font: true
# Generate assets for CraftEngine fabric mod

View File

@@ -191,9 +191,7 @@ public abstract class AbstractPackManager implements PackManager {
@Override
public Path resourcePackPath() {
return this.plugin.dataFolderPath()
.resolve("generated")
.resolve("resource_pack.zip");
return Config.resourcePackPath();
}
@Override
@@ -203,7 +201,7 @@ public abstract class AbstractPackManager implements PackManager {
if (hostingObj instanceof Map<?,?>) {
arguments = MiscUtils.castToMap(hostingObj, false);
} else if (hostingObj instanceof List<?> list && !list.isEmpty()) {
arguments = MiscUtils.castToMap(list.get(0), false);
arguments = MiscUtils.castToMap(list.getFirst(), false);
} else {
this.resourcePackHost = NoneHost.INSTANCE;
return;

View File

@@ -59,6 +59,7 @@ public class Config {
protected List<String> resource_pack$merge_external_folders;
protected List<String> resource_pack$merge_external_zips;
protected Set<String> resource_pack$exclude_file_extensions;
protected Path resource_pack$path;
protected boolean resource_pack$protection$crash_tools$method_1;
protected boolean resource_pack$protection$crash_tools$method_2;
@@ -282,6 +283,7 @@ public class Config {
debug$resource_pack = config.getBoolean("debug.resource-pack", false);
// resource pack
resource_pack$path = resolvePath(config.getString("resource-pack.path", "./generated/resource_pack.zip"));
resource_pack$override_uniform_font = config.getBoolean("resource-pack.override-uniform-font", false);
resource_pack$generate_mod_assets = config.getBoolean("resource-pack.generate-mod-assets", false);
resource_pack$remove_tinted_leaves_particle = config.getBoolean("resource-pack.remove-tinted-leaves-particle", true);
@@ -1010,6 +1012,10 @@ public class Config {
return instance.item$default_material;
}
public static Path resourcePackPath() {
return instance.resource_pack$path;
}
public void setObf(boolean enable) {
this.resource_pack$protection$obfuscation$enable = enable;
}
@@ -1065,7 +1071,7 @@ public class Config {
}
private Path resolvePath(String path) {
return path.startsWith(".") ? CraftEngine.instance().dataFolderPath().resolve(path) : Path.of(path);
return FileUtils.isAbsolute(path) ? Path.of(path) : this.plugin.dataFolderPath().resolve(path);
}
public YamlDocument settings() {

View File

@@ -15,6 +15,10 @@ public class FileUtils {
private FileUtils() {}
public static boolean isAbsolute(final String path) {
return path.startsWith("/") || path.matches("^[A-Za-z]:\\\\.*");
}
public static String getExtension(Path path) {
final String name = path.getFileName().toString();
int index = name.lastIndexOf('.');

View File

@@ -60,7 +60,11 @@ public class Int2ObjectBiMap<K> implements IndexedIterable<K> {
for (int i = 0; i < idToValues.length; i++) {
K prev = idToValues[i];
if (prev == null) break;
idToValues[i] = function.apply(prev);
K apply = function.apply(prev);
idToValues[i] = apply;
if (!apply.equals(prev)) {
changed = true;
}
}
return changed;
}
@@ -172,7 +176,7 @@ public class Int2ObjectBiMap<K> implements IndexedIterable<K> {
private int findFree(int size) {
int i;
for(i = size; i < this.values.length; ++i) {
for (i = size; i < this.values.length; ++i) {
if (this.values[i] == EMPTY) {
return i;
}