Skip to content

Commit

Permalink
new: Port to Mojang Mappings (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 authored Aug 1, 2024
1 parent 50ebe8b commit 6b123fd
Show file tree
Hide file tree
Showing 65 changed files with 810 additions and 805 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ buildscript {

plugins {
id 'signing'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
id 'io.github.juuxel.loom-quiltflower' version '1.10.0'
}

apply plugin: 'de.guntram.mcmod.crowdin-translate'
Expand Down Expand Up @@ -55,7 +54,7 @@ repositories {
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

//modImplementation "me.jellysquid.mods:sodium:0.5.9-snapshot+mc1.21-pre3-build.9"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
loader_version=0.16.0

# Mod Properties
mod_version=0.5.7
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ClientTickHandler {

public void onClientInitialize() {
ClientTickEvents.START_CLIENT_TICK.register(minecraftClient -> {
int currentFPS = MinecraftClientAccessor.getCurrentFPS();
int currentFPS = MinecraftClientAccessor.getFPS();
this.fpsQueue.add(currentFPS);
this.averageFps = (int) this.fpsQueue.stream().mapToInt(Integer::intValue).average().orElse(0);
this.lowestFps = this.fpsQueue.stream().min(Comparator.comparingInt(e -> e)).orElse(0);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.jellysquid.mods.sodium.client.gui.options.TextProvider;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.lwjgl.glfw.GLFW;

import java.io.File;
Expand All @@ -22,7 +22,7 @@

public class SodiumExtraGameOptions {
private static final Gson gson = new GsonBuilder()
.registerTypeAdapter(Identifier.class, new Identifier.Serializer())
.registerTypeAdapter(ResourceLocation.class, new ResourceLocation.Serializer())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.setPrettyPrinting()
.excludeFieldsWithModifiers(Modifier.PRIVATE)
Expand Down Expand Up @@ -78,14 +78,14 @@ public enum OverlayCorner implements TextProvider {
BOTTOM_LEFT("sodium-extra.option.overlay_corner.bottom_left"),
BOTTOM_RIGHT("sodium-extra.option.overlay_corner.bottom_right");

private final Text text;
private final Component text;

OverlayCorner(String text) {
this.text = Text.translatable(text);
this.text = Component.translatable(text);
}

@Override
public Text getLocalizedName() {
public Component getLocalizedName() {
return this.text;
}
}
Expand All @@ -95,14 +95,14 @@ public enum TextContrast implements TextProvider {
BACKGROUND("sodium-extra.option.text_contrast.background"),
SHADOW("sodium-extra.option.text_contrast.shadow");

private final Text text;
private final Component text;

TextContrast(String text) {
this.text = Text.translatable(text);
this.text = Component.translatable(text);
}

@Override
public Text getLocalizedName() {
public Component getLocalizedName() {
return this.text;
}
}
Expand All @@ -112,15 +112,15 @@ public enum VerticalSyncOption implements TextProvider {
ON("options.on"),
ADAPTIVE("sodium-extra.option.use_adaptive_sync.name", GLFW.glfwExtensionSupported("GLX_EXT_swap_control_tear") || GLFW.glfwExtensionSupported("WGL_EXT_swap_control_tear"));

private final Text name;
private final Component name;
private final boolean supported;

VerticalSyncOption(String name) {
this(name, true);
}

VerticalSyncOption(String name, boolean supported) {
this.name = Text.translatable(name);
this.name = Component.translatable(name);
this.supported = supported;
}

Expand All @@ -129,7 +129,7 @@ public static VerticalSyncOption[] getAvailableOptions() {
}

@Override
public Text getLocalizedName() {
public Component getLocalizedName() {
return this.name;
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public static class ParticleSettings {
public boolean blockBreak;
public boolean blockBreaking;
@SerializedName("other")
public Map<Identifier, Boolean> otherMap;
public Map<ResourceLocation, Boolean> otherMap;

public ParticleSettings() {
this.particles = true;
Expand Down Expand Up @@ -194,7 +194,7 @@ public static class RenderSettings {
public int fogStart;
public boolean multiDimensionFogControl;
@SerializedName("dimensionFogDistance")
public Map<Identifier, Integer> dimensionFogDistanceMap;
public Map<ResourceLocation, Integer> dimensionFogDistanceMap;
public boolean lightUpdates;
public boolean itemFrame;
public boolean armorStand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,81 @@
import me.flashyreese.mods.sodiumextra.mixin.gui.MinecraftClientAccessor;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.phys.Vec3;

import java.util.List;

public class SodiumExtraHud implements HudRenderCallback, ClientTickEvents.StartTick {

private final List<Text> textList = new ObjectArrayList<>();
private final List<Component> textList = new ObjectArrayList<>();

private final MinecraftClient client = MinecraftClient.getInstance();
private final Minecraft client = Minecraft.getInstance();

@Override
public void onStartTick(MinecraftClient client) {
public void onStartTick(Minecraft client) {
// 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)
this.textList.clear();
if (SodiumExtraClientMod.options().extraSettings.showFps) {
int currentFPS = MinecraftClientAccessor.getCurrentFPS();
int currentFPS = MinecraftClientAccessor.getFPS();

Text text = Text.translatable("sodium-extra.overlay.fps", currentFPS);
Component text = Component.translatable("sodium-extra.overlay.fps", currentFPS);

if (SodiumExtraClientMod.options().extraSettings.showFPSExtended)
text = Text.literal(String.format("%s %s", text.getString(), Text.translatable("sodium-extra.overlay.fps_extended", SodiumExtraClientMod.getClientTickHandler().getHighestFps(), SodiumExtraClientMod.getClientTickHandler().getAverageFps(),
text = Component.literal(String.format("%s %s", text.getString(), Component.translatable("sodium-extra.overlay.fps_extended", SodiumExtraClientMod.getClientTickHandler().getHighestFps(), SodiumExtraClientMod.getClientTickHandler().getAverageFps(),
SodiumExtraClientMod.getClientTickHandler().getLowestFps()).getString()));

this.textList.add(text);
}

if (SodiumExtraClientMod.options().extraSettings.showCoords && !this.client.hasReducedDebugInfo() && this.client.player != null) {
Vec3d pos = this.client.player.getPos();
if (SodiumExtraClientMod.options().extraSettings.showCoords && !this.client.showOnlyReducedInfo() && this.client.player != null) {
Vec3 pos = this.client.player.position();

Text text = Text.translatable("sodium-extra.overlay.coordinates", String.format("%.2f", pos.x), String.format("%.2f", pos.y), String.format("%.2f", pos.z));
Component text = Component.translatable("sodium-extra.overlay.coordinates", String.format("%.2f", pos.x), String.format("%.2f", pos.y), String.format("%.2f", pos.z));
this.textList.add(text);
}

if (!SodiumExtraClientMod.options().renderSettings.lightUpdates) {
Text text = Text.translatable("sodium-extra.overlay.light_updates");
Component text = Component.translatable("sodium-extra.overlay.light_updates");
this.textList.add(text);
}
}

@Override
public void onHudRender(DrawContext drawContext, RenderTickCounter renderTickCounter) {
if (!this.client.getDebugHud().shouldShowDebugHud() && !this.client.options.hudHidden) {
public void onHudRender(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
if (!this.client.getDebugOverlay().showDebugScreen() && !this.client.options.hideGui) {
SodiumExtraGameOptions.OverlayCorner overlayCorner = SodiumExtraClientMod.options().extraSettings.overlayCorner;
// Calculate starting position based on the overlay corner
int x;
int y = overlayCorner == SodiumExtraGameOptions.OverlayCorner.BOTTOM_LEFT || overlayCorner == SodiumExtraGameOptions.OverlayCorner.BOTTOM_RIGHT ?
this.client.getWindow().getScaledHeight() - this.client.textRenderer.fontHeight - 2 : 2;
this.client.getWindow().getGuiScaledHeight() - this.client.font.lineHeight - 2 : 2;
// Render each text in the list
for (Text text : this.textList) {
for (Component text : this.textList) {
if (overlayCorner == SodiumExtraGameOptions.OverlayCorner.TOP_RIGHT || overlayCorner == SodiumExtraGameOptions.OverlayCorner.BOTTOM_RIGHT) {
x = this.client.getWindow().getScaledWidth() - this.client.textRenderer.getWidth(text) - 2;
x = this.client.getWindow().getGuiScaledWidth() - this.client.font.width(text) - 2;
} else {
x = 2;
}
this.drawString(drawContext, text, x, y);
this.drawString(guiGraphics, text, x, y);
if (overlayCorner == SodiumExtraGameOptions.OverlayCorner.BOTTOM_LEFT || overlayCorner == SodiumExtraGameOptions.OverlayCorner.BOTTOM_RIGHT) {
y -= client.textRenderer.fontHeight + 2;
y -= client.font.lineHeight + 2;
} else {
y += client.textRenderer.fontHeight + 2; // Increase the y-position for the next text
y += client.font.lineHeight + 2; // Increase the y-position for the next text
}
}
}
}

private void drawString(DrawContext drawContext, Text text, int x, int y) {
private void drawString(GuiGraphics guiGraphics, Component text, int x, int y) {
int textColor = 0xffffffff; // Default text color

if (SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.BACKGROUND) {
drawContext.fill(x - 1, y - 1, x + this.client.textRenderer.getWidth(text) + 1, y + this.client.textRenderer.fontHeight + 1, -1873784752);
guiGraphics.fill(x - 1, y - 1, x + this.client.font.width(text) + 1, y + this.client.font.lineHeight + 1, -1873784752);
}

drawContext.drawText(this.client.textRenderer, text, x, y, textColor, SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.SHADOW);
guiGraphics.drawString(this.client.font, text, x, y, textColor, SodiumExtraClientMod.options().extraSettings.textContrast == SodiumExtraGameOptions.TextContrast.SHADOW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import org.apache.commons.lang3.Validate;

public class SliderControlExtended implements Control<Integer> {
Expand Down Expand Up @@ -76,49 +76,49 @@ public Dim2i getSliderBounds() {
}

@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
super.render(drawContext, mouseX, mouseY, delta);
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
super.render(guiGraphics, mouseX, mouseY, delta);

if (this.option.isAvailable() && this.hovered) {
this.renderSlider(drawContext);
this.renderSlider(guiGraphics);
} else {
this.renderStandaloneValue(drawContext);
this.renderStandaloneValue(guiGraphics);
}
}

private void renderStandaloneValue(DrawContext drawContext) {
private void renderStandaloneValue(GuiGraphics guiGraphics) {
int sliderX = this.getSliderBounds().x();
int sliderY = this.getSliderBounds().y();
int sliderWidth = this.getSliderBounds().width();
int sliderHeight = this.getSliderBounds().height();

Text label = this.formatter.format(this.option.getValue());
int labelWidth = this.font.getWidth(label);
Component label = this.formatter.format(this.option.getValue());
int labelWidth = this.font.width(label);

this.drawString(drawContext, label, sliderX + sliderWidth - labelWidth, sliderY + (sliderHeight / 2) - 4, 0xFFFFFFFF);
this.drawString(guiGraphics, label, sliderX + sliderWidth - labelWidth, sliderY + (sliderHeight / 2) - 4, 0xFFFFFFFF);
}

private void renderSlider(DrawContext drawContext) {
private void renderSlider(GuiGraphics guiGraphics) {
int sliderX = this.getSliderBounds().x();
int sliderY = this.getSliderBounds().y();
int sliderWidth = this.getSliderBounds().width();
int sliderHeight = this.getSliderBounds().height();

this.thumbPosition = this.getThumbPositionForValue(option.getValue());

double thumbOffset = MathHelper.clamp((double) (this.getIntValue() - this.min) / this.range * sliderWidth, 0, sliderWidth);
double thumbOffset = Mth.clamp((double) (this.getIntValue() - this.min) / this.range * sliderWidth, 0, sliderWidth);

double thumbX = sliderX + thumbOffset - THUMB_WIDTH;
double trackY = sliderY + (sliderHeight / 2) - ((double) TRACK_HEIGHT / 2);

this.drawRect(drawContext, (int) thumbX, sliderY, (int) (thumbX + (THUMB_WIDTH * 2)), sliderY + sliderHeight, 0xFFFFFFFF);
this.drawRect(drawContext, sliderX, (int) trackY, sliderX + sliderWidth, (int) (trackY + TRACK_HEIGHT), 0xFFFFFFFF);
this.drawRect(guiGraphics, (int) thumbX, sliderY, (int) (thumbX + (THUMB_WIDTH * 2)), sliderY + sliderHeight, 0xFFFFFFFF);
this.drawRect(guiGraphics, sliderX, (int) trackY, sliderX + sliderWidth, (int) (trackY + TRACK_HEIGHT), 0xFFFFFFFF);

Text label = this.displayIntValueWhileSliding ? Text.of(String.valueOf(this.getIntValue())) : this.formatter.format(this.option.getValue());
Component label = this.displayIntValueWhileSliding ? Component.literal(String.valueOf(this.getIntValue())) : this.formatter.format(this.option.getValue());

int labelWidth = this.font.getWidth(label);
int labelWidth = this.font.width(label);

this.drawString(drawContext, label, sliderX - labelWidth - 6, sliderY + (sliderHeight / 2) - 4, 0xFFFFFFFF);
this.drawString(guiGraphics, label, sliderX - labelWidth - 6, sliderY + (sliderHeight / 2) - 4, 0xFFFFFFFF);
}

public int getIntValue() {
Expand Down Expand Up @@ -149,7 +149,7 @@ private void setValueFromMouse(double d) {
}

private void setValue(double d) {
this.thumbPosition = MathHelper.clamp(d, 0.0D, 1.0D);
this.thumbPosition = Mth.clamp(d, 0.0D, 1.0D);

int value = this.getIntValue();

Expand Down
Loading

0 comments on commit 6b123fd

Please sign in to comment.