This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allows you to use your brightness slider with Methane as well.
- Loading branch information
1 parent
a8bcc1b
commit 4cff23d
Showing
10 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/modrinth/methane/client/BrightnessUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.modrinth.methane.client; | ||
|
||
import com.github.anopensaucedev.libmcdevfabric.Debug; | ||
import com.modrinth.methane.Methane; | ||
import com.modrinth.methane.mixin.accessor.WorldRendererBuiltChunkStorageAccessor; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.BuiltChunkStorage; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BrightnessUtil { | ||
|
||
// our default brightness value * the user's gamma | ||
public static float DEFAULT_LIGHT_VALUE = grabBaseGamma(); // 1.0F = fully lit, 0.0F = complete darkness | ||
|
||
public static float grabBaseGamma(){ | ||
float f = MinecraftClient.getInstance().options.getGamma().getValue().floatValue() + 0.1f; | ||
f += 1.0f; | ||
return f / 2; | ||
} | ||
|
||
public static float calculateBrightnessScale(){ | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
|
||
float scale = 1.0F; // 1 = normal, 0 = pitch black. | ||
|
||
long time = client.world.getTimeOfDay(); | ||
if(time >= 0 && time <= 12000){ // 0 <-> 12000 ticks is when the sky is fully bright | ||
|
||
} else if (time >= 12001 && time <= 12999) { // 12001 <-> 13000 is when the sky gets a bit darker | ||
scale = 0.9F; | ||
} else if (time >= 13000 && time <= 17000) { // darker... (mobs start spawning!) | ||
scale = 0.5F; | ||
} else if (time >= 17001 && time <= 20000) { // darker... | ||
scale = 0.25F; | ||
} else if (time >= 20001 && time <= 23000) { // lighter! | ||
scale = 0.5F; | ||
} else if (time >= 23001 && time <= 24000) { // day! | ||
scale = 1.0F; | ||
} | ||
|
||
|
||
|
||
return scale; | ||
} | ||
|
||
public static void rebuildChunks(MinecraftClient client){ | ||
BuiltChunkStorage storage = ((WorldRendererBuiltChunkStorageAccessor) client.worldRenderer).getChunks(); | ||
Arrays.stream(storage.chunks).parallel().forEach(builtChunk -> { | ||
builtChunk.scheduleRebuild(true); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...main/java/com/modrinth/methane/mixin/accessor/WorldRendererBuiltChunkStorageAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.modrinth.methane.mixin.accessor; | ||
|
||
import net.minecraft.client.render.BuiltChunkStorage; | ||
import net.minecraft.client.render.WorldRenderer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(WorldRenderer.class) | ||
public interface WorldRendererBuiltChunkStorageAccessor { | ||
|
||
@Accessor | ||
BuiltChunkStorage getChunks(); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/modrinth/methane/mixin/getLightLevelHack/ChunkRenderReigonMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.modrinth.methane.mixin.getLightLevelHack; | ||
|
||
import com.modrinth.methane.Methane; | ||
import com.modrinth.methane.client.BrightnessUtil; | ||
import net.minecraft.client.render.chunk.ChunkRendererRegion; | ||
import net.minecraft.util.math.Direction; | ||
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.CallbackInfoReturnable; | ||
|
||
import static com.modrinth.methane.client.BrightnessUtil.calculateBrightnessScale; | ||
|
||
@Mixin(ChunkRendererRegion.class) | ||
public class ChunkRenderReigonMixin { | ||
|
||
|
||
//impl. of: BlockRenderView$getBrightness | ||
@Inject(method = "getBrightness", at = @At("HEAD"), cancellable = true) | ||
public void MethaneSetCustomLightLevel(Direction direction, boolean shaded, CallbackInfoReturnable<Float> cir){ | ||
if(Methane.ModActive && Methane.settings.dynamicShading) { | ||
cir.setReturnValue(BrightnessUtil.grabBaseGamma() * calculateBrightnessScale()); // only gets darker, never brighter. 1.0F = fully lit. | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/modrinth/methane/mixin/getLightLevelHack/ClientWorldMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.modrinth.methane.mixin.getLightLevelHack; | ||
|
||
import com.modrinth.methane.Methane; | ||
import com.modrinth.methane.client.BrightnessUtil; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.util.math.Direction; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.CallbackInfoReturnable; | ||
|
||
import static com.modrinth.methane.client.BrightnessUtil.calculateBrightnessScale; | ||
|
||
@Mixin(ClientWorld.class) | ||
public class ClientWorldMixin { | ||
|
||
//TODO: lerp brightness to be less jarring | ||
|
||
@Shadow @Final private MinecraftClient client; | ||
|
||
|
||
|
||
@Inject(method = "getBrightness", at = @At("HEAD"), cancellable = true) | ||
public void MethaneSetCustomLightLevel(Direction direction, boolean shaded, CallbackInfoReturnable<Float> cir){ | ||
if(Methane.ModActive && Methane.settings.dynamicShading) { | ||
cir.setReturnValue(BrightnessUtil.grabBaseGamma() * calculateBrightnessScale()); // only gets darker, never brighter. 1.0F = fully lit. | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters