diff --git a/build.gradle b/build.gradle index 2d93117..a807bd5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ //file:noinspection GroovyAccessibility //file:noinspection GroovyAssignabilityCheck +//file:noinspection DependencyNotationArgument plugins { id "architectury-plugin" version "${architectury_plugin_version}" @@ -15,7 +16,10 @@ subprojects { dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.layered { + it.mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2") + it.mappings("dev.architectury:yarn-mappings-patch-neoforge:1.21+build.4") + } } } diff --git a/common/build.gradle b/common/build.gradle index 216d1a3..c22b254 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,6 @@ //file:noinspection GroovyAccessibility //file:noinspection GroovyAssignabilityCheck +//file:noinspection DependencyNotationArgument def archivesNameCommon = "${rootProject.mod_id}-common" @@ -20,9 +21,6 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - // Mixin Extras - compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${rootProject.mixin_extras_version}")) - // Architectury API modApi("dev.architectury:architectury:${rootProject.architectury_api_version}") { exclude group: 'net.fabricmc', module: 'fabric-loader' 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..529f466 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 @@ -2,6 +2,7 @@ import io.github.steveplays28.stevesrealisticsleep.api.StevesRealisticSleepApi; import io.github.steveplays28.stevesrealisticsleep.extension.ServerWorldExtension; +import io.github.steveplays28.stevesrealisticsleep.mixin.accessor.AbstractCauldronBlockAccessor; import io.github.steveplays28.stevesrealisticsleep.util.SleepMathUtil; import net.minecraft.block.*; import net.minecraft.entity.EntityType; @@ -376,7 +377,6 @@ private void tickChunkInject(WorldChunk chunk, int randomTickSpeed, CallbackInfo var randomPosInChunk = this.getRandomPosInChunk(chunkStartPosX, chunkSectionYOffset, chunkStartPosZ, 15); var biome = this.getBiome(randomPosInChunk).value(); var precipitation = biome.getPrecipitation(randomPosInChunk); - if (precipitation == Biome.Precipitation.NONE) { continue; } @@ -385,10 +385,9 @@ private void tickChunkInject(WorldChunk chunk, int randomTickSpeed, CallbackInfo randomPosInChunk.getY() - chunkSectionYOffset, randomPosInChunk.getZ() - chunkStartPosZ ); var randomBlockInChunk = randomBlockStateInChunk.getBlock(); - if (randomBlockInChunk instanceof AbstractCauldronBlock cauldronBlock) { cauldronBlock.precipitationTick(randomBlockStateInChunk, this, randomPosInChunk, precipitation); - cauldronBlock.scheduledTick(randomBlockStateInChunk, this.toServerWorld(), randomPosInChunk, random); + ((AbstractCauldronBlockAccessor) cauldronBlock).invokeScheduledTick(randomBlockStateInChunk, this.toServerWorld(), randomPosInChunk, random); } } diff --git a/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/accessor/AbstractCauldronBlockAccessor.java b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/accessor/AbstractCauldronBlockAccessor.java new file mode 100644 index 0000000..2da7718 --- /dev/null +++ b/common/src/main/java/io/github/steveplays28/stevesrealisticsleep/mixin/accessor/AbstractCauldronBlockAccessor.java @@ -0,0 +1,15 @@ +package io.github.steveplays28.stevesrealisticsleep.mixin.accessor; + +import net.minecraft.block.AbstractCauldronBlock; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(AbstractCauldronBlock.class) +public interface AbstractCauldronBlockAccessor { + @Invoker + void invokeScheduledTick(BlockState blockState, ServerWorld serverWorld, BlockPos blockPosition, Random random); +} diff --git a/common/src/main/resources/steves_realistic_sleep-common.mixins.json b/common/src/main/resources/steves_realistic_sleep-common.mixins.json index f746f4b..7478758 100644 --- a/common/src/main/resources/steves_realistic_sleep-common.mixins.json +++ b/common/src/main/resources/steves_realistic_sleep-common.mixins.json @@ -8,6 +8,7 @@ "ServerPlayerEntityMixin", "ServerWorldMixin", "SleepManagerMixin", + "accessor.AbstractCauldronBlockAccessor", "accessor.ServerWorldAccessor" ], "injectors": { diff --git a/fabric/build.gradle b/fabric/build.gradle index a87d451..6a5da7e 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,7 @@ //file:noinspection GroovyAccessibility //file:noinspection GroovyAssignabilityCheck +//file:noinspection DependencyNotationArgument +//file:noinspection DependencyNotationArgument plugins { id "com.github.johnrengelman.shadow" version "${shadow_plugin_version}" @@ -31,9 +33,6 @@ configurations { dependencies { modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - // Mixin Extras - include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${rootProject.mixin_extras_version}"))) - // Architectury API modRuntimeOnly("dev.architectury:architectury-fabric:${rootProject.architectury_api_version}") diff --git a/gradle.properties b/gradle.properties index 51bc06b..80ce0b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,15 +13,15 @@ mod_name=Steve's Realistic Sleep mod_description=Makes sleeping speed up time instead of skipping to day. mod_license=LGPL-3.0 mod_version=1.10.2 -supported_minecraft_version=1.20.4 -supported_minecraft_version_name=1.20.4 +supported_minecraft_version=>=1.21 <=1.21.1 +supported_minecraft_version_name=1.21-1.21.1 # Multiloader properties architectury_plugin_version=3.4-SNAPSHOT -architectury_loom_version=1.6-SNAPSHOT +architectury_loom_version=1.7-SNAPSHOT shadow_plugin_version=7.1.2 -minecraft_version=1.20.4 -java_version=17 +minecraft_version=1.21 +java_version=21 enabled_platforms=fabric,neoforge # mc-publish properties @@ -30,16 +30,15 @@ modrinth_project_id=KuNKN7d2 # Fabric properties # Check these on https://modmuss50.me/fabric.html -yarn_mappings=1.20.4+build.3 -fabric_loader_version=0.14.25 +yarn_mappings=1.21+build.9 +fabric_loader_version=0.15.11 # NeoForge properties -neoforge_version=20.4.237 +neoforge_version=21.0.167 # Dependencies -mixin_extras_version=0.3.5 -architectury_api_version=11.1.17 -fabric_api_version=0.97.1+1.20.4 -cloth_config_version=13.0.121 -mod_menu_version=9.0.0 -server_translation_api_version=2.2.0+1.20.3-rc1 +architectury_api_version=13.0.6 +fabric_api_version=0.100.3+1.21 +cloth_config_version=15.0.127 +mod_menu_version=11.0.0-beta.2 +server_translation_api_version=2.3.1+1.21-pre2 diff --git a/neoforge/build.gradle b/neoforge/build.gradle index b4763d4..60dfcef 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -1,5 +1,6 @@ //file:noinspection GroovyAccessibility //file:noinspection GroovyAssignabilityCheck +//file:noinspection DependencyNotationArgument plugins { id "com.github.johnrengelman.shadow" version "${shadow_plugin_version}" @@ -31,9 +32,6 @@ configurations { dependencies { neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" - // Mixin Extras - implementation(annotationProcessor("io.github.llamalad7:mixinextras-neoforge:${rootProject.mixin_extras_version}")) - // Architectury API modRuntimeOnly("dev.architectury:architectury-neoforge:${rootProject.architectury_api_version}") @@ -47,7 +45,7 @@ dependencies { processResources { inputs.property "version", "${project.version}-neoforge" - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version, "mod_id": rootProject.mod_id, "mod_namespace": rootProject.mod_namespace, diff --git a/neoforge/src/main/java/io/github/steveplays28/stevesrealisticsleep/neoforge/event/StevesRealisticSleepNeoForgeEventHandler.java b/neoforge/src/main/java/io/github/steveplays28/stevesrealisticsleep/neoforge/event/StevesRealisticSleepNeoForgeEventHandler.java index 8c48217..059ea63 100644 --- a/neoforge/src/main/java/io/github/steveplays28/stevesrealisticsleep/neoforge/event/StevesRealisticSleepNeoForgeEventHandler.java +++ b/neoforge/src/main/java/io/github/steveplays28/stevesrealisticsleep/neoforge/event/StevesRealisticSleepNeoForgeEventHandler.java @@ -1,20 +1,28 @@ package io.github.steveplays28.stevesrealisticsleep.neoforge.event; import io.github.steveplays28.stevesrealisticsleep.StevesRealisticSleep; -import net.neoforged.bus.api.Event; +import net.minecraft.entity.player.PlayerEntity; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.event.entity.player.SleepingTimeCheckEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.CanPlayerSleepEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import static io.github.steveplays28.stevesrealisticsleep.StevesRealisticSleep.config; -@Mod.EventBusSubscriber(modid = StevesRealisticSleep.MOD_ID) +@EventBusSubscriber(modid = StevesRealisticSleep.MOD_ID) public class StevesRealisticSleepNeoForgeEventHandler { @SubscribeEvent - public static void onSleepingTimeCheck(@NotNull SleepingTimeCheckEvent event) { - if (config.allowDaySleeping) { - event.setResult(Event.Result.ALLOW); + public static void onCanPlayerSleep(@NotNull CanPlayerSleepEvent event) { + if (!config.allowDaySleeping) { + return; } + + @Nullable var vanillaProblem = event.getVanillaProblem(); + if (vanillaProblem == null || !vanillaProblem.equals(PlayerEntity.SleepFailureReason.NOT_POSSIBLE_NOW)) { + return; + } + + event.setProblem(null); } } diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml