-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
52 additions
and
3 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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/github/steveplays28/realisticsleep/mixin/WorldRendererMixin.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,44 @@ | ||
package com.github.steveplays28.realisticsleep.mixin; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.render.WorldRenderer; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.world.GameRules; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
import static com.github.steveplays28.realisticsleep.RealisticSleep.config; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(WorldRenderer.class) | ||
public class WorldRendererMixin { | ||
@Shadow | ||
@Nullable | ||
private ClientWorld world; | ||
|
||
@ModifyConstant(method = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Matrix4f;FDDD)V", constant = @Constant(floatValue = 0.03f)) | ||
private float modifyCloudSpeed(float cloudSpeed) { | ||
if (world == null) { | ||
return cloudSpeed; | ||
} | ||
|
||
var players = world.getPlayers(); | ||
var sleepingPlayers = players.stream().filter(LivingEntity::isSleeping); | ||
var playerCount = players.size(); | ||
var sleepingPlayerCount = sleepingPlayers.count(); | ||
double sleepingRatio = (double) sleepingPlayerCount / playerCount; | ||
double sleepingPercentage = sleepingRatio * 100; | ||
int playersRequiredToSleepPercentage = world.getGameRules().getInt(GameRules.PLAYERS_SLEEPING_PERCENTAGE); | ||
|
||
if (sleepingPercentage < playersRequiredToSleepPercentage) { | ||
return cloudSpeed; | ||
} | ||
|
||
return cloudSpeed * config.cloudSpeedMultiplier; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,8 @@ | |
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
}, | ||
"client": [ | ||
"WorldRendererMixin" | ||
] | ||
} |