diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/CauldronBlockMixin.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/CauldronBlockMixin.java index 7e8bb50..ad353bf 100644 --- a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/CauldronBlockMixin.java +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/CauldronBlockMixin.java @@ -8,6 +8,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -21,20 +22,19 @@ public class CauldronBlockMixin { @Shadow @Final private static float FILL_WITH_RAIN_CHANCE; - @Shadow @Final private static float FILL_WITH_SNOW_CHANCE; @SuppressWarnings("unused") @ModifyExpressionValue(method = "precipitationTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/CauldronBlock;canFillWithPrecipitation(Lnet/minecraft/world/World;Lnet/minecraft/world/biome/Biome$Precipitation;)Z")) - private boolean modifyFillWithPrecipitationRequirements(boolean original, @Local World world, @Local BlockPos pos, @Local Biome.Precipitation precipitation) { - return canBeFilledByPrecipitation(world, pos, precipitation); + private boolean stevesrealisticsleep$modifyFillWithPrecipitationRequirements(boolean original, @Local(argsOnly = true) @NotNull World world, @Local(argsOnly = true) @NotNull BlockPos blockPosition, @Local(argsOnly = true) @NotNull Biome.Precipitation precipitation) { + return stevesrealisticsleep$canBeFilledByPrecipitation(world, blockPosition, precipitation); } @Unique - private boolean canBeFilledByPrecipitation(World world, BlockPos pos, Biome.Precipitation precipitation) { - if (CauldronUtil.canBeFilledByDripstone(world, pos)) { + private boolean stevesrealisticsleep$canBeFilledByPrecipitation(@NotNull World world, @NotNull BlockPos blockPosition, @NotNull Biome.Precipitation precipitation) { + if (CauldronUtil.canBeFilledByDripstone(world, blockPosition)) { return false; } diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerPlayerEntityMixin.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerPlayerEntityMixin.java index be82392..8be3ad0 100644 --- a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerPlayerEntityMixin.java +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerPlayerEntityMixin.java @@ -24,11 +24,10 @@ public ServerPlayerEntityMixin(EntityType type, World world) { public abstract void sendMessage(Text message, boolean overlay); @Inject(method = "wakeUp(ZZ)V", at = @At(value = "HEAD")) - public void wakeUpInject(boolean skipSleepTimer, boolean updateSleepingPlayers, CallbackInfo ci) { + public void stevesrealisticsleep$sendWakeUpMessage(boolean skipSleepTimer, boolean updateSleepingPlayers, CallbackInfo ci) { var timeOfDay = getWorld().getTimeOfDay() % DAY_LENGTH; var ticksUntilDawn = Math.abs(timeOfDay - DAWN_WAKE_UP_TIME); var ticksUntilDusk = Math.abs(timeOfDay - DUSK_WAKE_UP_TIME); - if (ticksUntilDawn > WAKE_UP_GRACE_PERIOD_TICKS && ticksUntilDusk > WAKE_UP_GRACE_PERIOD_TICKS) { return; } diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerWorldMixin.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerWorldMixin.java index 0bc9f05..a7d475a 100644 --- a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerWorldMixin.java +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/ServerWorldMixin.java @@ -29,6 +29,7 @@ import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.level.ServerWorldProperties; import net.minecraft.world.tick.WorldTickScheduler; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -46,25 +47,24 @@ @Mixin(ServerWorld.class) public abstract class ServerWorldMixin extends World implements ServerWorldExtension { - @Unique - public double timeStepPerTick = 2; - @Unique - public int timeStepPerTickRounded = 1; - @Unique - public long tickDelay; - @Unique - public MutableText sleepMessage; - @Unique - public Boolean shouldSkipWeather = false; - @Unique - public int consecutiveSleepTicks = 0; + protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey registryRef, DynamicRegistryManager registryManager, RegistryEntry dimensionEntry, Supplier profiler, boolean isClient, boolean debugWorld, long biomeAccess, int maxChainedNeighborUpdates) { + super(properties, registryRef, registryManager, dimensionEntry, profiler, isClient, debugWorld, biomeAccess, + maxChainedNeighborUpdates + ); + } @Shadow @Final protected RaidManager raidManager; + @Shadow @Final List players; + + @Shadow + @Final + private static int MAX_TICKS; + @Shadow @Final private ServerWorldProperties worldProperties; @@ -79,13 +79,13 @@ public abstract class ServerWorldMixin extends World implements ServerWorldExten private ServerChunkManager chunkManager; @Shadow @Final + private WorldTickScheduler fluidTickScheduler; + @Shadow + @Final private boolean shouldTickTime; - protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey registryRef, DynamicRegistryManager registryManager, RegistryEntry dimensionEntry, Supplier profiler, boolean isClient, boolean debugWorld, long biomeAccess, int maxChainedNeighborUpdates) { - super(properties, registryRef, registryManager, dimensionEntry, profiler, isClient, debugWorld, biomeAccess, - maxChainedNeighborUpdates - ); - } + @Shadow + public abstract ServerWorld toServerWorld(); @Shadow public abstract List getPlayers(); @@ -96,41 +96,43 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey @Shadow protected abstract BlockPos getLightningPos(BlockPos pos); - @Shadow - public abstract ServerWorld toServerWorld(); - @Shadow protected abstract void tickFluid(BlockPos pos, Fluid fluid); - @Shadow - @Final - private WorldTickScheduler fluidTickScheduler; - - @Shadow - @Final - private static int MAX_TICKS; + @Unique + private double stevesrealisticsleep$timeStepPerTick = 2; + @Unique + private long stevesrealisticsleep$tickDelay; + @Unique + private MutableText stevesrealisticsleep$sleepMessage; + @Unique + private boolean stevesrealisticsleep$shouldSkipWeather = false; + @Unique + private int stevesrealisticsleep$consecutiveSleepTicks = 0; @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getInt(Lnet/minecraft/world/GameRules$Key;)I")) - public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { + public void stevesrealisticsleep$tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { // Calculate seconds until awake int sleepingPlayerCount = sleepManager.getSleeping(); int playerCount = getPlayers().size(); double sleepingRatio = (double) sleepingPlayerCount / playerCount; - timeStepPerTick = SleepMathUtil.calculateTimeStepPerTick(sleepingRatio, config.sleepSpeedMultiplier, timeStepPerTick); + stevesrealisticsleep$timeStepPerTick = SleepMathUtil.calculateTimeStepPerTick(sleepingRatio, config.sleepSpeedMultiplier, + stevesrealisticsleep$timeStepPerTick + ); int timeOfDay = StevesRealisticSleepApi.getTimeOfDay(this); // TODO: Don't assume the TPS is 20 - int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, timeStepPerTick, 20)); + int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, stevesrealisticsleep$timeStepPerTick, 20)); // Check if the night has (almost) ended and the weather should be skipped - if (secondsUntilAwake <= 2 && shouldSkipWeather) { - clearWeather(); - shouldSkipWeather = false; + if (secondsUntilAwake <= 2 && stevesrealisticsleep$shouldSkipWeather) { + stevesrealisticsleep$clearWeather(); + stevesrealisticsleep$shouldSkipWeather = false; } // Check if anyone is sleeping if (sleepingPlayerCount <= 0) { // Reset consecutive sleep ticks - consecutiveSleepTicks = 0; + stevesrealisticsleep$consecutiveSleepTicks = 0; return; } @@ -160,7 +162,7 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { } // Fetch config values and do calculations - timeStepPerTickRounded = (int) Math.round(timeStepPerTick); + int timeStepPerTickRounded = (int) Math.round(stevesrealisticsleep$timeStepPerTick); int ticksUntilAwake = SleepMathUtil.calculateTicksUntilAwake(timeOfDay); boolean doDayLightCycle = server.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE); @@ -200,28 +202,31 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { // Check if players are still supposed to be sleeping, and send a HUD message if so if (ticksUntilAwake > WAKE_UP_GRACE_PERIOD_TICKS) { - if (consecutiveSleepTicks >= MINIMUM_SLEEP_TICKS_TO_CLEAR_WEATHER) { - shouldSkipWeather = true; + if (stevesrealisticsleep$consecutiveSleepTicks >= MINIMUM_SLEEP_TICKS_TO_CLEAR_WEATHER) { + stevesrealisticsleep$shouldSkipWeather = true; } if (config.sendSleepingMessage) { - sleepMessage = Text.translatable(String.format("%s.text.sleep_message", MOD_NAMESPACE), sleepingPlayerCount, playerCount).append( + stevesrealisticsleep$sleepMessage = Text.translatable( + String.format("%s.text.sleep_message", MOD_NAMESPACE), sleepingPlayerCount, playerCount).append( nightDayOrThunderstormText); if (isNight) { if (config.showTimeUntilDawn) { - sleepMessage.append(Text.translatable(String.format("%s.text.time_until_dawn", MOD_NAMESPACE), secondsUntilAwake)); + stevesrealisticsleep$sleepMessage.append( + Text.translatable(String.format("%s.text.time_until_dawn", MOD_NAMESPACE), secondsUntilAwake)); } } else if (config.showTimeUntilDusk) { - sleepMessage.append(Text.translatable(String.format("%s.text.time_until_dusk", MOD_NAMESPACE), secondsUntilAwake)); + stevesrealisticsleep$sleepMessage.append( + Text.translatable(String.format("%s.text.time_until_dusk", MOD_NAMESPACE), secondsUntilAwake)); } } for (ServerPlayerEntity player : players) { - player.sendMessage(sleepMessage, true); + player.sendMessage(stevesrealisticsleep$sleepMessage, true); } - consecutiveSleepTicks += timeStepPerTickRounded; + stevesrealisticsleep$consecutiveSleepTicks += timeStepPerTickRounded; } if (ticksUntilAwake <= WAKE_UP_GRACE_PERIOD_TICKS) { @@ -229,12 +234,12 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { this.wakeSleepingPlayers(); // Reset time step per tick, to reset the exponential sleep speed curve calculation - timeStepPerTick = 2; + stevesrealisticsleep$timeStepPerTick = 2; } } @Inject(method = "tickTime", at = @At(value = "HEAD"), cancellable = true) - public void tickTimeInject(CallbackInfo ci) { + public void stevesrealisticsleep$tickTimeWithTimeTickSpeedMultiplier(@NotNull CallbackInfo ci) { this.worldProperties.getScheduledEvents().processEvents(this.server, this.properties.getTime()); if (!this.shouldTickTime) { @@ -247,8 +252,8 @@ public void tickTimeInject(CallbackInfo ci) { this.worldProperties.setTime(l); } - if (tickDelay > 0L) { - tickDelay -= 1L; + if (stevesrealisticsleep$tickDelay > 0L) { + stevesrealisticsleep$tickDelay -= 1L; server.getPlayerManager().sendToDimension( new WorldTimeUpdateS2CPacket(worldProperties.getTime(), worldProperties.getTimeOfDay(), this.properties.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE) @@ -266,7 +271,7 @@ public void tickTimeInject(CallbackInfo ci) { this.worldProperties.setTimeOfDay(this.properties.getTimeOfDay() + 1L); } - tickDelay = config.tickDelay; + stevesrealisticsleep$tickDelay = config.tickDelay; ci.cancel(); } @@ -279,12 +284,12 @@ public void tickTimeInject(CallbackInfo ci) { */ @SuppressWarnings("JavadocReference") @Inject(method = "sendSleepingStatus", at = @At(value = "HEAD"), cancellable = true) - private void sendSleepingStatusInject(CallbackInfo ci) { + private void stevesrealisticsleep$preventSendingSleepingStatus(@NotNull CallbackInfo ci) { ci.cancel(); } @Inject(method = "tickChunk", at = @At(value = "HEAD")) - private void tickChunkInject(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci) { + private void stevesrealisticsleep$tickChunksWithChunkTickSpeedMultiplier(@NotNull WorldChunk chunk, int randomTickSpeed, CallbackInfo ci) { if (!StevesRealisticSleepApi.isSleeping(this)) { return; } @@ -419,7 +424,7 @@ private void tickChunkInject(WorldChunk chunk, int randomTickSpeed, CallbackInfo } @Unique - private void clearWeather() { + private void stevesrealisticsleep$clearWeather() { boolean doWeatherCycle = server.getGameRules().getBoolean(GameRules.DO_WEATHER_CYCLE); if (doWeatherCycle && (worldProperties.isRaining() || worldProperties.isThundering())) { diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/SleepManagerMixin.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/SleepManagerMixin.java index b6ee9a1..cc60baf 100644 --- a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/SleepManagerMixin.java +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/SleepManagerMixin.java @@ -1,6 +1,7 @@ package io.github.steveplays28.stevesrealisticsleep.mixin; import net.minecraft.server.world.SleepManager; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -9,13 +10,13 @@ @Mixin(SleepManager.class) public class SleepManagerMixin { /** - * Cancels {@link SleepManager#canSkipNight canSkipNight} and sets the return value to false. + * Cancels {@link SleepManager#canSkipNight canSkipNight} and sets the return value to {@code false}. * * @author Steveplays28 * @reason Method conflicts with Realistic Sleep's functionality. */ @Inject(method = "canSkipNight", at = @At(value = "HEAD"), cancellable = true) - public void canSkipNightInject(int percentage, CallbackInfoReturnable cir) { + public void stevesrealisticsleep$preventNightSkip(int percentage, @NotNull CallbackInfoReturnable cir) { cir.setReturnValue(false); } } diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/util/CauldronUtil.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/util/CauldronUtil.java index 08ffc43..c9183eb 100644 --- a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/util/CauldronUtil.java +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/util/CauldronUtil.java @@ -3,10 +3,10 @@ import net.minecraft.block.PointedDripstoneBlock; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; public class CauldronUtil { - public static boolean canBeFilledByDripstone(World world, BlockPos pos) { - BlockPos blockPos = PointedDripstoneBlock.getDripPos(world, pos); - return blockPos != null; + public static boolean canBeFilledByDripstone(@NotNull World world, @NotNull BlockPos blockPosition) { + return PointedDripstoneBlock.getDripPos(world, blockPosition) != null; } }