Skip to content

Commit 0b50e75

Browse files
committed
change: Update for Sodium 0.7.0 & Minecraft 1.21.8
1 parent 1434896 commit 0b50e75

17 files changed

Lines changed: 261 additions & 51 deletions

File tree

build.gradle.kts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
plugins {
22
id("java")
3-
id("fabric-loom") version ("1.10-SNAPSHOT") apply (false)
3+
id("fabric-loom") version ("1.11-SNAPSHOT") apply (false)
44
}
55

6-
val MINECRAFT_VERSION by extra { "1.21.6" }
7-
val NEOFORGE_VERSION by extra { "21.6.4-beta" }
8-
val FABRIC_LOADER_VERSION by extra { "0.16.14" }
9-
val FABRIC_API_VERSION by extra { "0.127.0+1.21.6" }
6+
val MINECRAFT_VERSION by extra { "1.21.8" }
7+
val NEOFORGE_VERSION by extra { "21.8.47" }
8+
val FABRIC_LOADER_VERSION by extra { "0.17.2" }
9+
val FABRIC_API_VERSION by extra { "0.133.4+1.21.8" }
1010

1111
// This value can be set to null to disable Parchment.
1212
val PARCHMENT_VERSION by extra { null }
1313

1414
// https://semver.org/
1515
val MAVEN_GROUP by extra { "me.flashyreese.mods" }
1616
val ARCHIVE_NAME by extra { "sodium-extra" }
17-
val MOD_VERSION by extra { "0.6.6" }
18-
val SODIUM_VERSION by extra { "mc1.21.6-0.6.13" }
17+
val MOD_VERSION by extra { "0.7.0" }
18+
val SODIUM_VERSION by extra { "mc1.21.8-0.7.0" }
1919

