Skip to content

Commit

Permalink
new: FRAPI-based rendering and the largest refactor you've ever seen
Browse files Browse the repository at this point in the history
Sorry, not sorry.
  • Loading branch information
jellysquid3 committed Sep 3, 2021
1 parent f7d3a99 commit 22d50ca
Show file tree
Hide file tree
Showing 258 changed files with 3,378 additions and 2,080 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ dependencies {

// Fabric API
modIncludeImplementation(fabricApi.module("fabric-api-base", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-models-v0", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-textures-v0", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-renderer-api-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version))
modIncludeImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version))
}

if (project.use_third_party_mods) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package me.jellysquid.mods.sodium.client;

import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import me.jellysquid.mods.sodium.client.config.SodiumRenderConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import me.jellysquid.mods.sodium.client.interop.fabric.SodiumRenderer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SodiumClientMod implements ClientModInitializer {
private static SodiumGameOptions CONFIG;
private static SodiumRenderConfig CONFIG;
private static Logger LOGGER;

private static String MOD_VERSION;
Expand All @@ -22,9 +24,11 @@ public void onInitializeClient() {
MOD_VERSION = mod.getMetadata()
.getVersion()
.getFriendlyString();

RendererAccess.INSTANCE.registerRenderer(SodiumRenderer.INSTANCE);
}

public static SodiumGameOptions options() {
public static SodiumRenderConfig options() {
if (CONFIG == null) {
CONFIG = loadConfig();
}
Expand All @@ -40,8 +44,8 @@ public static Logger logger() {
return LOGGER;
}

private static SodiumGameOptions loadConfig() {
return SodiumGameOptions.load(FabricLoader.getInstance().getConfigDir().resolve("sodium-options.json"));
private static SodiumRenderConfig loadConfig() {
return SodiumRenderConfig.load(FabricLoader.getInstance().getConfigDir().resolve("sodium-options.json"));
}

public static String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.common.config;
package me.jellysquid.mods.sodium.client.config;

import me.jellysquid.mods.sodium.client.config.mixin.MixinOption;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;
Expand All @@ -16,14 +17,14 @@
* Documentation of these options: https://github.com/jellysquid3/sodium-fabric/wiki/Configuration-File
*/
@SuppressWarnings("CanBeFinal")
public class SodiumConfig {
public class SodiumMixinConfig {
private static final Logger LOGGER = LogManager.getLogger("SodiumConfig");

private static final String JSON_KEY_SODIUM_OPTIONS = "sodium:options";

private final Map<String, Option> options = new HashMap<>();
private final Map<String, MixinOption> options = new HashMap<>();

private SodiumConfig() {
private SodiumMixinConfig() {
// Defines the default rules which can be configured by the user or other mods.
// You must manually add a rule for any new mixins not covered by an existing package rule.
this.addMixinRule("core", true); // TODO: Don't actually allow the user to disable this
Expand Down Expand Up @@ -67,7 +68,7 @@ private SodiumConfig() {
private void addMixinRule(String mixin, boolean enabled) {
String name = getMixinRuleName(mixin);

if (this.options.putIfAbsent(name, new Option(name, enabled, false)) != null) {
if (this.options.putIfAbsent(name, new MixinOption(name, enabled, false)) != null) {
throw new IllegalStateException("Mixin rule already defined: " + mixin);
}
}
Expand All @@ -77,7 +78,7 @@ private void readProperties(Properties props) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();

Option option = this.options.get(key);
MixinOption option = this.options.get(key);

if (option == null) {
LOGGER.warn("No configuration key exists with name '{}', ignoring", key);
Expand Down Expand Up @@ -119,7 +120,7 @@ private void applyModOverrides() {
}

private void applyModOverride(ModMetadata meta, String name, CustomValue value) {
Option option = this.options.get(name);
MixinOption option = this.options.get(name);

if (option == null) {
LOGGER.warn("Mod '{}' attempted to override option '{}', which doesn't exist, ignoring", meta.getId(), name);
Expand Down Expand Up @@ -151,16 +152,16 @@ private void applyModOverride(ModMetadata meta, String name, CustomValue value)
*
* @return Null if no options matched the given mixin name, otherwise the effective option for this Mixin
*/
public Option getEffectiveOptionForMixin(String mixinClassName) {
public MixinOption getEffectiveOptionForMixin(String mixinClassName) {
int lastSplit = 0;
int nextSplit;

Option rule = null;
MixinOption rule = null;

while ((nextSplit = mixinClassName.indexOf('.', lastSplit)) != -1) {
String key = getMixinRuleName(mixinClassName.substring(0, nextSplit));

Option candidate = this.options.get(key);
MixinOption candidate = this.options.get(key);

if (candidate != null) {
rule = candidate;
Expand All @@ -180,15 +181,15 @@ public Option getEffectiveOptionForMixin(String mixinClassName) {
* Loads the configuration file from the specified location. If it does not exist, a new configuration file will be
* created. The file on disk will then be updated to include any new options.
*/
public static SodiumConfig load(File file) {
public static SodiumMixinConfig load(File file) {
if (!file.exists()) {
try {
writeDefaultConfig(file);
} catch (IOException e) {
LOGGER.warn("Could not write default configuration file", e);
}

return new SodiumConfig();
return new SodiumMixinConfig();
}

Properties props = new Properties();
Expand All @@ -199,7 +200,7 @@ public static SodiumConfig load(File file) {
throw new RuntimeException("Could not load config file", e);
}

SodiumConfig config = new SodiumConfig();
SodiumMixinConfig config = new SodiumMixinConfig();
config.readProperties(props);
config.applyModOverrides();

Expand Down Expand Up @@ -238,7 +239,7 @@ public int getOptionCount() {
public int getOptionOverrideCount() {
return (int) this.options.values()
.stream()
.filter(Option::isOverridden)
.filter(MixinOption::isOverridden)
.count();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.jellysquid.mods.sodium.client.gui;
package me.jellysquid.mods.sodium.client.config;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import me.jellysquid.mods.sodium.client.gui.options.TextProvider;
import me.jellysquid.mods.sodium.client.util.TextProvider;
import net.minecraft.client.option.GraphicsMode;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
Expand All @@ -16,7 +16,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class SodiumGameOptions {
public class SodiumRenderConfig {
public final QualitySettings quality = new QualitySettings();
public final AdvancedSettings advanced = new AdvancedSettings();
public final NotificationSettings notifications = new NotificationSettings();
Expand Down Expand Up @@ -95,17 +95,17 @@ public boolean isFancy(GraphicsMode graphicsMode) {
.excludeFieldsWithModifiers(Modifier.PRIVATE)
.create();

public static SodiumGameOptions load(Path path) {
SodiumGameOptions config;
public static SodiumRenderConfig load(Path path) {
SodiumRenderConfig config;

if (Files.exists(path)) {
try (FileReader reader = new FileReader(path.toFile())) {
config = GSON.fromJson(reader, SodiumGameOptions.class);
config = GSON.fromJson(reader, SodiumRenderConfig.class);
} catch (IOException e) {
throw new RuntimeException("Could not parse config", e);
}
} else {
config = new SodiumGameOptions();
config = new SodiumRenderConfig();
}

config.configPath = path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package me.jellysquid.mods.sodium.common.config;
package me.jellysquid.mods.sodium.client.config.mixin;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class Option {
public class MixinOption {
private final String name;

private Set<String> modDefined = null;
private boolean enabled;
private boolean userDefined;

public Option(String name, boolean enabled, boolean userDefined) {
public MixinOption(String name, boolean enabled, boolean userDefined) {
this.name = name;
this.enabled = enabled;
this.userDefined = userDefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

import me.jellysquid.mods.sodium.client.gui.options.control.Control;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import me.jellysquid.mods.sodium.client.gui.options.Control;
import me.jellysquid.mods.sodium.client.config.render.storage.OptionStorage;
import net.minecraft.text.Text;

import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

public enum OptionFlag {
REQUIRES_RENDERER_RELOAD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.Validate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

import me.jellysquid.mods.sodium.client.util.TextProvider;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

import me.jellysquid.mods.sodium.client.gui.options.binding.GenericBinding;
import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import me.jellysquid.mods.sodium.client.config.render.binding.GenericBinding;
import me.jellysquid.mods.sodium.client.config.render.binding.OptionBinding;
import me.jellysquid.mods.sodium.client.gui.options.Control;
import me.jellysquid.mods.sodium.client.config.render.storage.OptionStorage;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options;
package me.jellysquid.mods.sodium.client.config.render;

import com.google.common.collect.ImmutableList;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options.binding;
package me.jellysquid.mods.sodium.client.config.render.binding;

import java.util.function.BiConsumer;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options.binding;
package me.jellysquid.mods.sodium.client.config.render.binding;

public interface OptionBinding<S, T> {
void setValue(S storage, T value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.jellysquid.mods.sodium.client.gui.options.binding.compat;
package me.jellysquid.mods.sodium.client.config.render.binding.compat;

import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
import me.jellysquid.mods.sodium.client.config.render.binding.OptionBinding;
import net.minecraft.client.option.CyclingOption;
import net.minecraft.client.option.GameOptions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options.storage;
package me.jellysquid.mods.sodium.client.config.render.storage;

import me.jellysquid.mods.sodium.client.SodiumClientMod;
import net.minecraft.client.MinecraftClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gui.options.storage;
package me.jellysquid.mods.sodium.client.config.render.storage;

public interface OptionStorage<T> {
T getData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package me.jellysquid.mods.sodium.client.gui.options.storage;
package me.jellysquid.mods.sodium.client.config.render.storage;

import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import me.jellysquid.mods.sodium.client.config.SodiumRenderConfig;

import java.io.IOException;

public class SodiumOptionsStorage implements OptionStorage<SodiumGameOptions> {
private final SodiumGameOptions options;
public class SodiumOptionsStorage implements OptionStorage<SodiumRenderConfig> {
private final SodiumRenderConfig options;

public SodiumOptionsStorage() {
this.options = SodiumClientMod.options();
}

@Override
public SodiumGameOptions getData() {
public SodiumRenderConfig getData() {
return this.options;
}

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 22d50ca

Please sign in to comment.