From a85de5e4d271d5b002a0de4285515b371cdabda5 Mon Sep 17 00:00:00 2001 From: Steveplays28 Date: Thu, 7 Dec 2023 17:00:10 +0100 Subject: [PATCH] feat: Add Better Clouds compatibility (cherry picked from commit 682ff73008e16cf8cad5b4d6b25c90c7191b62d9) --- .../realisticsleep/RealisticSleep.java | 15 +++++++++ .../config/RealisticSleepConfig.java | 2 +- .../mixin/WorldRendererMixin.java | 31 ------------------- .../assets/realisticsleep/lang/en_us.json | 4 +-- .../data/realisticsleep/lang/en_us.json | 4 +-- src/main/resources/fabric.mod.json | 4 ++- src/main/resources/realisticsleep.mixins.json | 3 -- 7 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/com/github/steveplays28/realisticsleep/mixin/WorldRendererMixin.java diff --git a/src/main/java/com/github/steveplays28/realisticsleep/RealisticSleep.java b/src/main/java/com/github/steveplays28/realisticsleep/RealisticSleep.java index 5b97fad..ea72fc6 100644 --- a/src/main/java/com/github/steveplays28/realisticsleep/RealisticSleep.java +++ b/src/main/java/com/github/steveplays28/realisticsleep/RealisticSleep.java @@ -1,11 +1,15 @@ package com.github.steveplays28.realisticsleep; +import com.github.steveplays28.realisticsleep.api.RealisticSleepApi; import com.github.steveplays28.realisticsleep.config.RealisticSleepConfig; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.world.ClientWorld; import net.minecraft.util.ActionResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,5 +42,16 @@ public void onInitialize() { return ActionResult.PASS; })); + + // Tick the world renderer faster while sleeping + ClientTickEvents.START_WORLD_TICK.register(this::tickWorldRendererFasterWhileSleeping); + } + + private void tickWorldRendererFasterWhileSleeping(ClientWorld world) { + if (RealisticSleepApi.isSleeping(world)) { + for (int i = 0; i < config.worldRenderingSpeedMultiplier; i++) { + MinecraftClient.getInstance().worldRenderer.tick(); + } + } } } diff --git a/src/main/java/com/github/steveplays28/realisticsleep/config/RealisticSleepConfig.java b/src/main/java/com/github/steveplays28/realisticsleep/config/RealisticSleepConfig.java index 5818652..3482fa7 100644 --- a/src/main/java/com/github/steveplays28/realisticsleep/config/RealisticSleepConfig.java +++ b/src/main/java/com/github/steveplays28/realisticsleep/config/RealisticSleepConfig.java @@ -53,7 +53,7 @@ public class RealisticSleepConfig implements ConfigData { @ConfigEntry.Gui.Tooltip public double fluidRandomTickSpeedMultiplier = 1d; @ConfigEntry.Gui.Tooltip - public float cloudSpeedMultiplier = 25f; + public float worldRenderingSpeedMultiplier = 25f; @ConfigEntry.Gui.Tooltip public long tickDelay = -1; diff --git a/src/main/java/com/github/steveplays28/realisticsleep/mixin/WorldRendererMixin.java b/src/main/java/com/github/steveplays28/realisticsleep/mixin/WorldRendererMixin.java deleted file mode 100644 index 2d26cea..0000000 --- a/src/main/java/com/github/steveplays28/realisticsleep/mixin/WorldRendererMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.steveplays28.realisticsleep.mixin; - -import com.github.steveplays28.realisticsleep.api.RealisticSleepApi; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.world.ClientWorld; -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 || !RealisticSleepApi.isSleeping(world)) { - return cloudSpeed; - } - - return cloudSpeed * config.cloudSpeedMultiplier; - } -} diff --git a/src/main/resources/assets/realisticsleep/lang/en_us.json b/src/main/resources/assets/realisticsleep/lang/en_us.json index a2a9b01..6347c66 100644 --- a/src/main/resources/assets/realisticsleep/lang/en_us.json +++ b/src/main/resources/assets/realisticsleep/lang/en_us.json @@ -42,8 +42,8 @@ "text.autoconfig.realisticsleep.option.blockRandomTickSpeedMultiplier.@Tooltip": "How many times faster blocks should random tick. Enable at your own risk, may cause huge TPS loss!", "text.autoconfig.realisticsleep.option.fluidRandomTickSpeedMultiplier": "Fluid random tick speed multiplier", "text.autoconfig.realisticsleep.option.fluidRandomTickSpeedMultiplier.@Tooltip": "How many times faster fluids should random tick. Enable at your own risk, may cause huge TPS loss!", - "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.worldRenderingSpeedMultiplier": "World rendering speed multiplier", + "text.autoconfig.realisticsleep.option.worldRenderingSpeedMultiplier.@Tooltip": "How many times faster clouds should move, rain should fall, and thunder should strike.", "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 ", diff --git a/src/main/resources/data/realisticsleep/lang/en_us.json b/src/main/resources/data/realisticsleep/lang/en_us.json index a2a9b01..6347c66 100644 --- a/src/main/resources/data/realisticsleep/lang/en_us.json +++ b/src/main/resources/data/realisticsleep/lang/en_us.json @@ -42,8 +42,8 @@ "text.autoconfig.realisticsleep.option.blockRandomTickSpeedMultiplier.@Tooltip": "How many times faster blocks should random tick. Enable at your own risk, may cause huge TPS loss!", "text.autoconfig.realisticsleep.option.fluidRandomTickSpeedMultiplier": "Fluid random tick speed multiplier", "text.autoconfig.realisticsleep.option.fluidRandomTickSpeedMultiplier.@Tooltip": "How many times faster fluids should random tick. Enable at your own risk, may cause huge TPS loss!", - "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.worldRenderingSpeedMultiplier": "World rendering speed multiplier", + "text.autoconfig.realisticsleep.option.worldRenderingSpeedMultiplier.@Tooltip": "How many times faster clouds should move, rain should fall, and thunder should strike.", "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 ", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6c3da50..69687b2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -50,7 +50,9 @@ "fabric": ">=${fabric_version}" }, "suggests": { - "modmenu": ">=${modmenu_version}" + "modmenu": ">=${modmenu_version}", + "sodium": "*", + "better-clouds": "*" }, "conflicts": { "tawct": "*", diff --git a/src/main/resources/realisticsleep.mixins.json b/src/main/resources/realisticsleep.mixins.json index dd60d6b..49e8898 100644 --- a/src/main/resources/realisticsleep.mixins.json +++ b/src/main/resources/realisticsleep.mixins.json @@ -10,9 +10,6 @@ "SleepManagerMixin", "accessor.ServerWorldAccessor" ], - "client": [ - "WorldRendererMixin" - ], "injectors": { "defaultRequire": 1 }