From 157960f663a20583f2a37f967b9eda82134dbb0f Mon Sep 17 00:00:00 2001 From: Halbear Date: Wed, 5 Aug 2026 19:28:01 +0100 Subject: [PATCH] load cloud images --- .../java/net/halbear/skyboxmod/Config.java | 54 +++--- .../rendering/screen/ConfigScreen.java | 1 - .../rendering/screen/SelectionScreen.java | 182 ++++++++++++++++-- .../textures/correct_regex.png | Bin 0 -> 4016 bytes 4 files changed, 184 insertions(+), 53 deletions(-) create mode 100644 src/main/resources/assets/hals_skybox_mod/textures/correct_regex.png diff --git a/src/main/java/net/halbear/skyboxmod/Config.java b/src/main/java/net/halbear/skyboxmod/Config.java index 4b75a80..5309e2d 100644 --- a/src/main/java/net/halbear/skyboxmod/Config.java +++ b/src/main/java/net/halbear/skyboxmod/Config.java @@ -255,24 +255,30 @@ public class Config { } } - public List GetAndLoadAllCloudFiles(){ + public List GetAndLoadAllCloudFiles() { Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName); Path Clouds = ResourcesDir.resolve(CloudsFolderName); List CloudFiles = new ArrayList<>(); try (Stream stream = Files.walk(Clouds)) { List files = stream .filter(Files::isRegularFile) - .collect(Collectors.toList()); - files.forEach(cloudfile->{ - if(cloudfile.endsWith(".png")) { - File texture = cloudfile.toFile(); - Identifier loadedTexture = registerExternalTexture(texture); - CloudFiles.add(loadedTexture); - } + .toList(); + files.forEach(cloudfile -> { + SkyboxMod.LOGGER.debug("FILE: " + cloudfile.toString()); + File texture = cloudfile.toFile(); + Identifier loadedTexture = registerExternalTexture(texture); + CloudFiles.add(loadedTexture); }); } catch (IOException e) { - e.printStackTrace(); + SkyboxMod.LOGGER.error("failed to open cloud path: ", e); + } + if (RESOURCE_LOCATION.get() == ResourceLocations.IDENTIFIERS){ + List paths = CLOUD_PATHS.get(); + paths.forEach(path->{ + if(!Identifier.isValidPath(path)) CloudFiles.add(Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "textures/correct_regex.png")); + else CloudFiles.add(Identifier.parse(path)); + }); } return CloudFiles; } @@ -290,7 +296,8 @@ public class Config { }); } else{ paths.forEach(path->{ - loadedAssets.add(Identifier.parse(path)); + if(!Identifier.isValidPath(path)) loadedAssets.add(Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "textures/correct_regex.png")); + else loadedAssets.add(Identifier.parse(path)); }); } return loadedAssets; @@ -301,7 +308,11 @@ public class Config { public static Identifier registerExternalTexture(File imageFile) { if(LoadedTextureMap.containsKey( imageFile)) return LoadedTextureMap.get(imageFile); - Identifier location = Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "external_textures/loaded_texture_" + loadedTexture); + String path = "external_textures/"+loadedTexture+"loaded_texture_" + imageFile.getPath().split(CloudsFolderName)[1].substring(1).toLowerCase().replace(' ','-'); + if(!Identifier.isValidPath(path)) { + return Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "textures/correct_regex.png"); + } + Identifier location = Identifier.fromNamespaceAndPath(SkyboxMod.MODID,path ); try (InputStream stream = new FileInputStream(imageFile)) { NativeImage nativeImage = NativeImage.read(stream); @@ -317,19 +328,6 @@ public class Config { } } - public File getAssetAsFile(Identifier location) throws IOException { - var resourceManager = Minecraft.getInstance().getResourceManager(); - var resource = resourceManager.getResource(location) - .orElseThrow(() -> new FileNotFoundException("Asset not found: " + location)); - - try (InputStream stream = resource.open()) { - File tempFile = File.createTempFile("asset_", "_" + location.getPath().replace("/", "_")); - tempFile.deleteOnExit(); - - Files.copy(stream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - return tempFile; - } - } private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); @@ -411,13 +409,7 @@ public class Config { static final ModConfigSpec SPEC = BUILDER.build(); private static boolean ValidateCloudPath(final Object obj) { - return obj instanceof String itemName && Identifier.isValidPath(itemName); + return obj instanceof String itemName; } - public static final ModConfigSpec.ConfigValue> ITEM_STRINGS = BUILDER - .comment("A list of items to log on common setup.") - .defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), () -> "", Config::validateItemName); - private static boolean validateItemName(final Object obj) { - return obj instanceof String itemName && BuiltInRegistries.ITEM.containsKey(Identifier.parse(itemName)); - } } diff --git a/src/main/java/net/halbear/skyboxmod/rendering/screen/ConfigScreen.java b/src/main/java/net/halbear/skyboxmod/rendering/screen/ConfigScreen.java index 6c83750..6b0b6c3 100644 --- a/src/main/java/net/halbear/skyboxmod/rendering/screen/ConfigScreen.java +++ b/src/main/java/net/halbear/skyboxmod/rendering/screen/ConfigScreen.java @@ -42,7 +42,6 @@ public class ConfigScreen extends OptionsSubScreen { this.list.addBig(Config.Instance.CloudCount()); this.list.addSmall(CloudOptions(this.options)); this.list.addBig(Config.Instance.OpenCloudSprites()); - this.list.addBig(Config.Instance.OpenCloudImageButton()); } diff --git a/src/main/java/net/halbear/skyboxmod/rendering/screen/SelectionScreen.java b/src/main/java/net/halbear/skyboxmod/rendering/screen/SelectionScreen.java index be4cca9..79fceee 100644 --- a/src/main/java/net/halbear/skyboxmod/rendering/screen/SelectionScreen.java +++ b/src/main/java/net/halbear/skyboxmod/rendering/screen/SelectionScreen.java @@ -1,11 +1,14 @@ package net.halbear.skyboxmod.rendering.screen; +import net.halbear.skyboxmod.Config; import net.halbear.skyboxmod.SkyboxMod; +import net.halbear.skyboxmod.rendering.skybox.DistantSkyObject; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.packs.TransferableSelectionList; import net.minecraft.client.input.MouseButtonEvent; @@ -14,23 +17,31 @@ import net.minecraft.resources.Identifier; import net.minecraft.util.Util; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.neoforged.fml.loading.FMLPaths; import net.neoforged.neoforge.client.event.ContainerScreenEvent; import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.common.NeoForge; import org.jspecify.annotations.NonNull; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; +import static net.halbear.skyboxmod.Config.CloudsFolderName; +import static net.halbear.skyboxmod.Config.ResourceFolderName; + public class SelectionScreen extends Screen { private final Screen lastScreen; private final File targetDirectory; - private final List availableItems = new ArrayList<>(List.of("Test1", "Test2", "Test3", "Test4")); - private final List selectedItems = new ArrayList<>(List.of("Test5")); + private final LinkedHashSet AllItemsLoaded = new LinkedHashSet<>(); + private final LinkedHashSet availableItems = new LinkedHashSet<>(); + private final LinkedHashSet selectedItems = new LinkedHashSet<>(); private final ConcurrentLinkedQueue