Skip to content

Commit

Permalink
Use embeddium api
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jul 1, 2024
1 parent ca4a224 commit 03e4807
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
with:
fetch-depth: 0

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Get previous tag
run: echo "previous_tag=$(git rev-parse $(git describe --tags --abbrev=0 --exclude *-dev) 2>/dev/null || echo '')" >> $GITHUB_ENV
Expand Down Expand Up @@ -77,4 +77,4 @@ jobs:
oculus(optional)
java: |
17
21
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
}
}
maven {
url = "https://repo.constructlegacy.ru/public"
url = "https://repo.redlance.org/public"
}
maven {
url = "https://maven.neoforged.net/releases"
Expand Down Expand Up @@ -52,7 +52,7 @@ dependencies {
processResources {
inputs.property "version", project.version

filesMatching("META-INF/mods.toml") {
filesMatching("META-INF/neoforge.mods.toml") {
expand "version": project.version
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package me.flashyreese.mods.sodiumextra.client;

import me.flashyreese.mods.sodiumextra.EmbeddiumExtraMod;
import com.google.common.collect.EvictingQueue;
import me.flashyreese.mods.sodiumextra.mixin.gui.MinecraftClientAccessor;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.ClientTickEvent;

import java.util.Queue;
import java.util.stream.IntStream;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT, modid = EmbeddiumExtraMod.MOD_ID)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT, modid = SodiumExtraClientMod.MOD_ID)
public class ClientTickHandler {
private static int averageFps, lowestFps, highestFps;
private static final Queue<Integer> fpsQueue = EvictingQueue.create(200);

@SubscribeEvent
public static void onTick(final TickEvent.ClientTickEvent event) {
// The ClientTickEvent is fired twice per tick, once at the start and once at the end.
if (event.phase == TickEvent.Phase.END)
return;

public static void onTick(final ClientTickEvent.Post event) {
final int currentFPS = MinecraftClientAccessor.getCurrentFPS();
fpsQueue.add(currentFPS);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package me.flashyreese.mods.sodiumextra.client;

import me.flashyreese.mods.sodiumextra.client.gui.EmbeddiumExtendedOptions;
import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptionPages;
import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptions;
import net.caffeinemc.caffeineconfig.CaffeineConfig;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLPaths;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.embeddedt.embeddium.api.OptionGUIConstructionEvent;
import org.embeddedt.embeddium.api.OptionGroupConstructionEvent;
import org.embeddedt.embeddium.api.OptionPageConstructionEvent;
import org.embeddedt.embeddium.client.gui.options.OptionIdentifier;
import org.embeddedt.embeddium.client.gui.options.StandardOptions;

@Mod(value = SodiumExtraClientMod.MOD_ID, dist = Dist.CLIENT)
public class SodiumExtraClientMod {
public static final String MOD_ID = "embeddium_extra";
public static final Logger LOGGER = LogManager.getLogger("Embeddium Extra");
private static SodiumExtraGameOptions CONFIG;
private static CaffeineConfig MIXIN_CONFIG;
Expand Down Expand Up @@ -70,11 +81,38 @@ private static SodiumExtraGameOptions loadConfig() {
}

public SodiumExtraClientMod() {
/* if (SodiumExtraClientMod.options().superSecretSettings.fetchSodiumExtraCrowdinTranslations) {
CrowdinTranslate.downloadTranslations(SodiumExtraClientMod.options().superSecretSettings.sodiumExtraCrowdinProjectIdentifier, "sodium-extra");
}
if (SodiumExtraClientMod.options().superSecretSettings.fetchSodiumCrowdinTranslations) {
CrowdinTranslate.downloadTranslations(SodiumExtraClientMod.options().superSecretSettings.sodiumCrowdinProjectIdentifier, "sodium");
}*/
OptionGUIConstructionEvent.BUS.addListener(event -> {
event.addPage(SodiumExtraGameOptionPages.animation());
event.addPage(SodiumExtraGameOptionPages.particle());
event.addPage(SodiumExtraGameOptionPages.detail());
event.addPage(SodiumExtraGameOptionPages.render());
event.addPage(SodiumExtraGameOptionPages.extra());
});

OptionPageConstructionEvent.BUS.addListener(event -> {
if (event.getId().matches(StandardOptions.Pages.QUALITY)) {
event.addGroup(EmbeddiumExtendedOptions.EFFECTS_GROUP);

} else if (event.getId().matches(StandardOptions.Pages.GENERAL)) {
event.addGroup(EmbeddiumExtendedOptions.RESOLUTION_GROUP);
}
});

OptionGroupConstructionEvent.BUS.addListener(event -> {
if (!event.getId().matches(StandardOptions.Group.WINDOW)) {
return;
}

event.getOptions().replaceAll(option -> {
if (option.getId() == null || !option.getId().matches(StandardOptions.Option.VSYNC)) {
return option;
}
return EmbeddiumExtendedOptions.ADAPTIVE_VSYNC;
});
});
}

public static OptionIdentifier<Void> optionIdentifier(String path) {
return OptionIdentifier.create(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,109 @@
package me.flashyreese.mods.sodiumextra.client.gui;

import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.flashyreese.mods.sodiumextra.client.gui.options.control.SliderControlExtended;
import me.flashyreese.mods.sodiumextra.common.util.ControlValueFormatterExtended;
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.OptionGroup;
import me.jellysquid.mods.sodium.client.gui.options.OptionImpact;
import me.jellysquid.mods.sodium.client.gui.options.OptionImpl;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter;
import me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl;
import me.jellysquid.mods.sodium.client.gui.options.control.SliderControl;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.util.VideoMode;
import net.minecraft.client.util.Window;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.Optional;

public class EmbeddiumExtendedOptions {
private static final OptionStorage<GameOptions> vanillaOpts = SodiumGameOptionPages.getVanillaOpts();

public static final Option<?> ADAPTIVE_VSYNC = OptionImpl.createBuilder(SodiumExtraGameOptions.VerticalSyncOption.class, SodiumExtraGameOptionPages.sodiumExtraOpts)
.setName(Text.translatable("options.vsync"))
.setId(new Identifier(SodiumExtraClientMod.MOD_ID, "vsync"))
.setTooltip(Text.literal(Text.translatable("sodium.options.v_sync.tooltip").getString() + "\n- " + Text.translatable("sodium-extra.option.use_adaptive_sync.name").getString() + ": " + Text.translatable("sodium-extra.option.use_adaptive_sync.tooltip").getString()))
.setControl((opt) -> new CyclingControl<>(opt, SodiumExtraGameOptions.VerticalSyncOption.class,
SodiumExtraGameOptions.VerticalSyncOption.getAvailableOptions()))
.setBinding((opts, value) -> {
switch (value) {
case OFF -> {
opts.extraSettings.useAdaptiveSync = false;
vanillaOpts.getData().getEnableVsync().setValue(false);
}
case ON -> {
opts.extraSettings.useAdaptiveSync = false;
vanillaOpts.getData().getEnableVsync().setValue(true);
}
case ADAPTIVE -> {
opts.extraSettings.useAdaptiveSync = true;
vanillaOpts.getData().getEnableVsync().setValue(true);
}
}
vanillaOpts.save();
}, opts -> {
if (vanillaOpts.getData().getEnableVsync().getValue() && !opts.extraSettings.useAdaptiveSync) {
return SodiumExtraGameOptions.VerticalSyncOption.ON;
} else if (!vanillaOpts.getData().getEnableVsync().getValue() && !opts.extraSettings.useAdaptiveSync) {
return SodiumExtraGameOptions.VerticalSyncOption.OFF;
} else {
return SodiumExtraGameOptions.VerticalSyncOption.ADAPTIVE;
}
})
.setImpact(OptionImpact.VARIES)
.build();

public static final OptionGroup EFFECTS_GROUP = OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName(Text.translatable("options.screenEffectScale"))
.setTooltip(Text.translatable("options.screenEffectScale.tooltip"))
.setControl(option -> new SliderControl(option, 0, 100, 1, ControlValueFormatter.percentage()))
.setBinding((opts, value) -> opts.getDistortionEffectScale().setValue((double) value / 100.0F), (opts) -> Math.toIntExact(Math.round(opts.getDistortionEffectScale().getValue() * 100.0F)))
.setImpact(OptionImpact.LOW)
.build()
)
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName(Text.translatable("options.fovEffectScale"))
.setTooltip(Text.translatable("options.fovEffectScale.tooltip"))
.setControl(option -> new SliderControl(option, 0, 100, 1, ControlValueFormatter.percentage()))
.setBinding((opts, value) -> opts.getFovEffectScale().setValue(Math.sqrt(value / 100.0F)), (opts) -> (int) Math.round(Math.pow(opts.getFovEffectScale().getValue(), 2.0D) * 100.0F))
.setImpact(OptionImpact.LOW)
.build()
)
.build();

public static final OptionGroup RESOLUTION_GROUP = OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName(Text.translatable("options.fullscreen.resolution"))
.setTooltip(Text.translatable("sodium-extra.option.resolution.tooltip"))
.setControl(option -> new SliderControlExtended(option, 0, window().getMonitor() != null ? window().getMonitor().getVideoModeCount() : 0, 1, ControlValueFormatterExtended.resolution(), false))
.setBinding((options, value) -> {
if (window().getMonitor() != null) {
if (value == 0) {
window().setVideoMode(Optional.empty());
} else {
window().setVideoMode(Optional.of(window().getMonitor().getVideoMode(value - 1)));
}
}
window().applyVideoMode();
}, options -> {
if (window().getMonitor() == null) {
return 0;
} else {
Optional<VideoMode> optional = window().getVideoMode();
return optional.map((videoMode) -> window().getMonitor().findClosestVideoModeIndex(videoMode) + 1).orElse(0);
}
})
.setImpact(OptionImpact.HIGH)
.build())
.build();

private static Window window() {
return MinecraftClient.getInstance().getWindow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static OptionPage animation() {
.build()
)
.build());
return new OptionPage(Text.translatable("sodium-extra.option.animations"), ImmutableList.copyOf(groups));
return new OptionPage(SodiumExtraClientMod.optionIdentifier("animations"), Text.translatable("sodium-extra.option.animations"), ImmutableList.copyOf(groups));
}

public static OptionPage particle() {
Expand Down Expand Up @@ -163,7 +163,7 @@ public static OptionPage particle() {
).build()
));

return new OptionPage(parseVanillaString("options.particles"), ImmutableList.copyOf(groups));
return new OptionPage(SodiumExtraClientMod.optionIdentifier("particles"), parseVanillaString("options.particles"), ImmutableList.copyOf(groups));
}

public static OptionPage detail() {
Expand Down Expand Up @@ -221,7 +221,7 @@ public static OptionPage detail() {
.build()
)
.build());
return new OptionPage(Text.translatable("sodium-extra.option.details"), ImmutableList.copyOf(groups));
return new OptionPage(SodiumExtraClientMod.optionIdentifier("details"), Text.translatable("sodium-extra.option.details"), ImmutableList.copyOf(groups));
}

public static OptionPage render() {
Expand Down Expand Up @@ -377,7 +377,7 @@ public static OptionPage render() {
.build()
)
.build());
return new OptionPage(Text.translatable("sodium-extra.option.render"), ImmutableList.copyOf(groups));
return new OptionPage(SodiumExtraClientMod.optionIdentifier("render"), Text.translatable("sodium-extra.option.render"), ImmutableList.copyOf(groups));
}

public static OptionPage extra() {
Expand Down Expand Up @@ -534,7 +534,7 @@ public static OptionPage extra() {
)
.build());

return new OptionPage(Text.translatable("sodium-extra.option.extras"), ImmutableList.copyOf(groups));
return new OptionPage(SodiumExtraClientMod.optionIdentifier("extras"), Text.translatable("sodium-extra.option.extras"), ImmutableList.copyOf(groups));
}

private static Text translatableName(Identifier identifier, String category) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.flashyreese.mods.sodiumextra.client.gui;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import me.flashyreese.mods.sodiumextra.EmbeddiumExtraMod;
import me.flashyreese.mods.sodiumextra.client.ClientTickHandler;
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.flashyreese.mods.sodiumextra.mixin.gui.MinecraftClientAccessor;
Expand All @@ -10,26 +9,22 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.RenderGuiEvent;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;

import java.util.List;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT, modid = EmbeddiumExtraMod.MOD_ID)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT, modid = SodiumExtraClientMod.MOD_ID)
public class SodiumExtraHud {

private static final List<Text> TEXT_LIST = new ObjectArrayList<>();

private static final MinecraftClient CLIENT = MinecraftClient.getInstance();

@SubscribeEvent
public static void onStartTick(TickEvent.ClientTickEvent client) {
if (client.phase == TickEvent.Phase.END) {
return;
}

public static void onStartTick(ClientTickEvent.Post event) {
// Clear the textList to start fresh (this might not be ideal but hey it's still better than whatever the fuck debug hud is doing)
TEXT_LIST.clear();
if (SodiumExtraClientMod.options().extraSettings.showFps) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package me.flashyreese.mods.sodiumextra.mixin.sodium.cloud;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.jellysquid.mods.sodium.client.render.immediate.CloudRenderer;
import net.minecraft.client.option.GameOptions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(CloudRenderer.class)
public class MixinCloudRenderer {
@ModifyVariable(method = "render", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/option/GameOptions;getClampedViewDistance()I"), index = 21, name = "renderDistance")
public int modifyCloudRenderDistance(int original) {
return original * SodiumExtraClientMod.options().extraSettings.cloudDistance / 100;
@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getClampedViewDistance()I"))
public int modifyCloudRenderDistance(GameOptions instance, Operation<Integer> original) {
return original.call(instance) * SodiumExtraClientMod.options().extraSettings.cloudDistance / 100;
}
}
}
5 changes: 0 additions & 5 deletions src/main/resources/sodium-extra.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"animation.MixinSpriteAtlasTexture",
"biome_colors.MixinBiomeColors",
"cloud.MixinDimensionEffectsOverworld",
"compat.MixinSodiumOptionsGUI",
"fog.MixinBackgroundRenderer",
"fog.ForgeHooksClientMixin",
"fog_falloff.MixinBackgroundRenderer",
Expand All @@ -36,12 +35,8 @@
"render.entity.MixinPaintingEntityRenderer",
"sky.MixinWorldRenderer",
"sky_colors.MixinBiome",
"sodium.accessibility.MixinSodiumGameOptionPages",
"sodium.cloud.MixinCloudRenderer",
"sodium.fog.MixinOcclusionCuller",
"sodium.resolution.MixinSodiumGameOptionPages",
"sodium.scrollable_page.MixinSodiumOptionsGUI",
"sodium.vsync.MixinSodiumGameOptionsPages",
"stars.MixinWorldRenderer",
"steady_debug_hud.MixinDebugHud",
"sun_moon.MixinWorldRenderer",
Expand Down

0 comments on commit 03e4807

Please sign in to comment.