Skip to content

Commit

Permalink
feat(legacy): ambience world color and new time mode options (CCBlueX…
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl authored Feb 1, 2025
1 parent 5f14b2e commit 0505a5e
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,63 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.config.*
import net.ccbluex.liquidbounce.event.PacketEvent
import net.ccbluex.liquidbounce.event.UpdateEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.loopHandler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.Category
import net.minecraft.network.play.server.S03PacketTimeUpdate
import net.minecraft.network.play.server.S2BPacketChangeGameState
import java.awt.Color

object Ambience : Module("Ambience", Category.RENDER, gameDetecting = false) {

private val timeMode by choices("Mode", arrayOf("None", "Normal", "Custom"), "Custom")
private val customWorldTime by int("Time", 19000, 0..24000) { timeMode == "Custom" }
private val timeMode by choices("Mode", arrayOf("None", "Normal", "Custom", "Day", "Dusk", "Night", "Dynamic"), "Custom")
private val customWorldTime by int("Time", 6, 0..24) { timeMode == "Custom" }
private val changeWorldTimeSpeed by int("TimeSpeed", 150, 10..500) { timeMode == "Normal" }
private val dynamicSpeed by int("DynamicSpeed", 20, 1.. 50) { timeMode =="Dynamic" }

private val weatherMode by choices("WeatherMode", arrayOf("None", "Sun", "Rain", "Thunder"), "None")
private val weatherStrength by float("WeatherStrength", 1f, 0f..1f)
{ weatherMode == "Rain" || weatherMode == "Thunder" }
private val weatherStrength by FloatValue("WeatherStrength", 1f, 0f..1f)

// world color
val worldColor by boolean("WorldColor", false)
val color by color("Color", Color(0, 90, 255))

private var i = 0L

override fun onDisable() {
i = 0
}

val onUpdate = loopHandler {

val onUpdate = handler<UpdateEvent> {
when (timeMode.lowercase()) {
"normal" -> {
i += changeWorldTimeSpeed
i %= 24000
mc.theWorld.worldTime = i
}

"custom" -> {
mc.theWorld.worldTime = customWorldTime.toLong()
mc.theWorld.worldTime = customWorldTime.toLong() * 1000
}
"day" -> {
mc.theWorld.worldTime = 2000
}
"dusk" -> {
mc.theWorld.worldTime = 13050
}
"night" -> {
mc.theWorld.worldTime = 16000
}
"dynamic" -> {
if (i < 24000) {
i += dynamicSpeed
} else {
i = 0
}
mc.theWorld.worldTime = i
}
}

Expand All @@ -49,19 +72,18 @@ object Ambience : Module("Ambience", Category.RENDER, gameDetecting = false) {
mc.theWorld.setRainStrength(0f)
mc.theWorld.setThunderStrength(0f)
}

"rain" -> {
mc.theWorld.setRainStrength(strength)
mc.theWorld.setThunderStrength(0f)
}

"thunder" -> {
mc.theWorld.setRainStrength(strength)
mc.theWorld.setThunderStrength(strength)
}
}
}


val onPacket = handler<PacketEvent> { event ->
val packet = event.packet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.potion.Potion;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -44,6 +48,46 @@ public abstract class MixinEntityRenderer {
@Shadow
private Minecraft mc;

@Shadow
private float thirdPersonDistanceTemp;

@Shadow
private float thirdPersonDistance;

@Mutable
@Final
@Shadow
private final int[] lightmapColors;
@Mutable
@Final
@Shadow
private final DynamicTexture lightmapTexture;

@Shadow
private final float torchFlickerX;

@Shadow
private final float bossColorModifier;
@Shadow
private final float bossColorModifierPrev;

@Shadow
private boolean lightmapUpdateNeeded;

@Shadow
protected abstract float getNightVisionBrightness(EntityLivingBase p_getNightVisionBrightness_1_, float p_getNightVisionBrightness_2_);

protected MixinEntityRenderer(int[] lightmapColors, DynamicTexture lightmapTexture, float torchFlickerX, float bossColorModifier, float bossColorModifierPrev, Minecraft mc, float thirdPersonDistanceTemp, float thirdPersonDistance) {
this.lightmapColors = lightmapColors;
this.lightmapTexture = lightmapTexture;
this.torchFlickerX = torchFlickerX;
this.bossColorModifier = bossColorModifier;
this.bossColorModifierPrev = bossColorModifierPrev;
this.mc = mc;
this.thirdPersonDistanceTemp = thirdPersonDistanceTemp;
this.thirdPersonDistance = thirdPersonDistance;
}

@Inject(method = "renderWorldPass", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderHand:Z", shift = At.Shift.BEFORE))
private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo callbackInfo) {
EventManager.INSTANCE.call(new Render3DEvent(partialTicks));
Expand Down Expand Up @@ -182,6 +226,131 @@ private void getMouseOver(float p_getMouseOver_1_, CallbackInfo ci) {
ci.cancel();
}

/**
* @author opZywl
* @reason Update Light Map
*/
@Inject(method = "updateLightmap", at = @At("HEAD"), cancellable = true)
private void updateLightmap(float p_updateLightmap_1_, CallbackInfo ci) {
final Ambience ambience = Ambience.INSTANCE;
if (this.lightmapUpdateNeeded) {
this.mc.mcProfiler.startSection("lightTex");
World world = this.mc.theWorld;
if (world != null) {
float f = world.getSunBrightness(1.0F);
float f1 = f * 0.95F + 0.05F;

for (int i = 0; i < 256; ++i) {
float f2 = world.provider.getLightBrightnessTable()[i / 16] * f1;
float f3 = world.provider.getLightBrightnessTable()[i % 16] * (this.torchFlickerX * 0.1F + 1.5F);
if (world.getLastLightningBolt() > 0) {
f2 = world.provider.getLightBrightnessTable()[i / 16];
}

float f4 = f2 * (f * 0.65F + 0.35F);
float f5 = f2 * (f * 0.65F + 0.35F);
float f6 = f3 * ((f3 * 0.6F + 0.4F) * 0.6F + 0.4F);
float f7 = f3 * (f3 * f3 * 0.6F + 0.4F);
float f8 = f4 + f3;
float f9 = f5 + f6;
float f10 = f2 + f7;
f8 = f8 * 0.96F + 0.03F;
f9 = f9 * 0.96F + 0.03F;
f10 = f10 * 0.96F + 0.03F;
if (this.bossColorModifier > 0.0F) {
float f11 = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * p_updateLightmap_1_;
f8 = f8 * (1.0F - f11) + f8 * 0.7F * f11;
f9 = f9 * (1.0F - f11) + f9 * 0.6F * f11;
f10 = f10 * (1.0F - f11) + f10 * 0.6F * f11;
}

if (world.provider.getDimensionId() == 1) {
f8 = 0.22F + f3 * 0.75F;
f9 = 0.28F + f6 * 0.75F;
f10 = 0.25F + f7 * 0.75F;
}

if (this.mc.thePlayer.isPotionActive(Potion.nightVision)) {
float f15 = this.getNightVisionBrightness(this.mc.thePlayer, p_updateLightmap_1_);
float f12 = 1.0F / f8;
if (f12 > 1.0F / f9) {
f12 = 1.0F / f9;
}

if (f12 > 1.0F / f10) {
f12 = 1.0F / f10;
}

f8 = f8 * (1.0F - f15) + f8 * f12 * f15;
f9 = f9 * (1.0F - f15) + f9 * f12 * f15;
f10 = f10 * (1.0F - f15) + f10 * f12 * f15;
}

if (f8 > 1.0F) {
f8 = 1.0F;
}

if (f9 > 1.0F) {
f9 = 1.0F;
}

if (f10 > 1.0F) {
f10 = 1.0F;
}

float f16 = this.mc.gameSettings.gammaSetting;
float f17 = 1.0F - f8;
float f13 = 1.0F - f9;
float f14 = 1.0F - f10;
f17 = 1.0F - f17 * f17 * f17 * f17;
f13 = 1.0F - f13 * f13 * f13 * f13;
f14 = 1.0F - f14 * f14 * f14 * f14;
f8 = f8 * (1.0F - f16) + f17 * f16;
f9 = f9 * (1.0F - f16) + f13 * f16;
f10 = f10 * (1.0F - f16) + f14 * f16;
f8 = f8 * 0.96F + 0.03F;
f9 = f9 * 0.96F + 0.03F;
f10 = f10 * 0.96F + 0.03F;
if (f8 > 1.0F) {
f8 = 1.0F;
}

if (f9 > 1.0F) {
f9 = 1.0F;
}

if (f10 > 1.0F) {
f10 = 1.0F;
}

if (f8 < 0.0F) {
f8 = 0.0F;
}

if (f9 < 0.0F) {
f9 = 0.0F;
}

if (f10 < 0.0F) {
f10 = 0.0F;
}

int j = 255;
int k = (int) (f8 * 255.0F);
int l = (int) (f9 * 255.0F);
int i1 = (int) (f10 * 255.0F);
this.lightmapColors[i] = ambience.handleEvents() && ambience.getWorldColor() ? ambience.getColor().getRGB() : j << 24 | k << 16 | l << 8 | i1;
}

this.lightmapTexture.updateDynamicTexture();
this.lightmapUpdateNeeded = false;
this.mc.mcProfiler.endSection();
}
}

ci.cancel();
}

/**
* Properly implement the confusion option from AntiBlind module
*/
Expand All @@ -202,4 +371,4 @@ private boolean injectAntiBlindB(EntityLivingBase instance, Potion potion) {

return (!module.handleEvents() || !module.getConfusionEffect()) && instance.isPotionActive(potion);
}
}
}

0 comments on commit 0505a5e

Please sign in to comment.