initial commit
@@ -0,0 +1,423 @@
|
||||
package net.halbear.skyboxmod;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.halbear.skyboxmod.rendering.screen.ConfigScreen;
|
||||
import net.halbear.skyboxmod.rendering.screen.SelectionScreen;
|
||||
import net.halbear.skyboxmod.rendering.skybox.DistantSkyObject;
|
||||
import net.halbear.skyboxmod.rendering.skybox.SkyBoxRendering;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.OptionInstance;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.util.Util;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import javax.naming.spi.DirectoryManager;
|
||||
|
||||
import static net.minecraft.client.Options.genericValueLabel;
|
||||
|
||||
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
|
||||
// Demonstrates how to use Neo's config APIs
|
||||
public class Config {
|
||||
private final OptionInstance<Integer> CloudCount;
|
||||
private final OptionInstance<Double> MinCloudSpeed;
|
||||
private final OptionInstance<Double> MaxCloudSpeed;
|
||||
private final OptionInstance<Integer> MaxVerticalAngle;
|
||||
private final OptionInstance<Integer> MinVerticalAngle;
|
||||
private final OptionInstance<Double> MaxScale;
|
||||
private final OptionInstance<Double> MinScale;
|
||||
private final OptionInstance<Boolean> OpenCloudImageButton;
|
||||
private final OptionInstance<Boolean> OpenCloudSprites;
|
||||
|
||||
private final OptionInstance<Boolean> RenderCustomSun;
|
||||
private final OptionInstance<Boolean> RenderCustomMoon;
|
||||
private final OptionInstance<Boolean> RenderCustomSkybox;
|
||||
private final OptionInstance<Boolean> RenderCustomClouds;
|
||||
|
||||
private final OptionInstance<Boolean> RenderSunTranslucent;
|
||||
private final OptionInstance<Boolean> RenderMoonTranslucent;
|
||||
private final OptionInstance<Double> SunScale;
|
||||
private final OptionInstance<Double> MoonScale;
|
||||
|
||||
public static String ResourcePath = "N/A";
|
||||
public static final String ResourceFolderName = "HalsSkyboxMod_Resources";
|
||||
public static final String CloudsFolderName = "Skybox_Clouds";
|
||||
public static Path ResourceLocation;
|
||||
|
||||
public OptionInstance<Integer> CloudCount(){return CloudCount;}
|
||||
public OptionInstance<Boolean> OpenCloudSprites(){return OpenCloudSprites;}
|
||||
public OptionInstance<Integer> MaxVerticalAngle(){return MaxVerticalAngle;}
|
||||
public OptionInstance<Integer> MinVerticalAngle(){return MinVerticalAngle;}
|
||||
public OptionInstance<Double> MinCloudSpeed(){return MinCloudSpeed;}
|
||||
public OptionInstance<Double> MaxCloudSpeed(){return MaxCloudSpeed;}
|
||||
public OptionInstance<Double> MaxScale(){return MaxScale;}
|
||||
public OptionInstance<Double> MinScale(){return MinScale;}
|
||||
public OptionInstance<Double> SunScale(){return SunScale;}
|
||||
public OptionInstance<Double> MoonScale(){return MoonScale;}
|
||||
public OptionInstance<Boolean> OpenCloudImageButton(){return OpenCloudImageButton;}
|
||||
public OptionInstance<Boolean> RenderCustomSun(){return RenderCustomSun;}
|
||||
public OptionInstance<Boolean> RenderCustomMoon(){return RenderCustomMoon;}
|
||||
public OptionInstance<Boolean> RenderCustomSkybox(){return RenderCustomSkybox;}
|
||||
public OptionInstance<Boolean> RenderCustomClouds(){return RenderCustomClouds;}
|
||||
public OptionInstance<Boolean> RenderSunTranslucent(){return RenderSunTranslucent;}
|
||||
public OptionInstance<Boolean> RenderMoonTranslucent(){return RenderMoonTranslucent;}
|
||||
|
||||
public static Config Instance;
|
||||
|
||||
public Config(){
|
||||
CloudCount = new OptionInstance<Integer>("hals_skybox_config.cloud_object_count", OptionInstance.noTooltip(), (caption, value) -> Component.literal(caption.getString() + ": " + value), (new OptionInstance.IntRange(0, 1024)).xmap((value) -> value, (value) -> value, true), Codec.intRange(0, 1024), CLOUD_COUNT.getAsInt(), (value) -> {
|
||||
CLOUD_COUNT.set(value);
|
||||
CLOUD_COUNT.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
MaxVerticalAngle = new OptionInstance<Integer>("hals_skybox_config.max_cloud_vertical_angle", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), (new OptionInstance.IntRange(-180, 180)).xmap((value) -> value, (value) -> value, true), Codec.intRange(-180, 180), MAX_CLOUD_VERTICALE_ANGLE.getAsInt(), (value) -> {
|
||||
MAX_CLOUD_VERTICALE_ANGLE.set(value);
|
||||
MAX_CLOUD_VERTICALE_ANGLE.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
MinVerticalAngle = new OptionInstance<Integer>("hals_skybox_config.min_cloud_vertical_angle", OptionInstance.noTooltip(), (caption, value) -> Component.literal(caption.getString() + ": " + value), (new OptionInstance.IntRange(-180, 180)).xmap((value) -> value, (value) -> value, true), Codec.intRange(-180, 180), MIN_CLOUD_VERTICAL_ANGLE.getAsInt(), (value) -> {
|
||||
MIN_CLOUD_VERTICAL_ANGLE.set(value);
|
||||
MIN_CLOUD_VERTICAL_ANGLE.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
RenderCustomSun = new OptionInstance<Boolean>("hals_skybox_config.render_sun", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_SUN.getAsBoolean(), (value) -> {
|
||||
RENDER_SUN.set(value);
|
||||
RENDER_SUN.save();
|
||||
});
|
||||
|
||||
RenderCustomMoon = new OptionInstance<Boolean>("hals_skybox_config.render_moon", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_MOON.getAsBoolean(), (value) -> {
|
||||
RENDER_MOON.set(value);
|
||||
RENDER_MOON.save();
|
||||
});
|
||||
|
||||
RenderCustomSkybox = new OptionInstance<Boolean>("hals_skybox_config.render_skybox", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_SKYBOX.getAsBoolean(), (value) -> {
|
||||
RENDER_SKYBOX.set(value);
|
||||
RENDER_SKYBOX.save();
|
||||
});
|
||||
RenderCustomClouds = new OptionInstance<Boolean>("hals_skybox_config.render_clouds", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_CLOUDS.getAsBoolean(), (value) -> {
|
||||
RENDER_CLOUDS.set(value);
|
||||
RENDER_CLOUDS.save();
|
||||
});
|
||||
|
||||
RenderSunTranslucent = new OptionInstance<Boolean>("hals_skybox_config.render_sun_translucent", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_SUN_TRANSLUCENCY.getAsBoolean(), (value) -> {
|
||||
RENDER_SUN_TRANSLUCENCY.set(value);
|
||||
RENDER_SUN_TRANSLUCENCY.save();
|
||||
});
|
||||
|
||||
RenderMoonTranslucent = new OptionInstance<Boolean>("hals_skybox_config.render_moon_translucent", OptionInstance.noTooltip(), (caption, value) -> Component.literal(""+ value), ( OptionInstance.BOOLEAN_VALUES), RENDER_MOON_TRANSLUCENCY.getAsBoolean(), (value) -> {
|
||||
RENDER_MOON_TRANSLUCENCY.set(value);
|
||||
RENDER_MOON_TRANSLUCENCY.save();
|
||||
});
|
||||
|
||||
|
||||
|
||||
OpenCloudSprites = new OptionInstance<Boolean>("hals_skybox_config.open_cloud_sprites", OptionInstance.noTooltip(), (caption, value) -> {return Component.literal("");},
|
||||
OptionInstance.BOOLEAN_VALUES, false, (value) -> {
|
||||
Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName);
|
||||
Path Clouds = ResourcesDir.resolve(CloudsFolderName);
|
||||
net.minecraft.client.Minecraft.getInstance().setScreen(
|
||||
new SelectionScreen(Minecraft.getInstance().screen,Clouds.toFile())
|
||||
);
|
||||
});
|
||||
|
||||
MoonScale = new OptionInstance<Double>("hals_skybox_config.moon_scale", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (MOON_SCALE.getAsDouble() - 1.0)/99.0, (value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
MOON_SCALE.set((realFloatValue));
|
||||
MOON_SCALE.save();
|
||||
});
|
||||
|
||||
SunScale = new OptionInstance<Double>("hals_skybox_config.sun_scale", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (SUN_SCALE.getAsDouble() - 1.0)/99.0, (value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
SUN_SCALE.set((realFloatValue));
|
||||
SUN_SCALE.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
|
||||
MinScale = new OptionInstance<Double>("hals_skybox_config.min_cloud_scale", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (MIN_CLOUD_SCALE.getAsDouble() - 1.0)/99.0, (value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
MIN_CLOUD_SCALE.set((realFloatValue));
|
||||
MIN_CLOUD_SCALE.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
MaxScale = new OptionInstance<Double>("hals_skybox_config.max_cloud_scale", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (MAX_CLOUD_SCALE.getAsDouble() - 1.0)/99.0, (value) -> {
|
||||
double realFloatValue = 1.0 + (value * (99));
|
||||
MAX_CLOUD_SCALE.set((realFloatValue));
|
||||
MAX_CLOUD_SCALE.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
|
||||
MinCloudSpeed = new OptionInstance<Double>("hals_skybox_config.min_cloud_speed", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = -1.0 + (value * (2));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (MIN_CLOUD_SPEED.getAsDouble() + 1.0)/2.0, (value) -> {
|
||||
double realFloatValue = -1.0 + (value * (2));
|
||||
MIN_CLOUD_SPEED.set((realFloatValue));
|
||||
MIN_CLOUD_SPEED.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
MaxCloudSpeed = new OptionInstance<Double>("hals_skybox_config.max_cloud_speed", OptionInstance.noTooltip(), (caption, value) -> {
|
||||
double realFloatValue = -1.0 + (value * (2));
|
||||
return Component.literal(caption.getString() + ": " + String.format("%.2f", realFloatValue));
|
||||
}, OptionInstance.UnitDouble.INSTANCE, (MAX_CLOUD_SPEED.getAsDouble() + 1.0)/2.0, (value) -> {
|
||||
double realFloatValue = -1.0 + (value * (2));
|
||||
MAX_CLOUD_SPEED.set((realFloatValue));
|
||||
MAX_CLOUD_SPEED.save();
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
});
|
||||
|
||||
Instance = this;
|
||||
OpenCloudImageButton = new OptionInstance<Boolean>("hals_skybox_config.open_cloud_images_location", OptionInstance.noTooltip(), (caption, value) -> {return Component.literal("");},
|
||||
OptionInstance.BOOLEAN_VALUES, false, (value) -> {
|
||||
Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName);
|
||||
Path Clouds = ResourcesDir.resolve(CloudsFolderName);
|
||||
if(!Files.isDirectory(Clouds)) {
|
||||
try {
|
||||
Files.createDirectories(Clouds);
|
||||
} catch (Exception e) {
|
||||
SkyboxMod.LOGGER.error("Failed to create Clouds directory", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Util.getPlatform().openFile(Clouds.toFile());
|
||||
});
|
||||
if(RESOURCE_LOCATION.get() == ResourceLocations.GAME_DIR){
|
||||
Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName);
|
||||
if(!Files.isDirectory(ResourcesDir)){
|
||||
try {
|
||||
Files.createDirectories(ResourcesDir);
|
||||
SkyboxMod.LOGGER.info("Successfully created folder: {}", ResourcesDir);
|
||||
} catch (IOException e) {
|
||||
SkyboxMod.LOGGER.error("Failed to create ResourcesDir directory", e);
|
||||
RESOURCE_LOCATION.set(ResourceLocations.IDENTIFIERS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ResourceLocation = ResourcesDir;
|
||||
Path Clouds = ResourcesDir.resolve(CloudsFolderName);
|
||||
if(!Files.isDirectory(Clouds)){
|
||||
try {
|
||||
Files.createDirectories(Clouds);
|
||||
SkyboxMod.LOGGER.info("Successfully created folder: {}", ResourcesDir);
|
||||
Identifier[] clouds = new Identifier[EmbeddedCloudTextures.length];
|
||||
for(int i = 0; i < EmbeddedCloudTextures.length; i++){
|
||||
clouds[i] = Identifier.parse(EmbeddedCloudTextures[i]);
|
||||
Optional<Resource> resource = Minecraft.getInstance().getResourceManager().getResource(clouds[i]);
|
||||
if (resource.isPresent()) {
|
||||
Path targetFile = Clouds.resolve(clouds[i].getPath().replace("/", "_"));
|
||||
try (InputStream stream = resource.get().open()) {
|
||||
//if(Files.notExists(targetFile))Files.createFile(targetFile);
|
||||
Files.copy(stream, targetFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
System.out.println("Successfully saved asset to: " + targetFile.toAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
SkyboxMod.LOGGER.error("Failed to something or other: ",e);
|
||||
RESOURCE_LOCATION.set(ResourceLocations.IDENTIFIERS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
SkyboxMod.LOGGER.error("Failed to create Clouds directory", e);
|
||||
RESOURCE_LOCATION.set(ResourceLocations.IDENTIFIERS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Identifier> GetAndLoadAllCloudFiles(){
|
||||
Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName);
|
||||
Path Clouds = ResourcesDir.resolve(CloudsFolderName);
|
||||
List<Identifier> CloudFiles = new ArrayList<>();
|
||||
try (Stream<Path> stream = Files.walk(Clouds)) {
|
||||
List<Path> 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);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return CloudFiles;
|
||||
}
|
||||
|
||||
public List<Identifier> GetAllClouds(){
|
||||
List<? extends String> paths = CLOUD_PATHS.get();
|
||||
List<Identifier> loadedAssets = new ArrayList<>();
|
||||
if(RESOURCE_LOCATION.get() == ResourceLocations.GAME_DIR){
|
||||
Path ResourcesDir = FMLPaths.GAMEDIR.get().resolve(ResourceFolderName);
|
||||
Path Clouds = ResourcesDir.resolve(CloudsFolderName);
|
||||
paths.forEach((path)->{
|
||||
File texture = Clouds.resolve(path.replace('/','_')).toFile();
|
||||
Identifier loadedTexture = registerExternalTexture(texture);
|
||||
loadedAssets.add(loadedTexture);
|
||||
});
|
||||
} else{
|
||||
paths.forEach(path->{
|
||||
loadedAssets.add(Identifier.parse(path));
|
||||
});
|
||||
}
|
||||
return loadedAssets;
|
||||
}
|
||||
|
||||
public static int loadedTexture = 0;
|
||||
public static Map<File, Identifier> LoadedTextureMap = new LinkedHashMap<>();
|
||||
|
||||
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);
|
||||
try (InputStream stream = new FileInputStream(imageFile)) {
|
||||
NativeImage nativeImage = NativeImage.read(stream);
|
||||
|
||||
DynamicTexture dynamicTexture = new DynamicTexture(()->"loaded_texture_" + loadedTexture,nativeImage);
|
||||
loadedTexture++;
|
||||
Minecraft.getInstance().getTextureManager().register(location, dynamicTexture);
|
||||
LoadedTextureMap.put(imageFile, location);
|
||||
return location;
|
||||
|
||||
} catch (IOException e) {
|
||||
SkyboxMod.LOGGER.error("Failed to load texture: ",e);
|
||||
return Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "textures/no_texture.png");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
public static final ModConfigSpec.IntValue CLOUD_COUNT = BUILDER
|
||||
.comment("how many clouds to render in the sky")
|
||||
.defineInRange("cloud_count", 128, 0, 1024);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue MIN_CLOUD_SPEED = BUILDER
|
||||
.comment("the slowest cloud")
|
||||
.defineInRange("min_cloud_speed", 0.05, -1f, 1f);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue MAX_CLOUD_SPEED = BUILDER
|
||||
.comment("the fastest cloud")
|
||||
.defineInRange("max_cloud_speed", 0.15, -1f, 1f);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue MIN_CLOUD_SCALE = BUILDER
|
||||
.comment("how small (in blocks) the clouds can render")
|
||||
.defineInRange("min_cloud_scale", 2, 1f, 100f);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue MAX_CLOUD_SCALE = BUILDER
|
||||
.comment("how large (in blocks) the clouds can render")
|
||||
.defineInRange("max_cloud_scale", 14, 1f, 100f);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue SUN_SCALE = BUILDER
|
||||
.comment("how large (in blocks) the sun can render")
|
||||
.defineInRange("sun_scale", 22.5, 1f, 100f);
|
||||
|
||||
public static final ModConfigSpec.DoubleValue MOON_SCALE = BUILDER
|
||||
.comment("how large (in blocks) the moon can render")
|
||||
.defineInRange("moon_scale", 22.5, 1f, 100f);
|
||||
|
||||
public static final ModConfigSpec.IntValue MIN_CLOUD_VERTICAL_ANGLE = BUILDER
|
||||
.comment("how Low in the sky it can render")
|
||||
.defineInRange("min_cloud_vert_angle", -130, -180, 180);
|
||||
|
||||
public static final ModConfigSpec.IntValue MAX_CLOUD_VERTICALE_ANGLE = BUILDER
|
||||
.comment("how high in the sky it can render")
|
||||
.defineInRange("max_cloud_vert_angle", -70, -180, 180);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_SUN = BUILDER
|
||||
.comment("render custom sun texture and pipeline")
|
||||
.define("render_custom_sun", true);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_SUN_TRANSLUCENCY = BUILDER
|
||||
.comment("render custom sun as a translucent object, this makes it have absolute colour with working transparency")
|
||||
.define("render_custom_sun_pipeline", false);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_MOON = BUILDER
|
||||
.comment("render custom moon texture and pipeline")
|
||||
.define("render_custom_moon", true);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_MOON_TRANSLUCENCY = BUILDER
|
||||
.comment("render custom moon as a translucent object, this makes it have absolute colour with working transparency")
|
||||
.define("render_custom_moon_pipeline", true);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_SKYBOX = BUILDER
|
||||
.comment("render custom Skybox")
|
||||
.define("render_custom_skybox", true);
|
||||
|
||||
public static final ModConfigSpec.BooleanValue RENDER_CLOUDS = BUILDER
|
||||
.comment("render custom cloud textures and pipeline")
|
||||
.define("render_custom_clouds", true);
|
||||
|
||||
public enum ResourceLocations{
|
||||
GAME_DIR,
|
||||
IDENTIFIERS,
|
||||
}
|
||||
|
||||
public static final ModConfigSpec.EnumValue<ResourceLocations> RESOURCE_LOCATION = BUILDER
|
||||
.comment("where the asset folders are located")
|
||||
.defineEnum("resource_location", ResourceLocations.GAME_DIR);
|
||||
|
||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> CLOUD_PATHS = BUILDER
|
||||
.comment("A list of items to log on common setup.")
|
||||
.defineListAllowEmpty("cloud_paths", List.of("textures/cloud2.png","textures/cloud3.png","textures/smallcloud1.png","textures/smallcloud2.png","textures/smallcloud3.png"), () -> "", Config::ValidateCloudPath);
|
||||
|
||||
private static final String[] EmbeddedCloudTextures = new String[]{"hals_skybox_mod:textures/cloud2.png","hals_skybox_mod:textures/cloud3.png","hals_skybox_mod:textures/smallcloud1.png","hals_skybox_mod:textures/smallcloud2.png","hals_skybox_mod:textures/smallcloud3.png"};
|
||||
|
||||
static final ModConfigSpec SPEC = BUILDER.build();
|
||||
|
||||
private static boolean ValidateCloudPath(final Object obj) {
|
||||
return obj instanceof String itemName && Identifier.isValidPath(itemName);
|
||||
}
|
||||
|
||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> 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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.halbear.skyboxmod;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.config.ModConfig;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.halbear.skyboxmod.rendering.skybox.DistantSkyObject.RegenerateClouds;
|
||||
|
||||
|
||||
@Mod(value = SkyboxMod.MODID, dist = Dist.CLIENT)
|
||||
public class SkyboxMod {
|
||||
|
||||
public static final String MODID = "hals_skybox_mod";
|
||||
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public SkyboxMod(IEventBus modEventBus, ModContainer modContainer) {
|
||||
// Register the commonSetup method for modloading
|
||||
modEventBus.addListener(this::commonSetup);
|
||||
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
|
||||
modEventBus.addListener(this::addCreative);
|
||||
|
||||
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
|
||||
}
|
||||
|
||||
private void commonSetup(FMLCommonSetupEvent event) {
|
||||
// Some common setup code
|
||||
LOGGER.info("HELLO FROM COMMON SETUP");
|
||||
|
||||
new Config();
|
||||
}
|
||||
|
||||
// Add the example block item to the building blocks tab
|
||||
private void addCreative(BuildCreativeModeTabContentsEvent event) {
|
||||
|
||||
}
|
||||
|
||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
||||
@SubscribeEvent
|
||||
public void onServerStarting(ServerStartingEvent event) {
|
||||
// Do something when the server starts
|
||||
LOGGER.info("HELLO from server starting");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.halbear.skyboxmod;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
|
||||
// This class will not load on dedicated servers. Accessing client side code from here is safe.
|
||||
@Mod(value = SkyboxMod.MODID, dist = Dist.CLIENT)
|
||||
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
|
||||
@EventBusSubscriber(modid = SkyboxMod.MODID, value = Dist.CLIENT)
|
||||
public class SkyboxModClient {
|
||||
public SkyboxModClient(ModContainer container) {
|
||||
// Allows NeoForge to create a config screen for this mod's configs.
|
||||
// The config screen is accessed by going to the Mods screen > clicking on your mod > clicking on config.
|
||||
// Do not forget to add translations for your config options to the en_us.json file.
|
||||
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
static void onClientSetup(FMLClientSetupEvent event) {
|
||||
// Some client setup code
|
||||
SkyboxMod.LOGGER.info("HELLO FROM CLIENT SETUP");
|
||||
SkyboxMod.LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.halbear.skyboxmod.rendering.screen;
|
||||
|
||||
import net.halbear.skyboxmod.Config;
|
||||
import net.halbear.skyboxmod.SkyboxMod;
|
||||
import net.minecraft.client.OptionInstance;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class ConfigScreen extends OptionsSubScreen {
|
||||
private final Screen lastScreen;
|
||||
|
||||
private static OptionInstance<?>[] CloudOptions(Options options) {
|
||||
return new OptionInstance[]{Config.Instance.MinCloudSpeed(),Config.Instance.MaxCloudSpeed(), Config.Instance.MinScale(),Config.Instance.MaxScale(), Config.Instance.MinVerticalAngle(),Config.Instance.MaxVerticalAngle()};
|
||||
}
|
||||
|
||||
private static OptionInstance<?>[] CelestialOptions(Options options) {
|
||||
return new OptionInstance[]{Config.Instance.SunScale(),Config.Instance.MoonScale()};
|
||||
}
|
||||
private static OptionInstance<?>[] GeneralOptions(Options options) {
|
||||
return new OptionInstance[]{Config.Instance.RenderCustomSun(),Config.Instance.RenderCustomMoon(),Config.Instance.RenderCustomSkybox(),Config.Instance.RenderCustomClouds()};
|
||||
}
|
||||
|
||||
public ConfigScreen(Screen lastScreen,Options options) {
|
||||
SkyboxMod.LOGGER.debug("screen!");
|
||||
|
||||
super(lastScreen,options,Component.literal("Skybox Configuration"));
|
||||
this.lastScreen = lastScreen;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void addOptions() {
|
||||
this.list.addHeader(Component.translatable("hals_skybox_config.general_header"));
|
||||
this.list.addSmall(GeneralOptions(this.options));
|
||||
this.list.addHeader(Component.translatable("hals_skybox_config.celestial_header"));
|
||||
this.list.addSmall(CelestialOptions(this.options));
|
||||
this.list.addBig(Config.Instance.RenderSunTranslucent());
|
||||
this.list.addBig(Config.Instance.RenderMoonTranslucent());
|
||||
this.list.addHeader(Component.translatable("hals_skybox_config.cloud_header"));
|
||||
this.list.addBig(Config.Instance.CloudCount());
|
||||
this.list.addSmall(CloudOptions(this.options));
|
||||
this.list.addBig(Config.Instance.OpenCloudSprites());
|
||||
this.list.addBig(Config.Instance.OpenCloudImageButton());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
this.minecraft.setScreen(this.lastScreen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package net.halbear.skyboxmod.rendering.screen;
|
||||
|
||||
import net.halbear.skyboxmod.SkyboxMod;
|
||||
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.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.packs.TransferableSelectionList;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
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.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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectionScreen extends Screen {
|
||||
|
||||
private final Screen lastScreen;
|
||||
private final File targetDirectory;
|
||||
|
||||
private final List<String> availableItems = new ArrayList<>(List.of("Test1", "Test2", "Test3", "Test4"));
|
||||
private final List<String> selectedItems = new ArrayList<>(List.of("Test5"));
|
||||
|
||||
private SelectionPanelList leftList;
|
||||
private SelectionPanelList rightList;
|
||||
|
||||
|
||||
public SelectionScreen(Screen lastScreen, File targetDirectory) {
|
||||
super(Component.literal("Select Custom Options"));
|
||||
this.lastScreen = lastScreen;
|
||||
this.targetDirectory = targetDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
int listWidth = 170;
|
||||
int listHeight = this.height - 80;
|
||||
|
||||
this.leftList = new SelectionPanelList(this.minecraft, listWidth, listHeight,40,24 );
|
||||
this.leftList.setX(this.width / 2 - 180);
|
||||
|
||||
|
||||
this.rightList = new SelectionPanelList(this.minecraft, listWidth, listHeight,40,24);
|
||||
this.rightList.setX(this.width / 2 + 10);
|
||||
|
||||
refreshListData();
|
||||
|
||||
this.addRenderableWidget(this.leftList);
|
||||
this.addRenderableWidget(this.rightList);
|
||||
|
||||
this.addRenderableWidget(Button.builder(
|
||||
Component.literal("Done"),
|
||||
button -> this.onClose()
|
||||
).bounds(this.width / 2 - 75, this.height - 32, 150, 20).build());
|
||||
}
|
||||
|
||||
private void refreshListData() {
|
||||
this.leftList.clearEntries();
|
||||
this.rightList.clearEntries();
|
||||
|
||||
for (String item : availableItems) {
|
||||
this.leftList.AddEntry(new TextRowEntry(item, true,this));
|
||||
}
|
||||
for (String item : selectedItems) {
|
||||
this.rightList.AddEntry(new TextRowEntry(item, false,this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractBackground(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super.extractBackground(guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractRenderState(GuiGraphicsExtractor guiGraphicsExtractor, int mouseX, int mouseY, float partialTick){
|
||||
super.extractRenderState(guiGraphicsExtractor,mouseX,mouseY,partialTick);
|
||||
guiGraphicsExtractor.pose().pushMatrix();
|
||||
guiGraphicsExtractor.text(this.font, this.title, this.width / 2 - this.font.width(this.title)/2, 8, 0xFFFFFF,false);
|
||||
guiGraphicsExtractor.text(this.font, "Drag and drop sprites inside...", this.width / 2 - this.font.width("Drag and drop sprites inside...")/2, 20, 0x808080,false);
|
||||
guiGraphicsExtractor.pose().popMatrix();
|
||||
|
||||
// NeoForge.EVENT_BUS.post(new ScreenEvent.Render.Post(this,guiGraphicsExtractor, mouseX, mouseY,partialTick));
|
||||
|
||||
SkyboxMod.LOGGER.debug("\n this font: " + this.font + "\n this width:" + this.width + "\n this Title: " + this.title + "\n this title width: " + this.font.width(this.title));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
this.minecraft.setScreen(this.lastScreen);
|
||||
}
|
||||
|
||||
|
||||
private class SelectionPanelList extends ObjectSelectionList<TextRowEntry> {
|
||||
public SelectionPanelList(Minecraft minecraft, int width, int height, int y, int itemHeight) {
|
||||
super(minecraft, width, height, y, itemHeight);
|
||||
}
|
||||
public void AddEntry(TextRowEntry entry){
|
||||
this.addEntry(entry);
|
||||
}
|
||||
|
||||
|
||||
public void ClearChildren(){
|
||||
this.clearEntries();
|
||||
}
|
||||
}
|
||||
|
||||
private class TextRowEntry extends ObjectSelectionList.Entry<TextRowEntry> {
|
||||
private final String textValue;
|
||||
private final Button transferButton;
|
||||
private final SelectionScreen Parent;
|
||||
|
||||
public TextRowEntry(String value, boolean isAvailableSide, SelectionScreen Parent) {
|
||||
this.Parent = Parent;
|
||||
this.textValue = value;
|
||||
|
||||
String buttonSymbol = isAvailableSide ? "➡" : "⬅";
|
||||
this.transferButton = Button.builder(Component.literal(buttonSymbol), button -> {
|
||||
if (isAvailableSide) {
|
||||
availableItems.remove(textValue);
|
||||
selectedItems.add(textValue);
|
||||
} else {
|
||||
selectedItems.remove(textValue);
|
||||
availableItems.add(textValue);
|
||||
}
|
||||
refreshListData();
|
||||
}).bounds(0, 0, 20, 20).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractContent(@NonNull GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean isHovered, float partialTick) {
|
||||
int left = this.getX();
|
||||
int top = this.getY();
|
||||
int rowWidth = this.getWidth();
|
||||
int rowHeight = this.getHeight();
|
||||
graphics.pose().pushMatrix();
|
||||
graphics.pose().translate((float)left, (float)top);
|
||||
this.transferButton.extractRenderState(graphics, mouseX, mouseY, partialTick);
|
||||
SkyboxMod.LOGGER.debug("\n this font: " + Parent.getFont() + "\n this rowWidth:" + rowWidth + "\n this Text: " + this.textValue + "\n this Position: " + left +"_"+top);
|
||||
graphics.blit( Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "textures/no_texture.png"),0, 0,0 + 20, 0 + 20,0,1,0,1);
|
||||
graphics.text(Parent.getFont(), this.textValue, 0 + 4, 0 + 6, 0xFFFFFF, true);
|
||||
graphics.pose().popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(MouseButtonEvent event, boolean doubleclicked) {
|
||||
if (this.transferButton.mouseClicked(event, doubleclicked)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseClicked(event, doubleclicked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getNarration() {
|
||||
return Component.literal(this.textValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package net.halbear.skyboxmod.rendering.skybox;
|
||||
|
||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.halbear.skyboxmod.Config;
|
||||
import net.halbear.skyboxmod.SkyboxMod;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.halbear.skyboxmod.rendering.skybox.SkyBoxRendering.*;
|
||||
|
||||
public class DistantSkyObject {
|
||||
public static Map<Double, GpuBuffer> SkyObjectMeshMap = new HashMap<>();
|
||||
public static Map<String, DistantSkyObject> SkyObjectRegistry = new HashMap<>();
|
||||
public static Map<ResourceKey, List<String>> ObjectsMappedToDimension = new HashMap<>();
|
||||
public static float DayAlpha = 1.0f;
|
||||
public static float NightAlpha = 0.0f;
|
||||
|
||||
public static void RegenerateClouds(){
|
||||
SkyObjectRegistry.clear();
|
||||
ObjectsMappedToDimension.clear();
|
||||
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
|
||||
Identifier[] clouds = Config.Instance.GetAllClouds().toArray(new Identifier[0]);
|
||||
double[] aspectRatios = new double[clouds.length];
|
||||
for(int i = 0; i < clouds.length; i++){
|
||||
SkyboxMod.LOGGER.debug(clouds[i].getPath());
|
||||
AbstractTexture texture = textureManager.getTexture(clouds[i]);
|
||||
int width = texture.getTexture().getWidth(0);
|
||||
int height = texture.getTexture().getHeight(0);
|
||||
if(width != 0 && height != 0) {
|
||||
aspectRatios[i] = (double)width/(double)height;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < Config.CLOUD_COUNT.getAsInt(); i++){
|
||||
|
||||
int Index = (int)Math.min(clouds.length * Math.random(), clouds.length - 1);
|
||||
|
||||
String name = "Cloud"+ i;
|
||||
double MinSpeed = Config.MIN_CLOUD_SPEED.getAsDouble();
|
||||
double MaxSpeed = Config.MAX_CLOUD_SPEED.getAsDouble();
|
||||
float Speed = (float)(MinSpeed + (MaxSpeed - MinSpeed) *Math.random());
|
||||
DistantSkyObject.Action TickUpdateAction = new DistantSkyObject.Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
DistantSkyObject object = DistantSkyObject.SkyObjectRegistry.get(name);
|
||||
object.AddHorizontalDegrees(Speed);
|
||||
float DayAlpha = DistantSkyObject.DayAlpha;
|
||||
float NightAlpha = DistantSkyObject.NightAlpha;
|
||||
object.GetColourModifiers().set(0.75 + (DayAlpha * 0.25f) - (NightAlpha * 0.65f),0.35 + (DayAlpha * 0.65f) - (NightAlpha * 0.25f),0.25 + (DayAlpha * 0.75f) - (NightAlpha * 0.1f),1);
|
||||
}
|
||||
};
|
||||
|
||||
double MinCloudScale = Config.MIN_CLOUD_SCALE.getAsDouble();
|
||||
double MaxCloudScale = Config.MAX_CLOUD_SCALE.getAsDouble();
|
||||
float Scale = (float)(MinCloudScale + (Math.random() * (MaxCloudScale - MinCloudScale)));
|
||||
|
||||
double MinCloudAngle = (double)Config.MIN_CLOUD_VERTICAL_ANGLE.getAsInt();
|
||||
double MaxCloudAngle = (double)Config.MAX_CLOUD_VERTICALE_ANGLE.getAsInt();
|
||||
|
||||
new DistantSkyObject(name, clouds[Index], aspectRatios[Index],
|
||||
(float)Math.toRadians(360*Math.random()),(float)Math.toRadians(MinCloudAngle + ((MaxCloudAngle - MinCloudAngle) * Math.random())),
|
||||
new Vector3f(0,100,0),new Vector3f(-Scale,-1,Scale),new Vector4f(1,1,1,1))
|
||||
.AddToDimension(OVERWORLD)
|
||||
.OverrideTickFunction(TickUpdateAction)
|
||||
.Cloud();
|
||||
}
|
||||
}
|
||||
|
||||
public static void TickUpdate(ResourceKey Dimension){
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
long time = minecraft.level != null ? minecraft.level.getOverworldClockTime() % 24000 : 0;
|
||||
DayAlpha = getDayAlpha(time);
|
||||
NightAlpha = getNightAlpha(time);
|
||||
List<DistantSkyObject> objects = GetAllObjectsInDimenstion(Dimension);
|
||||
for(int i = 0; i < objects.size(); i++){
|
||||
objects.get(i).TickUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DistantSkyObject> GetAllObjectsInDimenstion(ResourceKey Dimension){
|
||||
List<String> Keys = ObjectsMappedToDimension.get(Dimension);
|
||||
if(Keys == null || Keys.isEmpty()) return new ArrayList<DistantSkyObject>();
|
||||
List<DistantSkyObject> objectsInDimentsion = new ArrayList<>();
|
||||
for(int i = 0; i < Keys.size(); i++){
|
||||
if(SkyObjectRegistry.containsKey(Keys.get(i)))objectsInDimentsion.add(SkyObjectRegistry.get(Keys.get(i)));
|
||||
}
|
||||
return objectsInDimentsion;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Action {
|
||||
void execute();
|
||||
}
|
||||
|
||||
private static GpuBuffer CreateMeshBuffer(double AspectRatio, float MeshScale, String ObjectName) {
|
||||
VertexFormat format = DefaultVertexFormat.POSITION_TEX;
|
||||
float Multipler = (float)AspectRatio;
|
||||
try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(4 * format.getVertexSize())) {
|
||||
BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, format);
|
||||
bufferBuilder.addVertex( MeshScale * Multipler, 0.0F, MeshScale).setUv(0.0F, 0.0F);
|
||||
bufferBuilder.addVertex( -MeshScale * Multipler, 0.0F, MeshScale).setUv(1.0F, 0.0F);
|
||||
bufferBuilder.addVertex( -MeshScale * Multipler, 0.0F, -MeshScale).setUv( 1.0F, 1.0F);
|
||||
bufferBuilder.addVertex( MeshScale * Multipler, 0.0F, -MeshScale).setUv( 0.0F, 1.0F);
|
||||
try (MeshData mesh = bufferBuilder.buildOrThrow()) {
|
||||
return RenderSystem.getDevice().createBuffer(() -> "Age of the Gods " + ObjectName +" Pass", 32, mesh.vertexBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ObjectType{
|
||||
Cloud,
|
||||
SkyObject
|
||||
}
|
||||
|
||||
private Identifier textureID;
|
||||
private double aspectRatio;
|
||||
private float HAngle;
|
||||
private float VAngle;
|
||||
private final String Name;
|
||||
private float NextHAngleAddition = 0;
|
||||
private float NextVAngleAddition = 0;
|
||||
private float PartialHAngle = HAngle;
|
||||
private float PartialVAngle = VAngle;
|
||||
private final Vector3f Translate;
|
||||
private final Vector3f Scale;
|
||||
private final Vector4f ColourModifiers;
|
||||
private ObjectType type;
|
||||
private Action ExecuteOnTick = new Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public DistantSkyObject Cloud(){
|
||||
this.type = ObjectType.Cloud;
|
||||
return this;
|
||||
}
|
||||
public DistantSkyObject SkyObject(){
|
||||
this.type = ObjectType.SkyObject;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DistantSkyObject AddToDimension(ResourceKey Dimension){
|
||||
if(!ObjectsMappedToDimension.containsKey(Dimension)){
|
||||
ObjectsMappedToDimension.put(Dimension, new ArrayList<String>());
|
||||
}
|
||||
ObjectsMappedToDimension.get(Dimension).add(Name);
|
||||
return this;
|
||||
}
|
||||
public DistantSkyObject RemoveFromDimension(ResourceKey Dimension){
|
||||
if(ObjectsMappedToDimension.containsKey(Dimension)){
|
||||
ObjectsMappedToDimension.get(Dimension).remove(Name);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DistantSkyObject TickUpdate(){
|
||||
HAngle += NextHAngleAddition;
|
||||
NextHAngleAddition = 0;
|
||||
VAngle += NextVAngleAddition;
|
||||
NextVAngleAddition = 0;
|
||||
ExecuteOnTick.execute();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DistantSkyObject PartialTick(double PartialTick){
|
||||
PartialHAngle = HAngle + (NextHAngleAddition * Math.clamp((float) PartialTick, 0, 1));
|
||||
PartialVAngle = VAngle + (NextVAngleAddition * Math.clamp((float) PartialTick, 0, 1));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DistantSkyObject OverrideTickFunction(Action newAction){
|
||||
ExecuteOnTick = newAction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DistantSkyObject GenerateBufferIfNonExistant(){
|
||||
if(!SkyObjectMeshMap.containsKey(aspectRatio)){
|
||||
GpuBuffer newMeshBuffer = CreateMeshBuffer(aspectRatio, 1f, Name);
|
||||
SkyObjectMeshMap.put(aspectRatio, newMeshBuffer);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public GpuBuffer GetMeshBuffer(){
|
||||
GenerateBufferIfNonExistant();
|
||||
return SkyObjectMeshMap.get(aspectRatio);
|
||||
}
|
||||
|
||||
public DistantSkyObject(String Name, Identifier TextureID, double AspectRatio, float HorizontalAngleRad, float VerticalAngleRad, Vector3f Translate, Vector3f Scale, Vector4f ColourModifiers){
|
||||
this.Name = Name;
|
||||
if(!SkyObjectRegistry.containsKey(Name)) SkyObjectRegistry.put(Name, this);
|
||||
this.Translate = Translate;
|
||||
this.Scale = Scale;
|
||||
this.ColourModifiers = ColourModifiers;
|
||||
this.textureID = TextureID;
|
||||
this.aspectRatio = AspectRatio;
|
||||
this.HAngle = HorizontalAngleRad;
|
||||
this.VAngle = VerticalAngleRad;
|
||||
PartialHAngle = HAngle;
|
||||
PartialVAngle = VAngle;
|
||||
}
|
||||
public void AddVerticalDegrees(float degrees){
|
||||
float Angle = GetVerticalAngleDegrees();
|
||||
Angle = (Angle + degrees) % 360;
|
||||
VAngle = (float)Math.toRadians(Angle);
|
||||
}
|
||||
public void AddHorizontalDegrees(float degrees){
|
||||
float Angle = GetHorizontalAngleDegrees();
|
||||
Angle = (Angle + degrees) % 360;
|
||||
HAngle = (float)Math.toRadians(Angle);
|
||||
}
|
||||
public Vector4f GetColourModifiers(){return ColourModifiers;}
|
||||
public Vector3f GetScale(){return Scale;}
|
||||
public Vector3f GetTranslate(){return Translate;}
|
||||
public String GetName(){return Name;}
|
||||
public double GetAspectRatio(){return aspectRatio;}
|
||||
public Identifier GetTextureID(){return textureID;}
|
||||
public float GetHorizontalAngleDegrees(){return (float)Math.toDegrees(HAngle);}
|
||||
public float GetHorizontalAngle(){return PartialHAngle;}
|
||||
public float GetRawHorizontalAngle(){return HAngle;}
|
||||
public float GetVerticalAngleDegrees(){return (float)Math.toDegrees(VAngle);}
|
||||
public float GetVerticalAngle(){return PartialVAngle;}
|
||||
public float GetRawVerticalAngle(){return VAngle;}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package net.halbear.skyboxmod.rendering.skybox;
|
||||
|
||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.systems.RenderPass;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Axis;
|
||||
import net.halbear.skyboxmod.Config;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.client.renderer.state.level.SkyRenderState;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fStack;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static net.halbear.skyboxmod.rendering.skybox.DistantSkyObject.RegenerateClouds;
|
||||
|
||||
@EventBusSubscriber(Dist.CLIENT)
|
||||
public class SkyBoxRendering {
|
||||
public static RenderPipeline CUSTOM_SKYBOX_PIPELINE;
|
||||
public static boolean CloudsRegistered = false;
|
||||
|
||||
private static GpuBuffer sunBuffer;
|
||||
private static GpuBuffer moonBuffer;
|
||||
private static GpuBuffer skyboxBuffer;
|
||||
public static final ResourceKey OVERWORLD = ResourceKey.create(Registries.DIMENSION, Identifier.parse("minecraft:overworld"));
|
||||
public static final Identifier OVERWORLD_DAY_SKYBOX = Identifier.parse("hals_skybox_mod:textures/skybox/skyboxcubemapday.png");
|
||||
public static final Identifier OVERWORLD_DUSK_SKYBOX = Identifier.parse("hals_skybox_mod:textures/skybox/cubemaptransitionskybox.png");
|
||||
public static final Identifier OVERWORLD_NIGHT_SKYBOX = Identifier.parse("hals_skybox_mod:textures/skybox/cubemapnightskybox.png");
|
||||
public static final Identifier OVERWORLD_SUN = Identifier.parse("hals_skybox_mod:textures/suntexture.png");
|
||||
public static final Identifier OVERWORLD_MOON = Identifier.parse("hals_skybox_mod:textures/moontexture.png");
|
||||
|
||||
private static void initBuffers() {
|
||||
if (sunBuffer == null)
|
||||
sunBuffer = buildCelestialBuffer(1.0f, "Sun");
|
||||
if (moonBuffer == null)
|
||||
moonBuffer = buildCelestialBuffer(1.0f, "Moon");
|
||||
if (skyboxBuffer == null)
|
||||
skyboxBuffer = buildSkyboxBuffer();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void renderSky(RenderLevelStageEvent.AfterSky event) {
|
||||
if(!CloudsRegistered){
|
||||
DistantSkyObject.RegenerateClouds();
|
||||
CloudsRegistered = true;
|
||||
}
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.player == null)
|
||||
return;
|
||||
if (minecraft.player.level().dimension() == OVERWORLD) {
|
||||
if(Config.RENDER_SKYBOX.getAsBoolean()) {
|
||||
renderCustomSkybox(event, OVERWORLD_DAY_SKYBOX, OVERWORLD_NIGHT_SKYBOX, OVERWORLD_DUSK_SKYBOX);
|
||||
}
|
||||
if(Config.RENDER_SUN.getAsBoolean())renderCustomSun(event, OVERWORLD_SUN);
|
||||
if(Config.RENDER_MOON.getAsBoolean())renderCustomMoon(event, OVERWORLD_MOON);
|
||||
}
|
||||
List<DistantSkyObject> SkyObjects = DistantSkyObject.GetAllObjectsInDimenstion(minecraft.player.level().dimension());
|
||||
if(!SkyObjects.isEmpty() && Config.RENDER_CLOUDS.getAsBoolean()){
|
||||
for (DistantSkyObject object : SkyObjects) {
|
||||
object.PartialTick(minecraft.getDeltaTracker().getGameTimeDeltaPartialTick(false));
|
||||
render2DObjectInSkybox(event, object.GetTextureID(), object.GetName(),object.GetHorizontalAngle(),object.GetVerticalAngle(),object.GetTranslate(),object.GetScale(),object.GetColourModifiers(),object.GetMeshBuffer(), CUSTOM_SKYBOX_PIPELINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSkyboxFace(BufferBuilder bufferBuilder, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4,
|
||||
float u4, float v4, int colour) {
|
||||
bufferBuilder.addVertex(x1, y1, z1).setUv(u1, v1).setColor(colour);
|
||||
bufferBuilder.addVertex(x2, y2, z2).setUv(u2, v2).setColor(colour);
|
||||
bufferBuilder.addVertex(x3, y3, z3).setUv(u3, v3).setColor(colour);
|
||||
bufferBuilder.addVertex(x4, y4, z4).setUv(u4, v4).setColor(colour);
|
||||
}
|
||||
|
||||
public static void render2DObjectInSkybox(RenderLevelStageEvent.AfterSky event, Identifier textureId, String Name, float HorizontalRotationRad, float VerticalRotationRad, Vector3f Translate, Vector3f Scale, Vector4f colourModulator, GpuBuffer meshBuffer, RenderPipeline pipeline) {
|
||||
initBuffers();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
PoseStack poseStack = event.getPoseStack();
|
||||
SkyRenderState state = event.getLevelRenderState().skyRenderState;
|
||||
poseStack.pushPose();
|
||||
poseStack.mulPose(Axis.YP.rotation(HorizontalRotationRad));
|
||||
poseStack.mulPose(Axis.XP.rotation(VerticalRotationRad));
|
||||
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
|
||||
modelViewStack.pushMatrix();
|
||||
modelViewStack.mul(poseStack.last().pose());
|
||||
modelViewStack.translate(Translate);
|
||||
modelViewStack.scale(Scale);
|
||||
GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms().writeTransform(modelViewStack, colourModulator, new Vector3f(), new Matrix4f());
|
||||
GpuTextureView colour = minecraft.getMainRenderTarget().getColorTextureView();
|
||||
GpuTextureView depth = minecraft.getMainRenderTarget().getDepthTextureView();
|
||||
GpuBuffer indexBuffer = RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).getBuffer(6);
|
||||
AbstractTexture texture = minecraft.getTextureManager().getTexture(textureId);
|
||||
try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Age of the Gods Skybox Object [" + Name + "]", colour, OptionalInt.empty(), depth, OptionalDouble.empty())) {
|
||||
renderPass.setPipeline(pipeline);
|
||||
RenderSystem.bindDefaultUniforms(renderPass);
|
||||
renderPass.setUniform("DynamicTransforms", dynamicTransforms);
|
||||
renderPass.bindTexture("Sampler0", texture.getTextureView(), texture.getSampler());
|
||||
renderPass.setVertexBuffer(0, meshBuffer);
|
||||
renderPass.setIndexBuffer(indexBuffer, RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).type());
|
||||
renderPass.drawIndexed(0, 0, 6, 1);
|
||||
}
|
||||
modelViewStack.popMatrix();
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
public static void renderCustomSun(RenderLevelStageEvent.AfterSky event, Identifier textureId) {
|
||||
initBuffers();
|
||||
SkyRenderState state = event.getLevelRenderState().skyRenderState;
|
||||
RenderPipeline pipeline = Config.RENDER_SUN_TRANSLUCENCY.getAsBoolean() ? CUSTOM_SKYBOX_PIPELINE : RenderPipelines.CELESTIAL;
|
||||
render2DObjectInSkybox(event, textureId, "Sun",(float)Math.toRadians(-90F),state.sunAngle,new Vector3f(0,100.0f,0),new Vector3f((float)Config.SUN_SCALE.getAsDouble(),-1.0F,(float)Config.SUN_SCALE.getAsDouble()),new Vector4f(1f,1f,1f,state.rainBrightness), sunBuffer,pipeline);
|
||||
}
|
||||
|
||||
public static void renderCustomMoon(RenderLevelStageEvent.AfterSky event, Identifier textureId) {
|
||||
initBuffers();
|
||||
SkyRenderState state = event.getLevelRenderState().skyRenderState;
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
long time = minecraft.level != null ? minecraft.level.getOverworldClockTime() % 24000 : 0;
|
||||
float DayAlpha = DistantSkyObject.DayAlpha;
|
||||
float NightAlpha = DistantSkyObject.NightAlpha;
|
||||
RenderPipeline pipeline = Config.RENDER_MOON_TRANSLUCENCY.getAsBoolean() ? CUSTOM_SKYBOX_PIPELINE : RenderPipelines.CELESTIAL;
|
||||
render2DObjectInSkybox(event, textureId, "Moon",(float)Math.toRadians(-90F),state.moonAngle,new Vector3f(0,100.0f,0),new Vector3f((float)Config.MOON_SCALE.getAsDouble(),-1.0F,(float)Config.MOON_SCALE.getAsDouble()),new Vector4f((float) (0.75 + (DayAlpha * 0.25f) + (NightAlpha * 0.25f)), (float) (0.35 + (DayAlpha * 0.65f) + (NightAlpha * 0.65f)), (float) (0.25 + (DayAlpha * 0.75f) + (NightAlpha * 0.75f)),1), moonBuffer,pipeline);//RenderPipelines.CELESTIAL);
|
||||
}
|
||||
|
||||
public static float getNightAlpha(long dayTime) {
|
||||
long time = dayTime % 24000;
|
||||
|
||||
if (time >= 13000) {
|
||||
if (time < 15000) return (float) (time-13000) / 2000.0F;
|
||||
if (time > 22000) return 1.0F - ((float)(time - 22000) / 2000.0F);
|
||||
return 1.0F;
|
||||
}
|
||||
return 0.0F;
|
||||
}
|
||||
public static float getDayAlpha(long dayTime) {
|
||||
long time = dayTime % 24000;
|
||||
|
||||
if (time >= 0 && time < 13000) {
|
||||
if (time < 2000) return (float) time / 2000.0F;
|
||||
if (time > 11000) return 1.0F - ((float)(time - 11000) / 2000.0F);
|
||||
return 1.0F;
|
||||
}
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
|
||||
public static void renderCustomSkybox(RenderLevelStageEvent.AfterSky event, Identifier daytextureId, Identifier nighttextureid, Identifier dusktextureid) {
|
||||
initBuffers();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
long time = minecraft.level != null ? minecraft.level.getOverworldClockTime() % 24000 : 0;
|
||||
float dayAlpha = getDayAlpha(time);
|
||||
float nightAlpha = getNightAlpha(time);
|
||||
PoseStack poseStack = event.getPoseStack();
|
||||
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
|
||||
modelViewStack.pushMatrix();
|
||||
modelViewStack.mul(poseStack.last().pose());
|
||||
GpuTextureView colour = minecraft.getMainRenderTarget().getColorTextureView();
|
||||
GpuTextureView depth = minecraft.getMainRenderTarget().getDepthTextureView();
|
||||
GpuBuffer indexBuffer = RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).getBuffer(36);
|
||||
GpuBufferSlice dynamicTransforms = RenderSystem.getDynamicUniforms().writeTransform(modelViewStack, new Vector4f(1.0F, 1.0F, 1.0F, 1.0F), new Vector3f(), new Matrix4f());
|
||||
AbstractTexture texture = minecraft.getTextureManager().getTexture(dusktextureid);
|
||||
try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Age of the Gods Dusk Skybox", colour, OptionalInt.empty(), depth, OptionalDouble.empty())) {
|
||||
renderPass.setPipeline(RenderPipelines.END_SKY);
|
||||
RenderSystem.bindDefaultUniforms(renderPass);
|
||||
renderPass.setUniform("DynamicTransforms", dynamicTransforms);
|
||||
renderPass.bindTexture("Sampler0", texture.getTextureView(), texture.getSampler());
|
||||
renderPass.setVertexBuffer(0, skyboxBuffer);
|
||||
renderPass.setIndexBuffer(indexBuffer, RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).type());
|
||||
renderPass.drawIndexed(0, 0, 36, 1);
|
||||
}
|
||||
dynamicTransforms = RenderSystem.getDynamicUniforms().writeTransform(modelViewStack, new Vector4f(1.0F, 1.0F, 1.0F, dayAlpha), new Vector3f(), new Matrix4f());
|
||||
texture = minecraft.getTextureManager().getTexture(daytextureId);
|
||||
try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Age of the Gods Day Skybox", colour, OptionalInt.empty(), depth, OptionalDouble.empty())) {
|
||||
renderPass.setPipeline(RenderPipelines.END_SKY);
|
||||
RenderSystem.bindDefaultUniforms(renderPass);
|
||||
renderPass.setUniform("DynamicTransforms", dynamicTransforms);
|
||||
renderPass.bindTexture("Sampler0", texture.getTextureView(), texture.getSampler());
|
||||
renderPass.setVertexBuffer(0, skyboxBuffer);
|
||||
renderPass.setIndexBuffer(indexBuffer, RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).type());
|
||||
renderPass.drawIndexed(0, 0, 36, 1);
|
||||
}
|
||||
dynamicTransforms = RenderSystem.getDynamicUniforms().writeTransform(modelViewStack, new Vector4f(1.0F, 1.0F, 1.0F, nightAlpha), new Vector3f(), new Matrix4f());
|
||||
texture = minecraft.getTextureManager().getTexture(nighttextureid);
|
||||
try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Age of the Gods Night Skybox", colour, OptionalInt.empty(), depth, OptionalDouble.empty())) {
|
||||
renderPass.setPipeline(RenderPipelines.END_SKY);
|
||||
RenderSystem.bindDefaultUniforms(renderPass);
|
||||
renderPass.setUniform("DynamicTransforms", dynamicTransforms);
|
||||
renderPass.bindTexture("Sampler0", texture.getTextureView(), texture.getSampler());
|
||||
renderPass.setVertexBuffer(0, skyboxBuffer);
|
||||
renderPass.setIndexBuffer(indexBuffer, RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS).type());
|
||||
renderPass.drawIndexed(0, 0, 36, 1);
|
||||
}
|
||||
modelViewStack.popMatrix();
|
||||
}
|
||||
|
||||
public static float MoonScale = 0.75f;
|
||||
public static float SunScale = 0.75f;
|
||||
|
||||
private static GpuBuffer buildCelestialBuffer(float CelestialScale, String CelestialObjectName) {
|
||||
VertexFormat format = DefaultVertexFormat.POSITION_TEX;
|
||||
|
||||
try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(4 * format.getVertexSize())) {
|
||||
BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, format);
|
||||
bufferBuilder.addVertex( -CelestialScale, 0.0F, -CelestialScale).setUv(0.0F, 0.0F);
|
||||
bufferBuilder.addVertex( CelestialScale, 0.0F, -CelestialScale).setUv(1.0F, 0.0F);
|
||||
bufferBuilder.addVertex( CelestialScale, 0.0F, CelestialScale).setUv( 1.0F, 1.0F);
|
||||
bufferBuilder.addVertex( -CelestialScale, 0.0F, CelestialScale).setUv( 0.0F, 1.0F);
|
||||
try (MeshData mesh = bufferBuilder.buildOrThrow()) {
|
||||
return RenderSystem.getDevice().createBuffer(() -> "Age of the Gods " + CelestialObjectName +" Pass", 32, mesh.vertexBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static GpuBuffer buildSkyboxBuffer() {
|
||||
VertexFormat format = DefaultVertexFormat.POSITION_TEX_COLOR;
|
||||
try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder.exactlySized(24 * format.getVertexSize())) {
|
||||
BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, format);
|
||||
float distance = 100.0F;
|
||||
float size = 100.0F;
|
||||
int colour = 0xFFFFFFFF;
|
||||
addSkyboxFace(bufferBuilder, -size, distance, -size, 1.0F / 4.0F, 1.0F / 3.0F, size, distance, -size, 2.0F / 4.0F, 1.0F / 3.0F, size, distance, size, 2.0F / 4.0F, 0.0F, -size, distance, size, 1.0F / 4.0F, 0.0F, colour);
|
||||
addSkyboxFace(bufferBuilder, -size, -distance, -size, 1.0F / 4.0F, 2.0F / 3.0F, -size, -distance, size, 1.0F / 4.0F, 3.0F / 3.0F, size, -distance, size, 2.0F / 4.0F, 3.0F / 3.0F, size, -distance, -size, 2.0F / 4.0F, 2.0F / 3.0F, colour);
|
||||
addSkyboxFace(bufferBuilder, -distance, -size, size, 0.0F, 2.0F / 3.0F, -distance, -size, -size, 1.0F / 4.0F, 2.0F / 3.0F, -distance, size, -size, 1.0F / 4.0F, 1.0F / 3.0F, -distance, size, size, 0.0F, 1.0F / 3.0F, colour);
|
||||
addSkyboxFace(bufferBuilder, -size, -size, -distance, 1.0F / 4.0F, 2.0F / 3.0F, size, -size, -distance, 2.0F / 4.0F, 2.0F / 3.0F, size, size, -distance, 2.0F / 4.0F, 1.0F / 3.0F, -size, size, -distance, 1.0F / 4.0F, 1.0F / 3.0F, colour);
|
||||
addSkyboxFace(bufferBuilder, distance, -size, -size, 2.0F / 4.0F, 2.0F / 3.0F, distance, -size, size, 3.0F / 4.0F, 2.0F / 3.0F, distance, size, size, 3.0F / 4.0F, 1.0F / 3.0F, distance, size, -size, 2.0F / 4.0F, 1.0F / 3.0F, colour);
|
||||
addSkyboxFace(bufferBuilder, size, -size, distance, 3.0F / 4.0F, 2.0F / 3.0F, -size, -size, distance, 4.0F / 4.0F, 2.0F / 3.0F, -size, size, distance, 4.0F / 4.0F, 1.0F / 3.0F, size, size, distance, 3.0F / 4.0F, 1.0F / 3.0F, colour);
|
||||
try (MeshData meshData = bufferBuilder.buildOrThrow()) {
|
||||
return RenderSystem.getDevice().createBuffer(() -> "Age of the Gods Skybox", 40, meshData.vertexBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.halbear.skyboxmod.utility;
|
||||
|
||||
import net.halbear.skyboxmod.SkyboxMod;
|
||||
import net.halbear.skyboxmod.rendering.screen.ConfigScreen;
|
||||
import net.halbear.skyboxmod.rendering.skybox.DistantSkyObject;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@EventBusSubscriber(modid = SkyboxMod.MODID, value = Dist.CLIENT)
|
||||
public class ClientEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(ClientTickEvent.Pre event) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.level != null && mc.player != null) {
|
||||
DistantSkyObject.TickUpdate(mc.level.dimension());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSkinCustomizationButton(Component component) {
|
||||
if (component.getContents() instanceof TranslatableContents translatable) {
|
||||
return "options.skinCustomisation".equals(translatable.getKey());
|
||||
}
|
||||
return component.getString().contains("Skin Customization");
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onScreenInit(ScreenEvent.Init.Post event) {
|
||||
if (event.getScreen() instanceof OptionsScreen pauseScreen) {
|
||||
for (var listener : event.getListenersList()) {
|
||||
if (listener instanceof AbstractWidget widget) {
|
||||
Component message = widget.getMessage();
|
||||
SkyboxMod.LOGGER.debug(message.getString());
|
||||
if (isSkinCustomizationButton(message)) {
|
||||
|
||||
int targetX = widget.getX();
|
||||
int targetY = widget.getY();
|
||||
int targetWidth = widget.getWidth();
|
||||
int targetHeight = widget.getHeight();
|
||||
SkyboxMod.LOGGER.debug("New Button Tiiime");
|
||||
|
||||
int myButtonX = targetX;
|
||||
int myButtonY = targetY - targetHeight - 4;
|
||||
|
||||
Button customMenuButton= new Button(
|
||||
myButtonX, myButtonY, widget.getWidth(), widget.getHeight(),
|
||||
Component.translatable("hals_skybox_mod.gui.optionsbutton"),
|
||||
button -> {
|
||||
SkyboxMod.LOGGER.debug("Cliiick!");
|
||||
net.minecraft.client.Minecraft.getInstance().setScreen(
|
||||
new ConfigScreen(pauseScreen,pauseScreen.getMinecraft().options)
|
||||
);
|
||||
}, new Button.CreateNarration() {
|
||||
@Override
|
||||
public MutableComponent createNarrationMessage(Supplier<MutableComponent> supplier) {
|
||||
return Component.translatable("hals_skybox_mod.gui.optionsbutton");
|
||||
}
|
||||
}
|
||||
) {
|
||||
@Override
|
||||
protected void extractContents(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
this.setX(widget.getX());
|
||||
this.setY(widget.getY() - widget.getHeight() - 4);
|
||||
this.setWidth(targetWidth);
|
||||
this.setHeight(targetHeight);
|
||||
|
||||
this.extractDefaultSprite(guiGraphics);
|
||||
this.extractDefaultLabel(guiGraphics.textRendererForWidget(this, GuiGraphicsExtractor.HoveredTextEffects.NONE));
|
||||
// SkyboxMod.LOGGER.debug("Resize: xy:" + widget.getX() + "_" + widget.getY() + " wh:" + targetWidth + "x" + targetHeight);
|
||||
}
|
||||
};
|
||||
|
||||
event.getScreen().renderables.add(customMenuButton);
|
||||
event.addListener(customMenuButton);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.halbear.skyboxmod.utility;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||
import com.mojang.blaze3d.pipeline.ColorTargetState;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import net.halbear.skyboxmod.SkyboxMod;
|
||||
import net.halbear.skyboxmod.rendering.skybox.SkyBoxRendering;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.RegisterRenderPipelinesEvent;
|
||||
|
||||
import static net.minecraft.client.renderer.RenderPipelines.MATRICES_PROJECTION_SNIPPET;
|
||||
|
||||
@EventBusSubscriber(modid = SkyboxMod.MODID, value = Dist.CLIENT)
|
||||
public class ModEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterPipelines(RegisterRenderPipelinesEvent event) {
|
||||
SkyBoxRendering.CUSTOM_SKYBOX_PIPELINE = RenderPipeline.builder(new RenderPipeline.Snippet[]{MATRICES_PROJECTION_SNIPPET})
|
||||
.withLocation(Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "pipeline/custom_skybox"))
|
||||
.withVertexShader(Identifier.withDefaultNamespace("core/position_tex"))
|
||||
.withFragmentShader(Identifier.withDefaultNamespace("core/position_tex"))
|
||||
.withSampler("Sampler0")
|
||||
.withCull(false)
|
||||
.withColorTargetState(new ColorTargetState(BlendFunction.TRANSLUCENT)).withVertexFormat(DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.QUADS).build();
|
||||
|
||||
event.registerPipeline(SkyBoxRendering.CUSTOM_SKYBOX_PIPELINE);
|
||||
System.out.println("Hal's Skybox Mod pipeline Registered");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
|
||||
"hals_skybox_mod.configuration.title": "Hal's Skybox Configs",
|
||||
"hals_skybox_mod.configuration.section.ageofthegods.common.toml": "Hal's Skybox Configs",
|
||||
"hals_skybox_mod.configuration.section.ageofthegods.common.toml.title": "Hal's Skybox Configs",
|
||||
"hals_skybox_mod.configuration.items": "Item List",
|
||||
"hals_skybox_mod.configuration.logDirtBlock": "Log Dirt Block",
|
||||
"hals_skybox_mod.configuration.magicNumberIntroduction": "Magic Number Text",
|
||||
"hals_skybox_mod.configuration.magicNumber": "Magic Number",
|
||||
|
||||
"hals_skybox_mod.gui.optionsbutton": "Skybox Configuration",
|
||||
"hals_skybox_config.cloud_object_count.max": "Capped at 1024",
|
||||
"hals_skybox_config.cloud_object_count": "Skybox Cloud Object Count",
|
||||
"hals_skybox_config.cloud_min_speed.max": "1°/tick",
|
||||
"hals_skybox_config.cloud_max_speed.max": "1°/tick",
|
||||
"hals_skybox_config.cloud_min_speed": "Minimum Cloud Speed",
|
||||
"hals_skybox_config.cloud_max_speed": "Maximum Cloud Speed",
|
||||
"hals_skybox_config.cloud_header": "Cloud Configuration",
|
||||
"hals_skybox_config.min_cloud_speed": "Min Speed",
|
||||
"hals_skybox_config.max_cloud_speed": "Max Speed",
|
||||
"hals_skybox_config.max_cloud_vertical_angle": "Max Angle",
|
||||
"hals_skybox_config.min_cloud_vertical_angle": "Min Angle",
|
||||
"hals_skybox_config.min_cloud_scale": "Min Scale",
|
||||
"hals_skybox_config.max_cloud_scale": "Max Scale",
|
||||
"hals_skybox_config.open_cloud_images_location": "Open cloud image folder",
|
||||
"hals_skybox_config.celestial_header": "Celestial Configuration",
|
||||
"hals_skybox_config.general_header": "General Settings",
|
||||
"hals_skybox_config.moon_scale": "Moon Scale",
|
||||
"hals_skybox_config.sun_scale": "Sun Scale",
|
||||
"hals_skybox_config.render_sun": "Render Sun",
|
||||
"hals_skybox_config.render_moon": "Render Moon",
|
||||
"hals_skybox_config.render_skybox": "Render Skybox",
|
||||
"hals_skybox_config.render_clouds": "Render Clouds",
|
||||
"hals_skybox_config.render_sun_translucent": "Render Sun as Translucent",
|
||||
"hals_skybox_config.render_moon_translucent": "Render Moon as Translucent",
|
||||
"hals_skybox_config.open_cloud_sprites": "Select Cloud Sprites"
|
||||
}
|
||||
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 553 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 179 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 593 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 217 KiB |
|
After Width: | Height: | Size: 346 KiB |
|
After Width: | Height: | Size: 347 KiB |
|
After Width: | Height: | Size: 326 KiB |
|
After Width: | Height: | Size: 1000 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"pack": {
|
||||
"min_format": 100.0,
|
||||
"max_format": 101.1,
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
# This is an example neoforge.mods.toml file. It contains the data relating to the loading mods.
|
||||
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
|
||||
# The overall format is standard TOML format, v0.5.0.
|
||||
# Note that there are a couple of TOML lists in this file.
|
||||
# Find more information on toml format here: https://github.com/toml-lang/toml
|
||||
|
||||
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
||||
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
||||
license="${mod_license}"
|
||||
|
||||
# A URL to refer people to when problems occur with this mod
|
||||
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
|
||||
|
||||
# A list of mods - how many allowed here is determined by the individual mod loader
|
||||
[[mods]] #mandatory
|
||||
|
||||
# The modid of the mod
|
||||
modId="${mod_id}" #mandatory
|
||||
|
||||
# The version number of the mod
|
||||
version="${mod_version}" #mandatory
|
||||
|
||||
# A display name for the mod
|
||||
displayName="${mod_name}" #mandatory
|
||||
|
||||
# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforged.net/docs/misc/updatechecker/
|
||||
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
|
||||
|
||||
# A URL for the "homepage" for this mod, displayed in the mod UI
|
||||
displayURL="https://halbear.net/" #optional
|
||||
|
||||
# A file name (in the root of the mod JAR) containing a logo for display
|
||||
logoFile="moon_texture.png" #optional
|
||||
|
||||
client_side_only=true
|
||||
|
||||
# The authors of the mod, displayed in the mod UI (optional)
|
||||
authors="Halbear1"
|
||||
|
||||
# The description text for the mod (multi line!) (#mandatory)
|
||||
description='''
|
||||
A customisable Skybox Mod
|
||||
'''
|
||||
|
||||
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
|
||||
|
||||
# The [[accessTransformers]] block allows you to declare where your AT file is.
|
||||
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
|
||||
#[[accessTransformers]]
|
||||
#file="META-INF/accesstransformer.cfg"
|
||||
|
||||
# The coremods config file path is not configurable and is always loaded from META-INF/coremods.json
|
||||
|
||||
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
||||
[[dependencies.${mod_id}]] #optional
|
||||
# the modid of the dependency
|
||||
modId="neoforge" #mandatory
|
||||
# The type of the dependency. Can be one of "required", "optional", "incompatible" or "discouraged" (case insensitive).
|
||||
# 'required' requires the mod to exist, 'optional' does not
|
||||
# 'incompatible' will prevent the game from loading when the mod exists, and 'discouraged' will show a warning
|
||||
type="required" #mandatory
|
||||
# Optional field describing why the dependency is required or why it is incompatible
|
||||
# reason="..."
|
||||
# The version range of the dependency
|
||||
versionRange="[${neo_version},)" #mandatory
|
||||
# An ordering relationship for the dependency.
|
||||
# BEFORE - This mod is loaded BEFORE the dependency
|
||||
# AFTER - This mod is loaded AFTER the dependency
|
||||
ordering="NONE"
|
||||
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
|
||||
side="BOTH"
|
||||
|
||||
# Here's another dependency
|
||||
[[dependencies.${mod_id}]]
|
||||
modId="minecraft"
|
||||
type="required"
|
||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||
versionRange="${minecraft_version_range}"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
|
||||
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
|
||||
# stop your mod loading on the server for example.
|
||||
#[features.${mod_id}]
|
||||
#openGLVersion="[3.2,)"
|
||||