2020
allprojects {
2121
apply(plugin = "java")

common/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import net.fabricmc.loom.task.AbstractRemapJarTask
33
plugins {
44
id("java")
55
id("idea")
6-
id("fabric-loom") version "1.10-SNAPSHOT"
6+
id("fabric-loom") version "1.11-SNAPSHOT"
77
}
88

99
val MINECRAFT_VERSION: String by rootProject.extra
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.flashyreese.mods.sodiumextra.client;
2+
3+
import net.minecraft.core.Registry;
4+
import net.minecraft.core.RegistryAccess;
5+
import net.minecraft.core.registries.Registries;
6+
import net.minecraft.resources.ResourceKey;
7+
import net.minecraft.world.level.dimension.DimensionType;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.Optional;
12+
13+
public class DimensionCloudHeightManager {
14+
private static final DimensionCloudHeightManager INSTANCE = new DimensionCloudHeightManager();
15+
private final Map<ResourceKey<DimensionType>, Integer> dimensionHeights = new HashMap<>();
16+
17+
public static DimensionCloudHeightManager getInstance() {
18+
return DimensionCloudHeightManager.INSTANCE;
19+
}
20+
21+
public void reload(RegistryAccess registryAccess) {
22+
Registry<DimensionType> registry = registryAccess.lookupOrThrow(Registries.DIMENSION_TYPE);
23+
this.dimensionHeights.clear();
24+
25+
for (var entry : registry.entrySet()) {
26+
ResourceKey<DimensionType> key = entry.getKey();
27+
DimensionType type = entry.getValue();
28+
type.cloudHeight().ifPresent(height -> this.dimensionHeights.put(key, height));
29+
}
30+
}
31+
32+
public Optional<Integer> getHeight(ResourceKey<DimensionType> typeKey) {
33+
return Optional.ofNullable(this.dimensionHeights.get(typeKey));
34+
}
35+
}

common/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptionPages.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.collect.ImmutableList;
44
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
5+
import me.flashyreese.mods.sodiumextra.client.gui.options.control.DynamicSliderControl;
56
import me.flashyreese.mods.sodiumextra.client.gui.options.control.SliderControlExtended;
67
import me.flashyreese.mods.sodiumextra.client.gui.options.storage.SodiumExtraOptionsStorage;
78
import me.flashyreese.mods.sodiumextra.common.util.ControlValueFormatterExtended;
@@ -271,6 +272,7 @@ public static OptionPage render() {
271272
config.environmentEndMultiplier = val;
272273
if (environmentEndRef.get() != null) {
273274
environmentEndRef.get().setValue(val);
275+
environmentEndRef.get().applyChanges();
274276
}
275277
}
276278
},
@@ -294,6 +296,7 @@ public static OptionPage render() {
294296
config.environmentStartMultiplier = val;
295297
if (environmentStartRef.get() != null) {
296298
environmentStartRef.get().setValue(val);
299+
environmentStartRef.get().applyChanges();
297300
}
298301
}
299302
},
@@ -318,6 +321,7 @@ public static OptionPage render() {
318321
config.renderDistanceEndMultiplier = val;
319322
if (renderDistanceEndRef.get() != null) {
320323
renderDistanceEndRef.get().setValue(val);
324+
renderDistanceEndRef.get().applyChanges();
321325
}
322326
}
323327
},
@@ -341,6 +345,7 @@ public static OptionPage render() {
341345
config.renderDistanceStartMultiplier = val;
342346
if (renderDistanceStartRef.get() != null) {
343347
renderDistanceStartRef.get().setValue(val);
348+
renderDistanceStartRef.get().applyChanges();
344349
}
345350
}
346351
},
@@ -541,14 +546,6 @@ public static OptionPage extra() {
541546
.setBinding((options, value) -> options.extraSettings.cloudHeight = value, options -> options.extraSettings.cloudHeight)
542547
.build()
543548
)
544-
.add(OptionImpl.createBuilder(int.class, sodiumExtraOpts)
545-
.setEnabled(() -> SodiumExtraClientMod.mixinConfig().getOptions().get("mixin.sodium.cloud").isEnabled())
546-
.setName(Component.translatable("sodium-extra.option.cloud_distance"))
547-
.setTooltip(Component.translatable("sodium-extra.option.cloud_distance.tooltip"))
548-
.setControl(option -> new SliderControl(option, 100, 300, 10, ControlValueFormatter.percentage()))
549-
.setBinding((options, value) -> options.extraSettings.cloudDistance = value, options -> options.extraSettings.cloudDistance)
550-
.build()
551-
)
552549
.build());
553550
groups.add(OptionGroup.createBuilder()
554551
.add(OptionImpl.createBuilder(boolean.class, vanillaOpts)

common/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ public static class ExtraSettings {
242242
public boolean reduceResolutionOnMac;
243243
public boolean useAdaptiveSync;
244244
public int cloudHeight;
245-
public int cloudDistance;
246245
public boolean toasts;
247246
public boolean advancementToast;
248247
public boolean recipeToast;
@@ -262,7 +261,6 @@ public ExtraSettings() {
262261
this.reduceResolutionOnMac = false;
263262
this.useAdaptiveSync = false;
264263
this.cloudHeight = 192;
265-
this.cloudDistance = 100;
266264
this.toasts = true;
267265
this.advancementToast = true;
268266
this.recipeToast = true;
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package me.flashyreese.mods.sodiumextra.client.gui.options.control;
2+
3+
import net.caffeinemc.mods.sodium.client.gui.options.Option;
4+
import net.caffeinemc.mods.sodium.client.gui.options.control.Control;
5+
import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement;
6+
import net.caffeinemc.mods.sodium.client.gui.options.control.ControlValueFormatter;
7+
import net.caffeinemc.mods.sodium.client.util.Dim2i;
8+
import net.minecraft.ChatFormatting;
9+
import net.minecraft.client.gui.GuiGraphics;
10+
import net.minecraft.client.renderer.Rect2i;
11+
import net.minecraft.network.chat.MutableComponent;
12+
import net.minecraft.network.chat.Style;
13+
import net.minecraft.util.Mth;
14+
import org.apache.commons.lang3.Validate;
15+
16+
import java.util.function.Supplier;
17+
18+
public class DynamicSliderControl implements Control<Integer> {
19+
private final Option<Integer> option;
20+
private final Supplier<Integer> min;
21+
private final Supplier<Integer> max;
22+
private final int interval;
23+
private final ControlValueFormatter mode;
24+
25+
public DynamicSliderControl(Option<Integer> option, Supplier<Integer> min, Supplier<Integer> max, int interval, ControlValueFormatter mode) {
26+
Validate.isTrue(interval > 0, "The slider interval must be greater than zero");
27+
Validate.notNull(mode, "The slider mode must not be null");
28+
this.option = option;
29+
this.min = min;
30+
this.max = max;
31+
this.interval = interval;
32+
this.mode = mode;
33+
}
34+
35+
public ControlElement<Integer> createElement(Dim2i dim) {
36+
int min = this.min.get();
37+
int max = this.max.get();
38+
int interval = this.interval;
39+
40+
Validate.isTrue(max > min, "The maximum value must be greater than the minimum value");
41+
Validate.isTrue(((max - min) % interval) == 0, "The maximum value must be divisable by the interval");
42+
43+
return new DynamicSliderControl.Button(this.option, dim, min, max, this.interval, this.mode);
44+
}
45+
46+
public Option<Integer> getOption() {
47+
return this.option;
48+
}
49+
50+
public int getMaxWidth() {
51+
return 170;
52+
}
53+
54+
private static class Button extends ControlElement<Integer> {
55+
private static final int THUMB_WIDTH = 2;
56+
private static final int TRACK_HEIGHT = 1;
57+
private final Rect2i sliderBounds;
58+
private final ControlValueFormatter formatter;
59+
private final int min;
60+
private final int max;
61+
private final int range;
62+
private final int interval;
63+
private int contentWidth;
64+
private double thumbPosition;
65+
private boolean sliderHeld;
66+
67+
public Button(Option<Integer> option, Dim2i dim, int min, int max, int interval, ControlValueFormatter formatter) {
68+
super(option, dim);
69+
this.min = min;
70+
this.max = max;
71+
this.range = max - min;
72+
this.interval = interval;
73+
this.thumbPosition = this.getThumbPositionForValue(option.getValue());
74+
this.formatter = formatter;
75+
this.sliderBounds = new Rect2i(dim.getLimitX() - 96, dim.getCenterY() - 5, 90, 10);
76+
this.sliderHeld = false;
77+
}
78+
79+
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
80+
int sliderX = this.sliderBounds.getX();
81+
int sliderY = this.sliderBounds.getY();
82+
int sliderWidth = this.sliderBounds.getWidth();
83+
int sliderHeight = this.sliderBounds.getHeight();
84+
MutableComponent label = this.formatter.format(this.option.getValue()).copy();
85+
if (!this.option.isAvailable()) {
86+
label.setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY).withItalic(true));
87+
}
88+
89+
int labelWidth = this.font.width(label);
90+
boolean drawSlider = this.option.isAvailable() && (this.hovered || this.isFocused());
91+
if (drawSlider) {
92+
this.contentWidth = sliderWidth + labelWidth;
93+
} else {
94+
this.contentWidth = labelWidth;
95+
}
96+
97+
super.render(graphics, mouseX, mouseY, delta);
98+
if (drawSlider) {
99+
this.thumbPosition = this.getThumbPositionForValue(this.option.getValue());
100+
double thumbOffset = Mth.clamp((double) (this.getIntValue() - this.min) / (double) this.range * (double) sliderWidth, 0.0F, sliderWidth);
101+
int thumbX = (int) ((double) sliderX + thumbOffset - (double) 2.0F);
102+
int trackY = (int) ((double) ((float) sliderY + (float) sliderHeight / 2.0F) - (double) 0.5F);
103+
this.drawRect(graphics, thumbX, sliderY, thumbX + 4, sliderY + sliderHeight, -1);
104+
this.drawRect(graphics, sliderX, trackY, sliderX + sliderWidth, trackY + 1, -1);
105+
this.drawString(graphics, label, sliderX - labelWidth - 6, sliderY + sliderHeight / 2 - 4, -1);
106+
} else {
107+
this.drawString(graphics, label, sliderX + sliderWidth - labelWidth, sliderY + sliderHeight / 2 - 4, -1);
108+
}
109+
110+
}
111+
112+
public int getContentWidth() {
113+
return this.contentWidth;
114+
}
115+
116+
public int getIntValue() {
117+
return this.min + this.interval * (int) Math.round(this.getSnappedThumbPosition() / (double) this.interval);
118+
}
119+
120+
public double getSnappedThumbPosition() {
121+
return this.thumbPosition / ((double) 1.0F / (double) this.range);
122+
}
123+
124+
public double getThumbPositionForValue(int value) {
125+
return (double) (value - this.min) * ((double) 1.0F / (double) this.range);
126+
}
127+
128+
public boolean mouseClicked(double mouseX, double mouseY, int button) {
129+
this.sliderHeld = false;
130+
if (this.option.isAvailable() && button == 0 && this.dim.containsCursor(mouseX, mouseY)) {
131+
if (this.sliderBounds.contains((int) mouseX, (int) mouseY)) {
132+
this.setValueFromMouse(mouseX);
133+
this.sliderHeld = true;
134+
}
135+
136+
return true;
137+
} else {
138+
return false;
139+
}
140+
}
141+
142+
private void setValueFromMouse(double d) {
143+
this.setValue((d - (double) this.sliderBounds.getX()) / (double) this.sliderBounds.getWidth());
144+
}
145+
146+
public void setValue(double d) {
147+
this.thumbPosition = Mth.clamp(d, 0.0F, 1.0F);
148+
int value = this.getIntValue();
149+
if (this.option.getValue() != value) {
150+
this.option.setValue(value);
151+
}
152+
153+
}
154+
155+
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
156+
if (!this.isFocused()) {
157+
return false;
158+
} else if (keyCode == 263) {
159+
this.option.setValue(Mth.clamp(this.option.getValue() - this.interval, this.min, this.max));
160+
return true;
161+
} else if (keyCode == 262) {
162+
this.option.setValue(Mth.clamp(this.option.getValue() + this.interval, this.min, this.max));
163+
return true;
164+
} else {
165+
return false;
166+
}
167+
}
168+
169+
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
170+
if (this.option.isAvailable() && button == 0) {
171+
if (this.sliderHeld) {
172+
this.setValueFromMouse(mouseX);
173+
}
174+
175+
return true;
176+
} else {
177+
return false;
178+
}
179+
}
180+
}
181+
}

