From cb9c0ce0937a54c1896c023f08f4945d585e4aa6 Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:15:37 +0800 Subject: [PATCH] change: Remove RSO suggestion screen --- .../client/gui/SodiumExtraGameOptions.java | 19 ------- .../client/gui/SuggestRSOScreen.java | 55 ------------------- .../control/SliderControlExtended.java | 26 ++++----- .../mixin/compat/MixinTitleScreen.java | 28 ---------- .../MixinBeaconBlockEntityRenderer.java | 36 ++++++------ .../MixinBeaconBlockEntityRenderer.java | 20 +++++++ src/main/resources/sodium-extra.mixins.json | 1 - 7 files changed, 51 insertions(+), 134 deletions(-) delete mode 100644 src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java delete mode 100644 src/main/java/me/flashyreese/mods/sodiumextra/mixin/compat/MixinTitleScreen.java diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptions.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptions.java index 18174da3..1c67b1ae 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptions.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraGameOptions.java @@ -32,10 +32,8 @@ public class SodiumExtraGameOptions { public final DetailSettings detailSettings = new DetailSettings(); public final RenderSettings renderSettings = new RenderSettings(); public final ExtraSettings extraSettings = new ExtraSettings(); - public final NotificationSettings notificationSettings = new NotificationSettings(); public final SuperSecretSettings superSecretSettings = new SuperSecretSettings(); private File file; - private boolean suggestedRSO; public static SodiumExtraGameOptions load(File file) { SodiumExtraGameOptions config; @@ -52,7 +50,6 @@ public static SodiumExtraGameOptions load(File file) { } config.file = file; - config.suggestedRSO = false; config.writeChanges(); return config; @@ -76,14 +73,6 @@ public void writeChanges() { } } - public boolean hasSuggestedRSO() { - return this.suggestedRSO; - } - - public void setSuggestedRSO(boolean suggestedRSO) { - this.suggestedRSO = suggestedRSO; - } - public enum OverlayCorner implements TextProvider { TOP_LEFT("sodium-extra.option.overlay_corner.top_left"), TOP_RIGHT("sodium-extra.option.overlay_corner.top_right"), @@ -276,14 +265,6 @@ public ExtraSettings() { } } - public static class NotificationSettings { - public boolean hideRSORecommendation; - - public NotificationSettings() { - this.hideRSORecommendation = false; - } - } - public static class SuperSecretSettings { public boolean fetchSodiumExtraCrowdinTranslations; public String sodiumExtraCrowdinProjectIdentifier; diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java deleted file mode 100644 index 3f7f2286..00000000 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java +++ /dev/null @@ -1,55 +0,0 @@ -package me.flashyreese.mods.sodiumextra.client.gui; - -import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.CheckboxWidget; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Util; - -public class SuggestRSOScreen extends Screen { - - private static final Text HEADER = Text.translatable("sodium-extra.suggestRSO.header").formatted(Formatting.BOLD); - private static final Text MESSAGE = Text.translatable("sodium-extra.suggestRSO.message"); - private static final Text CHECK_MESSAGE = Text.translatable("multiplayerWarning.check"); - private final Screen prevScreen; - private CheckboxWidget checkbox; - private MultilineText lines = MultilineText.EMPTY; - - public SuggestRSOScreen(Screen prevScreen) { - super(Text.literal("Reese's Sodium Options Suggestion")); - this.prevScreen = prevScreen; - } - - @Override - protected void init() { - super.init(); - this.lines = MultilineText.create(this.textRenderer, MESSAGE, this.width - 50); - int i = (this.lines.count() + 1) * this.textRenderer.fontHeight * 2; - - this.addDrawableChild(ButtonWidget.builder(Text.literal("CurseForge"), button -> Util.getOperatingSystem().open("https://curseforge.com/minecraft/mc-mods/reeses-sodium-options")).dimensions(this.width / 2 - 155, 130 + i, 150, 20).build()); - this.addDrawableChild(ButtonWidget.builder(Text.literal("Modrinth"), button -> Util.getOperatingSystem().open("https://modrinth.com/mod/reeses-sodium-options")).dimensions(this.width / 2 - 155 + 160, 130 + i, 150, 20).build()); - this.addDrawableChild(ButtonWidget.builder(ScreenTexts.PROCEED, button -> { - if (this.checkbox.isChecked()) { - SodiumExtraClientMod.options().notificationSettings.hideRSORecommendation = true; - SodiumExtraClientMod.options().writeChanges(); - } - this.client.setScreen(this.prevScreen); - }).dimensions(this.width / 2 - 155, 100 + i, 150, 20).build()); - this.addDrawableChild(ButtonWidget.builder(Text.translatable("menu.quit"), button -> this.client.scheduleStop()).dimensions(this.width / 2 - 155 + 160, 100 + i, 150, 20).build()); - this.checkbox = new CheckboxWidget(this.width / 2 - 155 + 80, 76 + i, 150, 20, CHECK_MESSAGE, false); - this.addDrawableChild(this.checkbox); - } - - @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - this.renderBackground(drawContext, mouseX, mouseY, delta); - drawContext.drawTextWithShadow(this.textRenderer, HEADER, 25, 30, 0XFFFFFF); - this.lines.drawWithShadow(drawContext, 25, 70, this.textRenderer.fontHeight * 2, 0xFFFFFF); - super.render(drawContext, mouseX, mouseY, delta); - } -} diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/options/control/SliderControlExtended.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/options/control/SliderControlExtended.java index 9fcfc6a5..65f185db 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/options/control/SliderControlExtended.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/options/control/SliderControlExtended.java @@ -6,7 +6,6 @@ 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.client.util.math.Rect2i; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import org.apache.commons.lang3.Validate; @@ -52,7 +51,6 @@ public int getMaxWidth() { private static class Slider extends ControlElement { private static final int THUMB_WIDTH = 2, TRACK_HEIGHT = 1; - private final Rect2i sliderBounds; private final ControlValueFormatter formatter; private final boolean displayIntValueWhileSliding; @@ -71,8 +69,10 @@ public Slider(Option option, Dim2i dim, int min, int max, int interval, this.thumbPosition = this.getThumbPositionForValue(option.getValue()); this.formatter = formatter; this.displayIntValueWhileSliding = displayIntValueWhileSliding; + } - this.sliderBounds = new Rect2i(dim.getLimitX() - 96, dim.getCenterY() - 5, 90, 10); + public Dim2i getSliderBounds() { + return new Dim2i(dim.getLimitX() - 96, dim.getCenterY() - 5, 90, 10); } @Override @@ -87,10 +87,10 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) } private void renderStandaloneValue(DrawContext drawContext) { - int sliderX = this.sliderBounds.getX(); - int sliderY = this.sliderBounds.getY(); - int sliderWidth = this.sliderBounds.getWidth(); - int sliderHeight = this.sliderBounds.getHeight(); + 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); @@ -99,10 +99,10 @@ private void renderStandaloneValue(DrawContext drawContext) { } private void renderSlider(DrawContext drawContext) { - int sliderX = this.sliderBounds.getX(); - int sliderY = this.sliderBounds.getY(); - int sliderWidth = this.sliderBounds.getWidth(); - int sliderHeight = this.sliderBounds.getHeight(); + 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()); @@ -135,7 +135,7 @@ public double getThumbPositionForValue(int value) { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.option.isAvailable() && button == 0 && this.sliderBounds.contains((int) mouseX, (int) mouseY)) { + if (this.option.isAvailable() && button == 0 && this.getSliderBounds().containsCursor(mouseX, mouseY)) { this.setValueFromMouse(mouseX); return true; @@ -145,7 +145,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } private void setValueFromMouse(double d) { - this.setValue((d - (double) this.sliderBounds.getX()) / (double) this.sliderBounds.getWidth()); + this.setValue((d - (double) this.getSliderBounds().x()) / (double) this.getSliderBounds().width()); } private void setValue(double d) { diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/compat/MixinTitleScreen.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/compat/MixinTitleScreen.java deleted file mode 100644 index e65f2f6c..00000000 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/compat/MixinTitleScreen.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.flashyreese.mods.sodiumextra.mixin.compat; - -import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod; -import me.flashyreese.mods.sodiumextra.client.gui.SuggestRSOScreen; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.text.Text; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TitleScreen.class) -public abstract class MixinTitleScreen extends Screen { - - protected MixinTitleScreen(Text title) { - super(title); - } - - @Inject(method = "init", at = @At(value = "RETURN")) - private void postInit(CallbackInfo ci) { - if (!FabricLoader.getInstance().isModLoaded("reeses-sodium-options") && !SodiumExtraClientMod.options().notificationSettings.hideRSORecommendation && !SodiumExtraClientMod.options().hasSuggestedRSO()) { - this.client.setScreen(new SuggestRSOScreen(this)); - SodiumExtraClientMod.options().setSuggestedRSO(true); - } - } -} diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java index 1286fe45..9ad137b0 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java @@ -24,30 +24,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = BeaconBlockEntityRenderer.class, priority = 1500) -public class MixinBeaconBlockEntityRenderer { - - @Inject(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "HEAD"), cancellable = true) - public void render(BeaconBlockEntity beaconBlockEntity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci) { - Frustum frustum = ((WorldRendererAccessor) MinecraftClient.getInstance().worldRenderer).getFrustum(); - Box box = new Box( - beaconBlockEntity.getPos().getX() - 1.0, - beaconBlockEntity.getPos().getY() - 1.0, - beaconBlockEntity.getPos().getZ() - 1.0, - beaconBlockEntity.getPos().getX() + 1.0, - beaconBlockEntity.getPos().getY() + (beaconBlockEntity.getBeamSegments().isEmpty() ? 1.0 : 1024.0), // todo: probably want to limit this to max height vanilla overshoots as well - beaconBlockEntity.getPos().getZ() + 1.0); - - if (!frustum.isVisible(box)) { - ci.cancel(); - } - } +public abstract class MixinBeaconBlockEntityRenderer { /** * @author FlashyReese * @reason Use optimized vertex writer, also avoids unnecessary allocations */ @Inject(method = "renderBeam(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/util/Identifier;FFJII[FFF)V", at = @At(value = "HEAD"), cancellable = true) - private static void renderBeam(MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, Identifier textureId, float tickDelta, float heightScale, long worldTime, int yOffset, int maxY, float[] color, float innerRadius, float outerRadius, CallbackInfo ci) { + private static void optimizeRenderBeam(MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, Identifier textureId, float tickDelta, float heightScale, long worldTime, int yOffset, int maxY, float[] color, float innerRadius, float outerRadius, CallbackInfo ci) { ci.cancel(); if (IrisCompat.isIrisPresent()) { if (IrisCompat.isRenderingShadowPass()) { @@ -137,4 +121,20 @@ private static long transformAndWriteVertex(long ptr, Matrix4f positionMatrix, f ptr += ModelVertex.STRIDE; return ptr; } + + @Inject(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "HEAD"), cancellable = true) + public void render(BeaconBlockEntity beaconBlockEntity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci) { + Frustum frustum = ((WorldRendererAccessor) MinecraftClient.getInstance().worldRenderer).getFrustum(); + Box box = new Box( + beaconBlockEntity.getPos().getX() - 1.0, + beaconBlockEntity.getPos().getY() - 1.0, + beaconBlockEntity.getPos().getZ() - 1.0, + beaconBlockEntity.getPos().getX() + 1.0, + beaconBlockEntity.getPos().getY() + (beaconBlockEntity.getBeamSegments().isEmpty() ? 1.0 : 1024.0), // todo: probably want to limit this to max height vanilla overshoots as well + beaconBlockEntity.getPos().getZ() + 1.0); + + if (!frustum.isVisible(box)) { + ci.cancel(); + } + } } diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/render/block/entity/MixinBeaconBlockEntityRenderer.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/render/block/entity/MixinBeaconBlockEntityRenderer.java index 2a9c6094..02c3e3dd 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/render/block/entity/MixinBeaconBlockEntityRenderer.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/render/block/entity/MixinBeaconBlockEntityRenderer.java @@ -6,15 +6,35 @@ import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer; import net.minecraft.client.util.math.MatrixStack; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Objects; + @Mixin(value = BeaconBlockEntityRenderer.class, priority = 999) public class MixinBeaconBlockEntityRenderer { + + @Shadow + private static void renderBeam(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta, long worldTime, int yOffset, int maxY, float[] color) { + } + @Inject(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "HEAD"), cancellable = true) public void render(BeaconBlockEntity beaconBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci) { if (!SodiumExtraClientMod.options().renderSettings.beaconBeam) ci.cancel(); } + + @Coerce + @Redirect(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/entity/BeaconBlockEntityRenderer;renderBeam(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;FJII[F)V")) + private void modifyMaxY(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta, long worldTime, int yOffset, int maxY, float[] color, BeaconBlockEntity beaconBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { + if (maxY == 1024) { + int lastSegment = beaconBlockEntity.getPos().getY() + yOffset; + maxY = Objects.requireNonNull(beaconBlockEntity.getWorld()).getTopY() - lastSegment; // Todo: This fixes the beam to max height of the world, should be toggle-able + } + renderBeam(matrices, vertexConsumers, tickDelta, worldTime, yOffset, maxY, color); + } } diff --git a/src/main/resources/sodium-extra.mixins.json b/src/main/resources/sodium-extra.mixins.json index 7bd47847..1898f0bd 100644 --- a/src/main/resources/sodium-extra.mixins.json +++ b/src/main/resources/sodium-extra.mixins.json @@ -10,7 +10,6 @@ "biome_colors.MixinBiomeColors", "cloud.MixinDimensionEffectsOverworld", "compat.MixinSodiumOptionsGUI", - "compat.MixinTitleScreen", "fog.MixinBackgroundRenderer", "fog_falloff.MixinBackgroundRenderer", "gui.MinecraftClientAccessor",