Skip to content

Commit

Permalink
Merge branch '1.19.x-dev' into 1.19.x-main
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Jul 12, 2023
2 parents 5a58b4e + 0ca490d commit 55a6aa7
Show file tree
Hide file tree
Showing 23 changed files with 435 additions and 143 deletions.
8 changes: 4 additions & 4 deletions docs/schema-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ Stores a list of four integers which specify the time in ticks to start and end

| Name | Datatype | Description | Required | Default |
|:--------------:|:--------:|:-------------------------------------------------------:|:--------:|:-------:|
| `startFadeIn` | Integer | The times in ticks when a skybox will start to fade in | :x: | -1 |
| `endFadeIn` | Integer | The times in ticks when a skybox will end fading in | :x: | -1 |
| `startFadeOut` | Integer | The times in ticks when a skybox will start to fade out | :x: | -1 |
| `endFadeOut` | Integer | The times in ticks when a skybox will end fading out | :x: | -1 |
| `startFadeIn` | Integer | The times in ticks when a skybox will start to fade in | :x: | 0 |
| `endFadeIn` | Integer | The times in ticks when a skybox will end fading in | :x: | 0 |
| `startFadeOut` | Integer | The times in ticks when a skybox will start to fade out | :x: | 0 |
| `endFadeOut` | Integer | The times in ticks when a skybox will end fading out | :x: | 0 |
| `alwaysOn` | Boolean | Whether the skybox should always be at full visibility | :x: | false |

**Conversion Table**
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.21
# Mod Properties
mod_version=0.7.1
mod_version=0.7.2
maven_group=io.github.amerebagatelle
archives_base_name=fabricskyboxes
# Dependencies
fabric_version=0.82.0+1.19.4
fabric_version=0.84.0+1.19.4
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package io.github.amerebagatelle.fabricskyboxes;

import io.github.amerebagatelle.fabricskyboxes.config.FabricSkyBoxesConfig;
import io.github.amerebagatelle.fabricskyboxes.resource.SkyboxResourceListener;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class FabricSkyBoxesClient implements ClientModInitializer {
public static final String MODID = "fabricskyboxes";
private static Logger LOGGER;
private static KeyBinding toggleFabricSkyBoxes;
private static FabricSkyBoxesConfig CONFIG;

public static Logger getLogger() {
if (LOGGER == null) {
Expand All @@ -29,22 +26,24 @@ public static Logger getLogger() {
return LOGGER;
}

public static FabricSkyBoxesConfig config() {
if (CONFIG == null) {
CONFIG = loadConfig();
}

return CONFIG;
}

private static FabricSkyBoxesConfig loadConfig() {
return FabricSkyBoxesConfig.load(FabricLoader.getInstance().getConfigDir().resolve("fabricskyboxes-config.json").toFile());
}

@Override
public void onInitializeClient() {
SkyboxType.initRegistry();
toggleFabricSkyBoxes = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_0, "category.fabricskyboxes"));
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SkyboxResourceListener());
SkyboxManager.getInstance().setEnabled(config().generalSettings.enable);
ClientTickEvents.END_WORLD_TICK.register(SkyboxManager.getInstance());
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (toggleFabricSkyBoxes.wasPressed()) {
SkyboxManager.getInstance().setEnabled(!SkyboxManager.getInstance().isEnabled());
assert client.player != null;
if (SkyboxManager.getInstance().isEnabled()) {
client.player.sendMessage(Text.translatable("fabricskyboxes.message.enabled"), false);
} else {
client.player.sendMessage(Text.translatable("fabricskyboxes.message.disabled"), false);
}
}
});
ClientTickEvents.END_CLIENT_TICK.register(config().getKeyBinding());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void addSkybox(Identifier identifier, JsonObject jsonObject) {
Skybox skybox = SkyboxManager.parseSkyboxJson(identifier, new JsonObjectWrapper(jsonObject));
if (skybox != null) {
this.addSkybox(identifier, skybox);
this.sortSkybox();
}
}

Expand Down Expand Up @@ -164,21 +163,16 @@ public List<Skybox> getActiveSkyboxes() {
}

@Override
public void onEndTick(ClientWorld world) {
// Add the skyboxes to a activeSkyboxes container so that they can be ordered
this.skyboxMap.values().stream().filter(this.renderPredicate).forEach(this.activeSkyboxes::add);
this.permanentSkyboxMap.values().stream().filter(this.renderPredicate).forEach(this.activeSkyboxes::add);

// Let's not sort by alpha value
//this.activeSkyboxes.sort((skybox1, skybox2) -> skybox1 instanceof FSBSkybox fsbSkybox1 && skybox2 instanceof FSBSkybox fsbSkybox2 ? Float.compare(fsbSkybox1.getAlpha(), fsbSkybox2.getAlpha()) : 0);
this.activeSkyboxes.sort((skybox1, skybox2) -> skybox1 instanceof FSBSkybox fsbSkybox1 && skybox2 instanceof FSBSkybox fsbSkybox2 ? Integer.compare(fsbSkybox1.getPriority(), fsbSkybox2.getPriority()) : 0);

public void onEndTick(ClientWorld client) {
this.totalAlpha = (float) StreamSupport
.stream(Iterables.concat(this.skyboxMap.values(), this.permanentSkyboxMap.values()).spliterator(), false)
.filter(FSBSkybox.class::isInstance)
.map(FSBSkybox.class::cast)
.mapToDouble(FSBSkybox::updateAlpha).sum();

this.activeSkyboxes.removeIf(skybox -> !skybox.isActiveLater());
this.activeSkyboxes.removeIf(skybox -> !skybox.isActive());
// Add the skyboxes to a activeSkyboxes container so that they can be ordered
this.skyboxMap.values().stream().filter(this.renderPredicate).forEach(this.activeSkyboxes::add);
this.permanentSkyboxMap.values().stream().filter(this.renderPredicate).forEach(this.activeSkyboxes::add);
this.activeSkyboxes.sort((skybox1, skybox2) -> skybox1 instanceof FSBSkybox fsbSkybox1 && skybox2 instanceof FSBSkybox fsbSkybox2 ? Integer.compare(fsbSkybox1.getPriority(), fsbSkybox2.getPriority()) : 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.amerebagatelle.fabricskyboxes.util.object.Conditions;
import io.github.amerebagatelle.fabricskyboxes.util.object.Decorations;
import io.github.amerebagatelle.fabricskyboxes.util.object.Properties;
import io.github.amerebagatelle.fabricskyboxes.util.object.RGBA;

public interface FSBSkybox extends Skybox {
float getAlpha();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ default int getPriority() {
* @return State of the skybox.
*/
boolean isActive();

/**
* Whether the skybox will be active in the next frame.
*
* @return State of skybox of the next frame.
*/
boolean isActiveLater();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.github.amerebagatelle.fabricskyboxes.config;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.github.amerebagatelle.fabricskyboxes.FabricSkyBoxesClient;
import io.github.amerebagatelle.fabricskyboxes.SkyboxManager;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Modifier;

public class FabricSkyBoxesConfig {
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithModifiers(Modifier.PRIVATE)
.create();
public final GeneralSettings generalSettings = new GeneralSettings();
private final KeyBindingImpl keyBinding = new KeyBindingImpl();
private File file;

public static FabricSkyBoxesConfig load(File file) {
FabricSkyBoxesConfig config;
if (file.exists()) {
try (FileReader reader = new FileReader(file)) {
config = GSON.fromJson(reader, FabricSkyBoxesConfig.class);
} catch (Exception e) {
FabricSkyBoxesClient.getLogger().error("Could not parse config, falling back to defaults!", e);
config = new FabricSkyBoxesConfig();
}
} else {
config = new FabricSkyBoxesConfig();
}
config.file = file;
config.save();

return config;
}

public KeyBindingImpl getKeyBinding() {
return this.keyBinding;
}

public void save() {
File dir = this.file.getParentFile();

if (!dir.exists()) {
if (!dir.mkdirs()) {
throw new RuntimeException("Could not create parent directories");
}
} else if (!dir.isDirectory()) {
throw new RuntimeException("The parent file is not a directory");
}

try (FileWriter writer = new FileWriter(this.file)) {
GSON.toJson(this, writer);
} catch (IOException e) {
throw new RuntimeException("Could not save configuration file", e);
}
}

public static class GeneralSettings {
public boolean enable = true;
public int unexpectedTransitionDuration = 20;

public boolean debugMode = false;
}


public static class KeyBindingImpl implements ClientTickEvents.EndTick {

public final KeyBinding toggleFabricSkyBoxes;

public KeyBindingImpl() {
this.toggleFabricSkyBoxes = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_0, "category.fabricskyboxes"));
}

@Override
public void onEndTick(MinecraftClient client) {
while (this.toggleFabricSkyBoxes.wasPressed()) {
FabricSkyBoxesClient.config().generalSettings.enable = !FabricSkyBoxesClient.config().generalSettings.enable;
FabricSkyBoxesClient.config().save();
SkyboxManager.getInstance().setEnabled(FabricSkyBoxesClient.config().generalSettings.enable);

assert client.player != null;
if (SkyboxManager.getInstance().isEnabled()) {
client.player.sendMessage(Text.translatable("fabricskyboxes.message.enabled"), false);
} else {
client.player.sendMessage(Text.translatable("fabricskyboxes.message.disabled"), false);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.amerebagatelle.fabricskyboxes.mixin.skybox;

import io.github.amerebagatelle.fabricskyboxes.SkyboxManager;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.FSBSkybox;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.util.Constants;
import io.github.amerebagatelle.fabricskyboxes.util.Utils;
import io.github.amerebagatelle.fabricskyboxes.util.object.RGBA;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.world.ClientWorld;
Expand All @@ -30,11 +29,11 @@ public class FogColorMixin {
*/
@Inject(method = "render(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/world/ClientWorld;IF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/BackgroundRenderer;lastWaterFogColorUpdateTime:J", ordinal = 6))
private static void modifyColors(Camera camera, float tickDelta, ClientWorld world, int i, float f, CallbackInfo ci) {
Skybox skybox = SkyboxManager.getInstance().getCurrentSkybox();
if (skybox instanceof FSBSkybox fsbSkybox && fsbSkybox.getAlpha() > Constants.MINIMUM_ALPHA && fsbSkybox.getProperties().isChangeFog()) {
red = fsbSkybox.getProperties().getFogColors().getRed();
green = fsbSkybox.getProperties().getFogColors().getGreen();
blue = fsbSkybox.getProperties().getFogColors().getBlue();
RGBA fogColor = Utils.alphaBlendFogColors(SkyboxManager.getInstance().getActiveSkyboxes(), new RGBA(red, green, blue));
if (SkyboxManager.getInstance().isEnabled() && fogColor != null) {
red = fogColor.getRed();
green = fogColor.getGreen();
blue = fogColor.getBlue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ static Identifier getEndSky() {

@Accessor
VertexBuffer getStarsBuffer();

@Accessor
VertexBuffer getDarkSkyBuffer();
}
Loading

0 comments on commit 55a6aa7

Please sign in to comment.