From d59c806000287878a4a6f20bca144dc1b99a35b8 Mon Sep 17 00:00:00 2001 From: Steveplays28 Date: Sun, 1 Oct 2023 23:13:04 +0200 Subject: [PATCH] refactor: Replace `overwrite` with an `inject` This should be better for mod compatibility. Also restyled and updated some JavaDocs and renamed the `SleepOverridesMixin` class to `SleepManagerMixin`. --- .../mixin/ServerWorldMixin.java | 21 +++++++++++-------- .../mixin/SleepManagerMixin.java | 21 +++++++++++++++++++ .../mixin/SleepOverrideMixin.java | 17 --------------- src/main/resources/realisticsleep.mixins.json | 2 +- 4 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepManagerMixin.java delete mode 100644 src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepOverrideMixin.java diff --git a/src/main/java/com/github/steveplays28/realisticsleep/mixin/ServerWorldMixin.java b/src/main/java/com/github/steveplays28/realisticsleep/mixin/ServerWorldMixin.java index 1e6d3b0..3e5169c 100644 --- a/src/main/java/com/github/steveplays28/realisticsleep/mixin/ServerWorldMixin.java +++ b/src/main/java/com/github/steveplays28/realisticsleep/mixin/ServerWorldMixin.java @@ -170,15 +170,6 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { } } - /** - * @author Steveplays28 - * @reason Method's HUD messages conflicts with my custom HUD messages - */ - @Inject(method = "sendSleepingStatus", at = @At(value = "HEAD"), cancellable = true) - private void sendSleepingStatusInject(CallbackInfo ci) { - ci.cancel(); - } - @Inject(method = "tickTime", at = @At(value = "HEAD"), cancellable = true) public void tickTimeInject(CallbackInfo ci) { this.worldProperties.getScheduledEvents().processEvents(this.server, this.properties.getTime()); @@ -217,6 +208,18 @@ public void tickTimeInject(CallbackInfo ci) { ci.cancel(); } + /** + * Cancels {@link ServerWorld#sendSleepingStatus sendSleepingStatus}. + * + * @author Steveplays28 + * @reason Method's HUD messages conflict with Realistic Sleep's custom HUD messages. + */ + @SuppressWarnings("JavadocReference") + @Inject(method = "sendSleepingStatus", at = @At(value = "HEAD"), cancellable = true) + private void sendSleepingStatusInject(CallbackInfo ci) { + ci.cancel(); + } + @Unique private void clearWeather() { boolean doWeatherCycle = server.getGameRules().getBoolean(GameRules.DO_WEATHER_CYCLE); diff --git a/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepManagerMixin.java b/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepManagerMixin.java new file mode 100644 index 0000000..7c212ae --- /dev/null +++ b/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepManagerMixin.java @@ -0,0 +1,21 @@ +package com.github.steveplays28.realisticsleep.mixin; + +import net.minecraft.server.world.SleepManager; +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; + +@Mixin(SleepManager.class) +public class SleepManagerMixin { + /** + * Cancels {@link SleepManager#canSkipNight canSkipNight} and sets the return value to 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) { + cir.setReturnValue(false); + } +} diff --git a/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepOverrideMixin.java b/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepOverrideMixin.java deleted file mode 100644 index ff66c68..0000000 --- a/src/main/java/com/github/steveplays28/realisticsleep/mixin/SleepOverrideMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.steveplays28.realisticsleep.mixin; - -import net.minecraft.server.world.SleepManager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(SleepManager.class) -public class SleepOverrideMixin { - /** - * @author Steveplays28 - * @reason Method conflicts with my mod's functionality - */ - @Overwrite - public boolean canSkipNight(int percentage) { - return false; - } -} diff --git a/src/main/resources/realisticsleep.mixins.json b/src/main/resources/realisticsleep.mixins.json index 1d7369f..bb291bc 100644 --- a/src/main/resources/realisticsleep.mixins.json +++ b/src/main/resources/realisticsleep.mixins.json @@ -6,7 +6,7 @@ "mixins": [ "ServerPlayerEntityMixin", "ServerWorldMixin", - "SleepOverrideMixin" + "SleepManagerMixin" ], "injectors": { "defaultRequire": 1