diff --git a/src/main/java/com/connorcode/sigmautils/mixin/ScreenMixin.java b/src/main/java/com/connorcode/sigmautils/mixin/ScreenMixin.java new file mode 100644 index 0000000..22f81a9 --- /dev/null +++ b/src/main/java/com/connorcode/sigmautils/mixin/ScreenMixin.java @@ -0,0 +1,40 @@ +package com.connorcode.sigmautils.mixin; + +import com.connorcode.sigmautils.config.Config; +import com.connorcode.sigmautils.modules._interface.RandomBackground; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.GameMenuScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.advancement.AdvancementsScreen; +import net.minecraft.util.Identifier; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Screen.class) +public abstract class ScreenMixin { + @Shadow + public int width; + @Shadow + public int height; + + @Shadow + public static void renderBackgroundTexture(DrawContext context, Identifier texture, int x, int y, float u, float v, int width, int height) { + throw new RuntimeException(); + } + + @Shadow + public abstract void renderInGameBackground(DrawContext context); + + @Inject(method = "renderBackground", at = @At("HEAD"), cancellable = true) + void onRenderBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { + if (!Config.getEnabled(RandomBackground.class) || (Screen) (Object) this instanceof GameMenuScreen || (Screen) (Object) this instanceof AdvancementsScreen) + return; + + renderBackgroundTexture(context, RandomBackground.getTexture(), 0, 0, 0, 0, this.width, this.height); + renderInGameBackground(context); + ci.cancel(); + } +} diff --git a/src/main/java/com/connorcode/sigmautils/modules/_interface/RandomBackground.java b/src/main/java/com/connorcode/sigmautils/modules/_interface/RandomBackground.java new file mode 100644 index 0000000..5ea9314 --- /dev/null +++ b/src/main/java/com/connorcode/sigmautils/modules/_interface/RandomBackground.java @@ -0,0 +1,83 @@ +package com.connorcode.sigmautils.modules._interface; + +import com.connorcode.sigmautils.SigmaUtils; +import com.connorcode.sigmautils.config.settings.DynamicListSetting; +import com.connorcode.sigmautils.config.settings.EnumSetting; +import com.connorcode.sigmautils.config.settings.list.SimpleList; +import com.connorcode.sigmautils.misc.Components; +import com.connorcode.sigmautils.misc.util.Util; +import com.connorcode.sigmautils.module.Module; +import com.connorcode.sigmautils.module.ModuleInfo; +import net.minecraft.block.Block; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Objects; +import java.util.Random; + +import static com.connorcode.sigmautils.SigmaUtils.client; + +@ModuleInfo(description = "Uses random textures for the background tessellation", documentation = "It will change every time you open a new screen.") +public class RandomBackground extends Module { + static final List validBackgrounds = new BufferedReader(new InputStreamReader(Objects.requireNonNull(SigmaUtils.class.getClassLoader() + .getResourceAsStream("assets/sigma-utils/background_blocks.txt")))).lines().toList(); + static EnumSetting filterType = Util.filterSetting(RandomBackground.class) + .description("Whether to blacklist or whitelist background textures.").value(Util.FilterType.Blacklist) + .build(); + static DynamicListSetting textures = new DynamicListSetting<>(RandomBackground.class, "Textures", BlockList::new).description("Possible background textures.") + .build(); + static String asset; + static int screenHash = -1; + + public static Identifier getTexture() { + int currentScreenHash = Objects.requireNonNull(Objects.requireNonNull(client).currentScreen).hashCode(); + + if (screenHash != currentScreenHash || asset == null) { + screenHash = currentScreenHash; + + List valid = switch (filterType.value()) { + case Whitelist -> + textures.value().stream().map(block -> Registries.BLOCK.getId(block).getPath()).toList(); + case Blacklist -> validBackgrounds.stream().filter(s -> !textures.value() + .contains(Registries.BLOCK.get(Identifier.tryParse("minecraft:" + s)))).toList(); + }; + + var assetIndex = new Random().nextInt(valid.size()); + asset = valid.get(assetIndex); + } + + return Identifier.tryParse("textures/block/" + asset + ".png"); + } + + static class BlockList extends SimpleList { + + public BlockList(DynamicListSetting setting) { + super(setting, Registries.BLOCK); + } + + @Override + public String getDisplay(Block value) { + return value.getName().getString(); + } + + @Override + public boolean renderSelector(Block resource, Screen screen, int x, int y) { + var rawId = Registries.BLOCK.getId(resource).getPath(); + var id = Identifier.tryParse("textures/block/" + rawId + ".png"); + if (!RandomBackground.validBackgrounds.contains(rawId) || this.setting.value().contains(resource)) + return false; + Util.addDrawable(screen, new Components.DrawableElement() { + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + context.drawTexture(id, x - 1, y + 2, 0, 0.0F, 0.0F, 16, 16, 16, 16); + } + }); + return super.renderSelector(resource, screen, x + 16, y); + } + } +} diff --git a/src/main/java/com/connorcode/sigmautils/modules/misc/TickSpeed.java b/src/main/java/com/connorcode/sigmautils/modules/misc/TickSpeed.java index 030554e..3d780cb 100644 --- a/src/main/java/com/connorcode/sigmautils/modules/misc/TickSpeed.java +++ b/src/main/java/com/connorcode/sigmautils/modules/misc/TickSpeed.java @@ -23,14 +23,9 @@ Text getSliderTitle() { return Text.of(String.format("Tick Speed: %d [%d%%]", mspt.intValue(), Math.round((100 - mspt.value()) / .5))); } - void setTickSpeed(long mspt) { - // TODO - } - void setTickSpeedFromPercent(double percent) { mspt.value(50d * (percent * 2d)); mspt.value(Math.max(mspt.intValue(), 1)); - if (enabled) setTickSpeed(mspt.intValue()); } public void drawInterface(MinecraftClient client, Screen screen, int x, int y) { @@ -55,12 +50,4 @@ protected void applyValue() { } }); } - - public void enable(MinecraftClient client) { - setTickSpeed(mspt.intValue()); - } - - public void disable(MinecraftClient client) { - setTickSpeed(50); - } } diff --git a/src/main/resources/modules/modules.json b/src/main/resources/modules/modules.json index ff2c601..e77f077 100644 --- a/src/main/resources/modules/modules.json +++ b/src/main/resources/modules/modules.json @@ -12,6 +12,7 @@ "_interface.NoChatFade", "_interface.NoScoreboardValue", "_interface.PortalInventory", + "_interface.RandomBackground", "_interface.SeeThruLoading", "_interface.SignClickThrough", "_interface.SplashRefresh", @@ -58,7 +59,6 @@ "misc.SoundControl", "misc.TickSpeed", "misc.WindowTitle", - "rendering.MapBorder", "rendering.AllowShowBarrier", "rendering.Deadmau5Ears", "rendering.DebugRenderers", @@ -68,6 +68,7 @@ "rendering.FlippedEntities", "rendering.FullBright", "rendering.LightLevel", + "rendering.MapBorder", "rendering.NoArmor", "rendering.NoBreakParticles", "rendering.NoDarkSky", diff --git a/src/main/resources/sigma-utils.mixins.json b/src/main/resources/sigma-utils.mixins.json index b95c6f2..e0f123d 100644 --- a/src/main/resources/sigma-utils.mixins.json +++ b/src/main/resources/sigma-utils.mixins.json @@ -47,6 +47,7 @@ "RecipeBookWidgetMixin", "RenderTickCounter$DynamicMixin", "ScreenAccessor", + "ScreenMixin", "SimpleOptionAccessor", "SoundSystemMixin", "SplashTextResourceSupplierMixin",