Skip to content

Commit

Permalink
Improve background rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-mc committed Dec 6, 2024
1 parent b67d161 commit cd35915
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package keystrokesmod.mixins.impl.gui;


import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GuiMultiplayer.class)
public class MixinGuiMultiplayer extends GuiScreen {

@Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiMultiplayer;drawDefaultBackground()V"))
public void onDrawDefaultBackground(GuiMultiplayer instance) {
}
}
25 changes: 25 additions & 0 deletions src/main/java/keystrokesmod/mixins/impl/gui/MixinGuiSlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keystrokesmod.mixins.impl.gui;


import keystrokesmod.module.ModuleManager;
import keystrokesmod.utility.render.BackgroundUtils;
import net.minecraft.client.gui.GuiSlot;
import net.minecraft.client.renderer.Tessellator;
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(GuiSlot.class)
public class MixinGuiSlot {

@Inject(method = "drawContainerBackground", at = @At("HEAD"), cancellable = true, remap = false)
public void onDrawContainerBackground(Tessellator p_drawContainerBackground_1_, CallbackInfo ci) {
if (!ModuleManager.clientTheme.isEnabled() || !ModuleManager.clientTheme.background.isToggled())
return;

BackgroundUtils.renderBackground((GuiSlot) (Object) this);

ci.cancel();
}
}
3 changes: 1 addition & 2 deletions src/main/java/keystrokesmod/utility/DebugInfoRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public void onRenderTick(RenderTickEvent ev) {
}

