This commit is contained in:
lukasabbe
2025-10-08 10:32:40 +02:00
parent 8750d28667
commit 47b10cfe05
9 changed files with 36 additions and 23 deletions
+1 -1
View File
@@ -2,5 +2,5 @@ plugins {
// see https://fabricmc.net/develop/ for new versions
id 'fabric-loom' version '1.11-SNAPSHOT' apply false
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
id 'net.neoforged.moddev' version '2.0.107' apply false
id 'net.neoforged.moddev' version '2.0.112' apply false
}
@@ -39,7 +39,8 @@ public class Config {
}
private void createConfig(Path configPath){
Path defaultConfigPath = Services.PLATFORM.getFileInModContainer("bookshelfinspector", "bookshelfinspector-config.yml");
Path defaultConfigPath = Services.PLATFORM.getFileOrCopyInModContainer("bookshelfinspector", "bookshelfinspector-config.yml");
if(defaultConfigPath == null) return;
try {
Files.copy(defaultConfigPath, configPath);
} catch (IOException e) {
@@ -9,5 +9,5 @@ public interface IPlatformHelper {
Path getConfigPath(String file);
Path getFileInModContainer(String mod, String fileName);
Path getFileOrCopyInModContainer(String mod, String fileName);
}
@@ -15,7 +15,6 @@ public class FabricPlatformHelper implements IPlatformHelper {
@Override
public boolean isModLoaded(String modId) {
return FabricLoader.getInstance().isModLoaded(modId);
}
@@ -25,7 +24,7 @@ public class FabricPlatformHelper implements IPlatformHelper {
}
@Override
public Path getFileInModContainer(String mod, String fileName) {
public Path getFileOrCopyInModContainer(String mod, String fileName) {
if(FabricLoader.getInstance().getModContainer(mod).isEmpty()) return null;
ModContainer modContainer = FabricLoader.getInstance().getModContainer(mod).get();
return modContainer.findPath(fileName).orElseThrow();
+9 -9
View File
@@ -1,32 +1,32 @@
version=2.1+1.21.10-rc1
version=2.1+1.21.10
# release, beta & alpha
versionType=beta
versionType=release
group=com.lukasabbe.bookshelfinspector
java_version=21
# Common
minecraft_version=1.21.10-rc1
minecraft_version=1.21.10
mod_name=BookshelfInspector
mod_author=Lukasabbe
mod_id=bookshelfinspector
license=MIT
credits=
description=Inspect any book in a chiseled bookshelf.
minecraft_version_range=[1.21.10-rc1, 1.22)
minecraft_version_range=[1.21.10, 1.22)
# https://projects.neoforged.net/neoforged/neoform
neo_form_version=1.21.10-rc1-20251002.143406
neo_form_version=1.21.10-20251007.142004
# The version of ParchmentMC that is used, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
parchment_minecraft=1.21.8
parchment_version=2025.07.20
parchment_minecraft=1.21.9
parchment_version=2025.10.05
# Fabric
fabric_version=0.134.1+1.21.10
fabric_loader_version=0.17.2
# NeoForge
neoforge_version=21.9.9-beta
neoforge_version=21.10.1-beta
neoforge_loader_version_range=[4,)
# Gradle
@@ -35,5 +35,5 @@ org.gradle.daemon=false
# Global dep
YAML_snake=2.5
cloth_config=19.0.147
cloth_config=20.0.148
mod_menu=16.0.0-rc.1
+2 -2
View File
@@ -19,7 +19,7 @@ neoForge {
mappingsVersion = parchment_version
}
dependencies {
//api "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config}"
api "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config}"
}
runs {
@@ -46,7 +46,7 @@ neoForge {
dependencies {
jarJar(implementation("org.yaml:snakeyaml:2.4")){}
additionalRuntimeClasspath "org.yaml:snakeyaml:2.4"
runtimeOnly "org.yaml:snakeyaml:2.4"
}
sourceSets.main.resources { srcDir 'src/generated/resources' }
@@ -1,15 +1,18 @@
package com.lukasabbe.bookshelfinspector;
import com.lukasabbe.bookshelfinspector.config.ClothConfigGenerator;
import com.lukasabbe.bookshelfinspector.util.EventHandler;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
@Mod(value = Constants.MOD_ID, dist = Dist.CLIENT)
public class BookshelfInspectorNeoForgeClient {
public BookshelfInspectorNeoForgeClient(IEventBus bus) {
EventHandler.initClient();
BookshelfInspectorClient.clientInit();
//ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (client, parent) -> ClothConfigGenerator.createConfig(parent));
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (client, parent) -> ClothConfigGenerator.createConfig(parent));
}
}
@@ -1,4 +1,3 @@
/*
package com.lukasabbe.bookshelfinspector.config;
import com.lukasabbe.bookshelfinspector.BookshelfInspectorClient;
@@ -38,4 +37,3 @@ public class ClothConfigGenerator {
return builder.build();
}
}
*/
@@ -7,6 +7,7 @@ import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.loading.FMLPaths;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -29,9 +30,20 @@ public class NeoForgePlatformHelper implements IPlatformHelper {
}
@Override
public Path getFileInModContainer(String mod, String fileName) {
public Path getFileOrCopyInModContainer(String mod, String fileName) {
if(ModList.get().getModContainerById(mod).isEmpty()) return null;
ModContainer container = ModList.get().getModContainerById(mod).get();
return Paths.get(container.getModInfo().getOwningFile().getFile().getContents().findFile(fileName).get());
try {
InputStream inputStream = container.getModInfo().getOwningFile().getFile().getContents().get(fileName).open();
File targetFile = new File(getConfigPath("bookshelfinspector-config.yml").toUri());
try(OutputStream outputStream = new FileOutputStream(targetFile)){
byte[] buffer = new byte[8192];
int bytesRead;
while((bytesRead = inputStream.read(buffer)) != -1){
outputStream.write(buffer, 0, bytesRead);
}
}catch (IOException ignore){}
}catch (IOException ignore){}
return null;
}
}