Skip to content

Commit

Permalink
Backport to Minecraft 1.15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmangohands committed Dec 10, 2020
1 parent 888ee81 commit 924be5c
Show file tree
Hide file tree
Showing 59 changed files with 245 additions and 365 deletions.
18 changes: 2 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.5.28'
id 'fabric-loom' version '0.5-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -46,20 +46,6 @@ processResources {
}
}

if (project.use_third_party_mods) {
repositories {
maven { url = "https://jitpack.io" }
}

dependencies {
// DataBreaker applies a number of patches to eliminate the loading of data fixers
// This greatly reduces the amount of time needed to start the game, but is generally unsafe in production
modRuntime ("com.github.SuperCoder7979:databreaker:${project.databreaker_version}") {
transitive = false
}
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
Expand All @@ -77,4 +63,4 @@ task sourcesJar(type: Jar, dependsOn: classes) {

jar {
from "LICENSE.txt"
}
}
10 changes: 3 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.1
loader_version=0.10.6+build.214
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.17
loader_version=0.10.5+build.213

# Mod Properties
mod_version=0.1.1
maven_group=me.jellysquid.mods
archives_base_name=sodium-fabric

# If true, third-party mods will be loaded during runtime in the developer run configurations
use_third_party_mods = true
databreaker_version = 0.2.6
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import me.jellysquid.mods.sodium.client.gui.options.storage.SodiumOptionsStorage;
import me.jellysquid.mods.sodium.client.util.UnsafeUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.options.AttackIndicator;
import net.minecraft.client.options.GraphicsMode;
import net.minecraft.client.options.Option;
import net.minecraft.client.options.ParticlesMode;
import net.minecraft.client.options.ParticlesOption;
import net.minecraft.client.util.Window;

import java.util.ArrayList;
Expand Down Expand Up @@ -49,16 +47,7 @@ public static OptionPage general() {
.setName("Clouds")
.setTooltip("Controls whether or not clouds will be visible.")
.setControl(TickBoxControl::new)
.setBinding((opts, value) -> {
opts.quality.enableClouds = value;

if (MinecraftClient.isFabulousGraphicsOrBetter()) {
Framebuffer framebuffer = MinecraftClient.getInstance().worldRenderer.getCloudsFramebuffer();
if (framebuffer != null) {
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
}
}
}, (opts) -> opts.quality.enableClouds)
.setBinding((opts, value) -> opts.quality.enableClouds = value, (opts) -> opts.quality.enableClouds)
.setImpact(OptionImpact.LOW)
.build())
.build());
Expand Down Expand Up @@ -137,14 +126,14 @@ public static OptionPage quality() {
List<OptionGroup> groups = new ArrayList<>();

groups.add(OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(GraphicsMode.class, vanillaOpts)
.add(OptionImpl.createBuilder(SodiumGameOptions.DefaultGraphicsQuality.class, vanillaOpts)
.setName("Graphics Quality")
.setTooltip("The default graphics quality controls some legacy options and is necessary for mod compatibility. If the options below are left to " +
"\"Default\", they will use this setting.")
.setControl(option -> new CyclingControl<>(option, GraphicsMode.class, new String[] { "Fast", "Fancy", "Fabulous" }))
.setControl(option -> new CyclingControl<>(option, SodiumGameOptions.DefaultGraphicsQuality.class))
.setBinding(
(opts, value) -> opts.graphicsMode = value,
opts -> opts.graphicsMode)
(opts, value) -> opts.fancyGraphics = value == SodiumGameOptions.DefaultGraphicsQuality.FANCY,
opts -> (opts.fancyGraphics ? SodiumGameOptions.DefaultGraphicsQuality.FANCY : SodiumGameOptions.DefaultGraphicsQuality.FAST))
.setImpact(OptionImpact.HIGH)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
Expand All @@ -165,10 +154,10 @@ public static OptionPage quality() {
.setBinding((opts, value) -> opts.quality.weatherQuality = value, opts -> opts.quality.weatherQuality)
.setImpact(OptionImpact.MEDIUM)
.build())
.add(OptionImpl.createBuilder(ParticlesMode.class, vanillaOpts)
.add(OptionImpl.createBuilder(ParticlesOption.class, vanillaOpts)
.setName("Particle Quality")
.setTooltip("Controls the maximum number of particles which can be present on screen at any one time.")
.setControl(opt -> new CyclingControl<>(opt, ParticlesMode.class, new String[] { "High", "Medium", "Low" }))
.setControl(opt -> new CyclingControl<>(opt, ParticlesOption.class, new String[] { "High", "Medium", "Low" }))
.setBinding((opts, value) -> opts.particles = value, (opts) -> opts.particles)
.setImpact(OptionImpact.MEDIUM)
.build())
Expand All @@ -192,15 +181,6 @@ public static OptionPage quality() {
.setImpact(OptionImpact.LOW)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName("Entity Distance")
.setTooltip("Controls how far away entities can render from the player. Higher values increase the render distance at the expense " +
"of frame rates.")
.setControl(option -> new SliderControl(option, 50, 500, 25, ControlValueFormatter.percentage()))
.setBinding((opts, value) -> opts.entityDistanceScaling = value / 100.0F, opts -> Math.round(opts.entityDistanceScaling * 100.0F))
.setImpact(OptionImpact.MEDIUM)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, vanillaOpts)
.setName("Entity Shadows")
.setTooltip("If enabled, basic shadows will be rendered beneath mobs and other entities.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import me.jellysquid.mods.sodium.client.render.chunk.backends.gl20.GL20ChunkRenderBackend;
import me.jellysquid.mods.sodium.client.render.chunk.backends.gl30.GL30ChunkRenderBackend;
import me.jellysquid.mods.sodium.client.render.chunk.backends.gl43.GL43ChunkRenderBackend;
import net.minecraft.client.options.GraphicsMode;

import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -100,6 +99,22 @@ private interface SupportCheck {
}
}

public enum DefaultGraphicsQuality implements TextProvider {
FAST("Fast"),
FANCY("Fancy");

private final String name;

DefaultGraphicsQuality(String name) {
this.name = name;
}

@Override
public String getLocalizedName() {
return this.name;
}
}

public enum GraphicsQuality implements TextProvider {
DEFAULT("Default"),
FANCY("Fancy"),
Expand All @@ -116,8 +131,12 @@ public String getLocalizedName() {
return this.name;
}

public boolean isFancy(GraphicsMode graphicsMode) {
return (this == FANCY) || (this == DEFAULT && (graphicsMode == GraphicsMode.FANCY || graphicsMode == GraphicsMode.FABULOUS));
public boolean isFancy() {
return this == FANCY;
}

public boolean isFancy(boolean def) {
return this == DEFAULT ? def : this.isFancy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.VideoOptionsScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.OrderedText;
import net.minecraft.client.util.TextFormat;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Language;
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
Expand Down Expand Up @@ -100,7 +97,7 @@ private void rebuildGUIPages() {
int y = 6;

for (OptionPage page : this.pages) {
int width = 10 + this.textRenderer.getWidth(page.getName());
int width = 10 + this.font.getStringWidth(page.getName());

FlatButtonWidget button = new FlatButtonWidget(new Dim2i(x, y, width, 16), page.getName(), () -> this.setPage(page));
button.setSelected(this.currentPage == page);
Expand Down Expand Up @@ -134,17 +131,17 @@ private void rebuildGUIOptions() {
}

@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
super.renderBackground(matrixStack);
public void render(int mouseX, int mouseY, float delta) {
super.renderBackground();

this.updateControls();

for (Drawable drawable : this.drawable) {
drawable.render(matrixStack, mouseX, mouseY, delta);
drawable.render(mouseX, mouseY, delta);
}

if (this.hoveredElement != null) {
this.renderOptionTooltip(matrixStack, this.hoveredElement);
this.renderOptionTooltip(this.hoveredElement);
}
}

Expand Down Expand Up @@ -182,7 +179,7 @@ private Stream<ControlElement<?>> getActiveControls() {
return this.controls.stream();
}

private void renderOptionTooltip(MatrixStack matrixStack, ControlElement<?> element) {
private void renderOptionTooltip(ControlElement<?> element) {
Dim2i dim = element.getDimensions();

int textPadding = 3;
Expand All @@ -194,12 +191,12 @@ private void renderOptionTooltip(MatrixStack matrixStack, ControlElement<?> elem
int boxX = dim.getLimitX() + boxPadding;

Option<?> option = element.getOption();
List<OrderedText> tooltip = new ArrayList<>(this.textRenderer.wrapLines(option.getTooltip(), boxWidth - (textPadding * 2)));
List<String> tooltip = new ArrayList<>(this.font.wrapStringToWidthAsList(option.getTooltip(), boxWidth - (textPadding * 2)));

OptionImpact impact = option.getImpact();

if (impact != null) {
tooltip.add(Language.getInstance().reorder(new LiteralText(Formatting.GRAY + "Performance Impact: " + impact.toDisplayString())));
tooltip.add(TextFormat.GRAY + "Performance Impact: " + impact.toDisplayString());
}

int boxHeight = (tooltip.size() * 12) + boxPadding;
Expand All @@ -211,10 +208,10 @@ private void renderOptionTooltip(MatrixStack matrixStack, ControlElement<?> elem
boxY -= boxYLimit - boxYCutoff;
}

this.fillGradient(matrixStack, boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000, 0xE0000000);
this.fillGradient(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000, 0xE0000000);

for (int i = 0; i < tooltip.size(); i++) {
this.textRenderer.draw(matrixStack, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
this.font.draw(tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
}
}

Expand Down Expand Up @@ -272,6 +269,6 @@ public boolean shouldCloseOnEsc() {

@Override
public void onClose() {
this.client.openScreen(this.prevScreen);
this.minecraft.openScreen(this.prevScreen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

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

import java.util.Collection;

public interface Option<T> {
String getName();

Text getTooltip();
String getTooltip();

OptionImpact getImpact();

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

import net.minecraft.util.Formatting;
import net.minecraft.client.util.TextFormat;

public enum OptionImpact {
LOW(Formatting.GREEN, "Low"),
MEDIUM(Formatting.YELLOW, "Medium"),
HIGH(Formatting.GOLD, "High"),
EXTREME(Formatting.RED, "Extreme"),
VARIES(Formatting.WHITE, "Varies");
LOW(TextFormat.GREEN, "Low"),
MEDIUM(TextFormat.YELLOW, "Medium"),
HIGH(TextFormat.GOLD, "High"),
EXTREME(TextFormat.RED, "Extreme"),
VARIES(TextFormat.WHITE, "Varies");

private final Formatting color;
private final TextFormat color;
private final String text;

OptionImpact(Formatting color, String text) {
OptionImpact(TextFormat color, String text) {
this.color = color;
this.text = text;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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 net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

import java.util.Collection;
Expand All @@ -23,7 +21,7 @@ public class OptionImpl<S, T> implements Option<T> {
private final EnumSet<OptionFlag> flags;

private final String name;
private final Text tooltip;
private final String tooltip;

private final OptionImpact impact;

Expand All @@ -42,7 +40,7 @@ private OptionImpl(OptionStorage<S> storage,
boolean enabled) {
this.storage = storage;
this.name = name;
this.tooltip = new LiteralText(tooltip);
this.tooltip = tooltip;
this.binding = binding;
this.impact = impact;
this.flags = flags;
Expand All @@ -58,7 +56,7 @@ public String getName() {
}

@Override
public Text getTooltip() {
public String getTooltip() {
return this.tooltip;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Formatting;
import net.minecraft.client.util.TextFormat;

public class ControlElement<T> extends AbstractWidget {
protected final Option<T> option;
Expand All @@ -23,29 +22,29 @@ public boolean isHovered() {
}

@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) {
public void render(int mouseX, int mouseY, float delta) {
String name = this.option.getName();
String label;

if (this.hovered && this.font.getWidth(name) > (this.dim.getWidth() - this.option.getControl().getMaxWidth())) {
if (this.hovered && this.font.getStringWidth(name) > (this.dim.getWidth() - this.option.getControl().getMaxWidth())) {
name = name.substring(0, Math.min(name.length(), 10)) + "...";
}

if (this.option.isAvailable()) {
if (this.option.hasChanged()) {
label = Formatting.ITALIC + name + " *";
label = TextFormat.ITALIC + name + " *";
} else {
label = Formatting.WHITE + name;
label = TextFormat.WHITE + name;
}
} else {
label = String.valueOf(Formatting.GRAY) + Formatting.STRIKETHROUGH + name;
label = String.valueOf(TextFormat.GRAY) + TextFormat.STRIKETHROUGH + name;
}

this.hovered = this.dim.containsCursor(mouseX, mouseY);


this.drawRect(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), this.hovered ? 0xE0000000 : 0x90000000);
this.drawString(matrixStack, label, this.dim.getOriginX() + 6, this.dim.getCenterY() - 4, 0xFFFFFFFF);
this.drawString(label, this.dim.getOriginX() + 6, this.dim.getCenterY() - 4, 0xFFFFFFFF);
}

public Option<T> getOption() {
Expand Down
Loading

0 comments on commit 924be5c

Please sign in to comment.