if (mc.currentScreen == null) {
RenderUtils.renderBPS("Client speed", true, true);
RenderUtils.renderBPS("Server speed:", PlayerMove.getXzSecSpeed(lastServerPos, curServerPos), true, true);
RenderUtils.renderBPS(String.format("Server speed: %.2fbps Client speed: ", PlayerMove.getXzSecSpeed(lastServerPos, curServerPos)), true, true);
if (avgSpeedFromJump != -1) {
ScaledResolution scaledResolution = new ScaledResolution(Raven.mc);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/keystrokesmod/utility/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static boolean randomizeBoolean() {
}

public static int randomizeInt(double min, double max) {
return (int) randomizeDouble(min, max);
return (int) Math.round(randomizeDouble(min, max));
}

public static double randomizeDouble(double min, double max) {
Expand Down
99 changes: 56 additions & 43 deletions src/main/java/keystrokesmod/utility/render/BackgroundUtils.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,75 @@
package keystrokesmod.utility.render;

import keystrokesmod.Raven;
import lombok.Getter;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import keystrokesmod.utility.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSlot;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.List;

import static keystrokesmod.Raven.mc;

public class BackgroundUtils {
private static final int BLOOM_COLOR = new Color(255, 255, 255, 50).getRGB();
public static final ResourceLocation RES_BG = new ResourceLocation("keystrokesmod:textures/backgrounds/bg.png");
public static final ResourceLocation RES_QI = new ResourceLocation("keystrokesmod:textures/backgrounds/qi.png");
public static final ResourceLocation RES_DIANXIAN = new ResourceLocation("keystrokesmod:textures/backgrounds/DianXian.png");
public static final ResourceLocation RES_HUOCHE = new ResourceLocation("keystrokesmod:textures/backgrounds/huoChe.png");
public static final ResourceLocation RES_DIANXIAN2 = new ResourceLocation("keystrokesmod:textures/backgrounds/DianXian2.png");
public static final ResourceLocation RES_CAO = new ResourceLocation("keystrokesmod:textures/backgrounds/cao.png");
public static final ResourceLocation RES_REN = new ResourceLocation("keystrokesmod:textures/backgrounds/ren.png");
public static final ResourceLocation RES_LOGO = new ResourceLocation("keystrokesmod:textures/backgrounds/ravenxd.png");
private static final List<ResourceLocation> BACKGROUNDS = new ObjectArrayList<>();
private static final int MAX_INDEX;

private static long lastRenderTime = -1;
private static ResourceLocation lastBackground;
private static int shadow = 0;

static {
BACKGROUNDS.add(new ResourceLocation("keystrokesmod:textures/backgrounds/1.png"));
BACKGROUNDS.add(new ResourceLocation("keystrokesmod:textures/backgrounds/2.png"));
BACKGROUNDS.add(new ResourceLocation("keystrokesmod:textures/backgrounds/3.png"));
BACKGROUNDS.add(new ResourceLocation("keystrokesmod:textures/backgrounds/4.png"));
BACKGROUNDS.add(new ResourceLocation("keystrokesmod:textures/backgrounds/5.png"));
MAX_INDEX = BACKGROUNDS.size() - 1;

lastBackground = BACKGROUNDS.get(Utils.randomizeInt(0, MAX_INDEX));
}

public static void renderBackground(@NotNull GuiScreen screen) {
updateShadow(0);
renderBackground(screen.width, screen.height);
}

public static void renderBackground(@NotNull GuiSlot slot) {
updateShadow(200);
renderBackground(slot.width, slot.height);
}

private static void renderBackground(final int width, final int height) {
final long time = System.currentTimeMillis();
if (time - lastRenderTime > 30000) {
lastBackground = BACKGROUNDS.get(Utils.randomizeInt(0, MAX_INDEX));
}
lastRenderTime = time;

RenderUtils.drawImage(lastBackground, 0, 0, width, height);

if (shadow != 0) {
ScaledResolution resolution = new ScaledResolution(mc);
RenderUtils.drawBloomShadow(0, 0, resolution.getScaledWidth(), resolution.getScaledHeight(), 4,
new Color(0, 0, 0, shadow), false
);
}
}

private static int huoCheX = -99999;

public static void renderBackground(@NotNull GuiScreen gui) {
final int width = gui.width;
final int height = gui.height;

if (huoCheX == -99999)
huoCheX = -width;

RenderUtils.drawImage(RES_BG, 0, 0, width, height);
RenderUtils.drawImage(RES_QI, 0, 0, width, height);
RenderUtils.drawImage(RES_DIANXIAN, 0, 0, width, height);
RenderUtils.drawImage(RES_HUOCHE, huoCheX, height / 3F, width * 2F, height / 3F);
RenderUtils.drawImage(RES_DIANXIAN2, 0, 0, width, height);
RenderUtils.drawImage(RES_CAO, 0, 0, width, height);
RenderUtils.drawBloomShadow(0, 0, width, height, 12, 6, BLOOM_COLOR, true);
RenderUtils.drawImage(RES_REN, 0, 0, width, height);
if (huoCheX >= 0) {
huoCheX = -width;
private static void updateShadow(final int shadowTarget) {
if (shadowTarget > shadow) {
shadow = (int) Math.min(shadow + 4.0 * 300 / Minecraft.getDebugFPS(), shadowTarget);
} else if (shadowTarget < shadow) {
shadow = (int) Math.max(shadow - 4.0 * 300 / Minecraft.getDebugFPS(), shadowTarget);
}
huoCheX++;
}

public static ResourceLocation getLogoPng() {
return RES_LOGO;
}
}
}
6 changes: 2 additions & 4 deletions src/main/java/keystrokesmod/utility/render/Easing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package keystrokesmod.utility.render;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.function.Function;
Expand All @@ -14,6 +15,7 @@
*
* @author Patrick
*/
@Getter
public enum Easing {
LINEAR(x -> x),
EASE_IN_QUAD(x -> x * x),
Expand Down Expand Up @@ -48,10 +50,6 @@ public enum Easing {
this.function = function;
}

public Function<Double, Double> getFunction() {
return function;
}

@Override
public String toString() {
return StringUtils.capitalize(super.toString().toLowerCase().replace("_"," "));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/resources/mixins.raven.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"gui.MixinGuiContainer",
"gui.MixinGuiDownloadTerrain",
"gui.MixinGuiMainMenu",
"gui.MixinGuiMultiplayer",
"gui.MixinGuiScreen",
"gui.MixinGuiSlot",
"network.MixinClientSpoofer",
"network.MixinNetHandlerPlayClient",
"render.ItemRendererAccessor",
Expand Down

0 comments on commit cd35915

Please sign in to comment.