Skip to content

Commit

Permalink
feat: Add cloud speed multiplier
Browse files Browse the repository at this point in the history
Clouds now move faster while sleeping!
  • Loading branch information
Steveplays28 committed Oct 8, 2023
1 parent 3bdb5ef commit 544f2e2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class RealisticSleepConfig implements ConfigData {
public double chunkTickSpeedMultiplier = 1;
@ConfigEntry.Gui.Tooltip
public double raidTickSpeedMultiplier = 25;
@ConfigEntry.Gui.Tooltip
public float cloudSpeedMultiplier = 25f;

@ConfigEntry.Gui.Tooltip
public long tickDelay = -1;
Expand Down
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;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/realisticsleep/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"text.autoconfig.realisticsleep.option.chunkTickSpeedMultiplier.@Tooltip": "How many times faster chunks should tick. Enable at your own risk, may cause huge TPS loss!",
"text.autoconfig.realisticsleep.option.raidTickSpeedMultiplier": "Raid tick speed multiplier",
"text.autoconfig.realisticsleep.option.raidTickSpeedMultiplier.@Tooltip": "How many times faster raid timers should tick .",
"text.autoconfig.realisticsleep.option.entityTickSpeedMultiplier": "Entity tick speed multiplier",
"text.autoconfig.realisticsleep.option.entityTickSpeedMultiplier.@Tooltip": "How many times faster entities should tick.",
"text.autoconfig.realisticsleep.option.cloudSpeedMultiplier": "Cloud speed multiplier",
"text.autoconfig.realisticsleep.option.cloudSpeedMultiplier.@Tooltip": "How many times faster clouds should move.",
"text.autoconfig.realisticsleep.option.tickDelay": "Tick delay",
"text.autoconfig.realisticsleep.option.tickDelay.@Tooltip": "Adds an amount of ticks delay to every tick, so time goes slower.",
"realisticsleep.text.sleep_message": "%d/%d players are sleeping through this %s",
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/realisticsleep.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"client": [
"WorldRendererMixin"
]
}

0 comments on commit 544f2e2

Please sign in to comment.