common/src/main/java/me/flashyreese/mods/sodiumextra/mixin/cloud/MixinDimensionType.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package me.flashyreese.mods.sodiumextra.mixin.cloud;
22

3+
import me.flashyreese.mods.sodiumextra.client.DimensionCloudHeightManager;
34
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
5+
import net.minecraft.client.Minecraft;
6+
import net.minecraft.core.Holder;
7+
import net.minecraft.resources.ResourceKey;
48
import net.minecraft.world.level.dimension.DimensionType;
59
import org.spongepowered.asm.mixin.Mixin;
610
import org.spongepowered.asm.mixin.injection.At;
@@ -13,6 +17,18 @@
1317
public class MixinDimensionType {
1418
@Inject(method = "cloudHeight", at = @At(value = "TAIL"), cancellable = true)
1519
public void cloudHeight(CallbackInfoReturnable<Optional<Integer>> cir) {
20+
21+
Minecraft client = Minecraft.getInstance();
22+
if (client.level == null) return;
23+
24+
Holder<DimensionType> holder = client.level.dimensionTypeRegistration();
25+
ResourceKey<DimensionType> typeKey = holder.unwrapKey().orElse(null);
26+
if (typeKey != null) {
27+
Optional<Integer> override = DimensionCloudHeightManager.getInstance().getHeight(typeKey);
28+
//override.ifPresent(height -> cir.setReturnValue(Optional.of(height)));
29+
// todo:
30+
}
31+
1632
if (cir.getReturnValue().isPresent()) {
1733
cir.setReturnValue(Optional.of(SodiumExtraClientMod.options().extraSettings.cloudHeight));
1834
}

common/src/main/java/me/flashyreese/mods/sodiumextra/mixin/sodium/cloud/MixinCloudRenderer.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

common/src/main/resources/sodium-extra.mixins.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"sky.MixinSkyRenderer",
3737
"sky_colors.MixinBiome",
3838
"sodium.accessibility.MixinSodiumGameOptionPages",
39-
"sodium.cloud.MixinCloudRenderer",
4039
"sodium.fog.MixinOcclusionCuller",
4140
"sodium.scrollable_page.MixinSodiumOptionsGUI",
4241
"sodium.vsync.MixinSodiumGameOptionsPages",

0 commit comments

Comments
 (0)