diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 312a2b4a3..f4bf853ec 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -7,8 +7,8 @@ plugins { repositories { gradlePluginPortal() mavenCentral() - maven("https://maven.minecraftforge.net/") { - name = "MinecraftForge" + maven("https://maven.neoforged.net/releases/") { + name = "NeoForged" } maven("https://maven.architectury.dev/") { name = "Architectury" diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt index b448b7e0d..30e7ebd0d 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt @@ -52,6 +52,8 @@ class SubprojectPlugin: Plugin { val loom = project.the() loom.silentMojangMappingsLicense() + // FIXME y tho? :( + loom.mixin.useLegacyMixinAp = true loom.mixin.defaultRefmapName = "flywheel.refmap.json" } @@ -181,6 +183,6 @@ val processResourcesExpandProperties = listOf( "minecraft_semver_version_range", "minecraft_maven_version_range", "fabric_api_version_range", - "forge_version_range", + "neoforge_version_range", ) diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java index 993c0dffb..2840cd3aa 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java @@ -102,7 +102,7 @@ abstract class LevelRendererMixin { flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); } - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER)) + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSectionLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER)) private void flywheel$onStage$afterTranslucentTerrain(CallbackInfo ci) { flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); } @@ -113,6 +113,7 @@ abstract class LevelRendererMixin { flywheel$dispatch(RenderStage.AFTER_PARTICLES); } + //fixme take a look over if this is still needed @Group(name = "onStage$afterParticles") @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;)V", shift = Shift.AFTER)) private void flywheel$onStage$afterParticles$forge(CallbackInfo ci) { diff --git a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java index 7b55a0279..9a77c0d8c 100644 --- a/common/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java +++ b/common/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java @@ -10,9 +10,9 @@ import net.minecraft.world.level.block.entity.BlockEntity; -@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask") +@Mixin(targets = "net.minecraft.client.renderer.chunk.SectionRenderDispatcher$RenderSection$RebuildTask") abstract class RebuildTaskMixin { - @Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true) + @Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true) private void flywheel$tryAddBlockEntity(@Coerce Object compileResults, BlockEntity blockEntity, CallbackInfo ci) { if (VisualizationHelper.tryAddBlockEntity(blockEntity)) { ci.cancel(); diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java index c1ec8c809..57264a4e3 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java @@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -21,14 +22,14 @@ abstract class MinecraftMixin { @Final private ReloadableResourceManager resourceManager; - @Inject(method = "method_24040", at = @At("HEAD")) - private void flywheel$onEndInitialResourceReload(Optional error, CallbackInfo ci) { + @Inject(method = "method_53522", at = @At("HEAD")) + private void flywheel$onEndInitialResourceReload(@Coerce Object gameLoadCookie, Optional error, CallbackInfo ci) { EndClientResourceReloadCallback.EVENT.invoker() .onEndClientResourceReload((Minecraft) (Object) this, resourceManager, true, error); } @Inject(method = "method_24228", at = @At("HEAD")) - private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture future, + private void flywheel$onEndManualResourceReload(boolean recovery, @Coerce Object gameLoadCookie, CompletableFuture future, Optional error, CallbackInfo ci) { EndClientResourceReloadCallback.EVENT.invoker() .onEndClientResourceReload((Minecraft) (Object) this, resourceManager, false, error); diff --git a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/fabric/MinecraftMixin.java b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/fabric/MinecraftMixin.java index f80623ea7..e4c0d86af 100644 --- a/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/fabric/MinecraftMixin.java +++ b/fabric/src/main/java/com/jozufozu/flywheel/impl/mixin/fabric/MinecraftMixin.java @@ -23,7 +23,7 @@ abstract class MinecraftMixin { } } - @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + @Inject(method = "clearClientLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) private void flywheel$onClearLevel(CallbackInfo ci) { if (level != null) { LevelAttached.invalidateLevel(level); diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 49359a794..e4d050cce 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -55,12 +55,6 @@ defaultPackageInfos { } loom { - forge { - mixinConfig("flywheel.backend.mixins.json") - mixinConfig("flywheel.impl.mixins.json") - mixinConfig("flywheel.impl.sodium.mixins.json") - } - runs { configureEach { property("forge.logging.markers", "") @@ -69,8 +63,12 @@ loom { } } +repositories { + maven("https://maven.neoforged.net/releases/") +} + dependencies { - forge("net.minecraftforge:forge:${property("minecraft_version")}-${property("forge_version")}") + neoForge("net.neoforged:neoforge:${property("neoforge_version")}") modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}") modCompileOnly("maven.modrinth:oculus:${property("oculus_version")}") diff --git a/forge/gradle.properties b/forge/gradle.properties index a58ba1416..2e6ed7676 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -1 +1 @@ -loom.platform = forge +loom.platform = neoforge diff --git a/forge/src/api/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java b/forge/src/api/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java index 5f0bfe6ae..71894d763 100644 --- a/forge/src/api/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java +++ b/forge/src/api/java/com/jozufozu/flywheel/api/event/BeginFrameEvent.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.api.event; -import net.minecraftforge.eventbus.api.Event; +import net.neoforged.bus.api.Event; /** * This event is posted to the Forge event bus. diff --git a/forge/src/api/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java b/forge/src/api/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java index da5d07ac2..7140a4099 100644 --- a/forge/src/api/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java +++ b/forge/src/api/java/com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent.java @@ -4,8 +4,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraftforge.eventbus.api.Event; -import net.minecraftforge.fml.event.IModBusEvent; +import net.neoforged.bus.api.Event; +import net.neoforged.fml.event.IModBusEvent; /** * This event is posted to mod event buses. diff --git a/forge/src/api/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java b/forge/src/api/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java index 7ae09cd11..96717b97f 100644 --- a/forge/src/api/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java +++ b/forge/src/api/java/com/jozufozu/flywheel/api/event/ReloadLevelRendererEvent.java @@ -1,9 +1,10 @@ package com.jozufozu.flywheel.api.event; +import net.neoforged.bus.api.Event; + import org.jetbrains.annotations.Nullable; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraftforge.eventbus.api.Event; /** * This event is posted to the Forge event bus. diff --git a/forge/src/api/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java b/forge/src/api/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java index c67b285d6..78e9eb204 100644 --- a/forge/src/api/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java +++ b/forge/src/api/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.api.event; +import net.neoforged.bus.api.Event; + import org.joml.Matrix4f; import com.mojang.blaze3d.vertex.PoseStack; @@ -7,7 +9,6 @@ import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.RenderBuffers; -import net.minecraftforge.eventbus.api.Event; /** * This event is posted to the Forge event bus. diff --git a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java index cb6882a4d..843aa1ed9 100644 --- a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java +++ b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/BakedModelBufferer.java @@ -3,6 +3,9 @@ import java.util.Iterator; import java.util.function.Function; +import net.neoforged.neoforge.client.ChunkRenderTypeSet; +import net.neoforged.neoforge.client.model.data.ModelData; + import org.jetbrains.annotations.Nullable; import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; @@ -20,8 +23,6 @@ import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; -import net.minecraftforge.client.ChunkRenderTypeSet; -import net.minecraftforge.client.model.data.ModelData; final class BakedModelBufferer { private static final RenderType[] CHUNK_LAYERS = RenderType.chunkBufferLayers().toArray(RenderType[]::new); diff --git a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBakedModelBuilder.java b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBakedModelBuilder.java index 8ad0e0404..ce633db5d 100644 --- a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBakedModelBuilder.java +++ b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBakedModelBuilder.java @@ -2,6 +2,8 @@ import java.util.function.BiFunction; +import net.neoforged.neoforge.client.model.data.ModelData; + import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; @@ -20,7 +22,6 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; public final class ForgeBakedModelBuilder extends BakedModelBuilder { @Nullable diff --git a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBlockModelBuilder.java b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBlockModelBuilder.java index af06eadc9..680381bbf 100644 --- a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBlockModelBuilder.java +++ b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeBlockModelBuilder.java @@ -2,6 +2,8 @@ import java.util.function.BiFunction; +import net.neoforged.neoforge.client.model.data.ModelData; + import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; @@ -18,7 +20,6 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; public final class ForgeBlockModelBuilder extends BlockModelBuilder { @Nullable diff --git a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java index 48c3363b4..8c9f61e73 100644 --- a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java +++ b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java @@ -3,6 +3,8 @@ import java.util.function.BiFunction; import java.util.function.Function; +import net.neoforged.neoforge.client.model.data.ModelData; + import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; @@ -19,7 +21,6 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraftforge.client.model.data.ModelData; public final class ForgeMultiBlockModelBuilder extends MultiBlockModelBuilder { @Nullable diff --git a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java index 9957b2f2c..7782c23ba 100644 --- a/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java +++ b/forge/src/lib/java/com/jozufozu/flywheel/lib/model/baked/PartialModelEventHandler.java @@ -2,11 +2,12 @@ import java.util.Map; +import net.neoforged.neoforge.client.event.ModelEvent; + import org.jetbrains.annotations.ApiStatus; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.event.ModelEvent; @ApiStatus.Internal public final class PartialModelEventHandler { diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java index f8cdb2929..5889d0b90 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwCommands.java @@ -15,9 +15,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; -import net.minecraftforge.client.event.RegisterClientCommandsEvent; -import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; -import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; +import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent; +import net.neoforged.neoforge.common.ModConfigSpec; public final class FlwCommands { private FlwCommands() { @@ -28,7 +27,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { LiteralArgumentBuilder command = Commands.literal("flywheel"); - ConfigValue backendValue = config.client.backend; + ModConfigSpec.ConfigValue backendValue = config.client.backend; command.then(Commands.literal("backend") .executes(context -> { Backend backend = BackendManager.getBackend(); @@ -58,7 +57,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { return Command.SINGLE_SUCCESS; }))); - BooleanValue limitUpdatesValue = config.client.limitUpdates; + ModConfigSpec.BooleanValue limitUpdatesValue = config.client.limitUpdates; command.then(Commands.literal("limitUpdates") .executes(context -> { if (limitUpdatesValue.get()) { diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwImplXplatImpl.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwImplXplatImpl.java index 1234a4a4a..5ae39f9eb 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwImplXplatImpl.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwImplXplatImpl.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.impl; +import net.neoforged.neoforge.common.NeoForge; + import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.event.BeginFrameEvent; @@ -9,22 +11,21 @@ import com.jozufozu.flywheel.api.event.RenderStageEvent; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraftforge.common.MinecraftForge; public class FlwImplXplatImpl implements FlwImplXplat { @Override public void dispatchBeginFrameEvent(RenderContext context) { - MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(context)); + NeoForge.EVENT_BUS.post(new BeginFrameEvent(context)); } @Override public void dispatchReloadLevelRendererEvent(@Nullable ClientLevel level) { - MinecraftForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); + NeoForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); } @Override public void dispatchRenderStageEvent(RenderContext context, RenderStage stage) { - MinecraftForge.EVENT_BUS.post(new RenderStageEvent(context, stage)); + NeoForge.EVENT_BUS.post(new RenderStageEvent(context, stage)); } @Override diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java index 4dc57a159..32ebe7763 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlwLibXplatImpl.java @@ -2,6 +2,9 @@ import java.lang.reflect.Field; +import net.neoforged.fml.ModList; +import net.neoforged.fml.util.ObfuscationReflectionHelper; + import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -23,8 +26,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.util.ObfuscationReflectionHelper; public class FlwLibXplatImpl implements FlwLibXplat { private static final Logger LOGGER = LogUtils.getLogger(); @@ -38,6 +39,7 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { field.setAccessible(true); field.set(dispatcher, field.get(defaultDispatcher)); } + // fixme ~ is this still needed? neoforge uses mojmap at runtime ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); } catch (Exception e) { LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java index 7905f3709..8fadd30f8 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/FlywheelForge.java @@ -1,5 +1,30 @@ package com.jozufozu.flywheel.impl; +import net.minecraft.core.registries.Registries; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.CrashReportCallables; +import net.neoforged.fml.DistExecutor; +import net.neoforged.fml.LogicalSide; +import net.neoforged.fml.ModLoadingContext; + +import net.neoforged.fml.common.Mod; + +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent; +import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent; +import net.neoforged.neoforge.common.NeoForge; + +import net.neoforged.neoforge.event.TickEvent; + +import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; + +import net.neoforged.neoforge.event.entity.EntityLeaveLevelEvent; + +import net.neoforged.neoforge.event.level.LevelEvent; +import net.neoforged.neoforge.registries.RegisterEvent; + import org.apache.maven.artifact.versioning.ArtifactVersion; import org.jetbrains.annotations.UnknownNullability; @@ -18,32 +43,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.commands.synchronization.ArgumentTypeInfos; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; -import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.event.entity.EntityLeaveLevelEvent; -import net.minecraftforge.event.level.LevelEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.CrashReportCallables; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.LogicalSide; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegisterEvent; @Mod(Flywheel.ID) public final class FlywheelForge { @UnknownNullability private static ArtifactVersion version; - public FlywheelForge() { + public FlywheelForge(IEventBus modEventBus) { ModLoadingContext modLoadingContext = ModLoadingContext.get(); version = modLoadingContext @@ -51,9 +57,7 @@ public FlywheelForge() { .getModInfo() .getVersion(); - IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; - IEventBus modEventBus = FMLJavaModLoadingContext.get() - .getModEventBus(); + IEventBus forgeEventBus = NeoForge.EVENT_BUS; ForgeFlwConfig.INSTANCE.registerSpecs(modLoadingContext); @@ -88,7 +92,7 @@ private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBu forgeEventBus.addListener((CustomizeGuiOverlayEvent.DebugText e) -> { Minecraft minecraft = Minecraft.getInstance(); - if (!minecraft.options.renderDebug) { + if (!minecraft.getDebugOverlay().showDebugScreen()) { return; } @@ -97,16 +101,16 @@ private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBu modEventBus.addListener((FMLLoadCompleteEvent e) -> FlywheelInit.freezeRegistries()); - modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); + modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error() != null)); modEventBus.addListener((FMLCommonSetupEvent e) -> { ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); ArgumentTypeInfos.registerByClass(DebugModeArgument.class, DebugModeArgument.INFO); }); modEventBus.addListener((RegisterEvent e) -> { - if (e.getRegistryKey().equals(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES)) { - e.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("backend"), () -> BackendArgument.INFO); - e.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("debug_mode"), () -> DebugModeArgument.INFO); + if (e.getRegistryKey().equals(Registries.COMMAND_ARGUMENT_TYPE)) { + e.register(Registries.COMMAND_ARGUMENT_TYPE, Flywheel.rl("backend"), () -> BackendArgument.INFO); + e.register(Registries.COMMAND_ARGUMENT_TYPE, Flywheel.rl("debug_mode"), () -> DebugModeArgument.INFO); } }); } diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java b/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java index 012bea791..f974d8911 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/ForgeFlwConfig.java @@ -1,5 +1,9 @@ package com.jozufozu.flywheel.impl; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.ModConfigSpec; + import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -10,19 +14,16 @@ import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; public class ForgeFlwConfig implements FlwConfig { private static final Logger LOGGER = LogUtils.getLogger(); public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig(); public final ClientConfig client; - private final ForgeConfigSpec clientSpec; + private final ModConfigSpec clientSpec; private ForgeFlwConfig() { - Pair clientPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); + Pair clientPair = new ModConfigSpec.Builder().configure(ClientConfig::new); this.client = clientPair.getLeft(); clientSpec = clientPair.getRight(); } @@ -72,11 +73,11 @@ public void registerSpecs(ModLoadingContext context) { } public static class ClientConfig { - public final ForgeConfigSpec.ConfigValue backend; - public final ForgeConfigSpec.BooleanValue limitUpdates; - public final ForgeConfigSpec.IntValue workerThreads; + public final ModConfigSpec.ConfigValue backend; + public final ModConfigSpec.BooleanValue limitUpdates; + public final ModConfigSpec.IntValue workerThreads; - private ClientConfig(ForgeConfigSpec.Builder builder) { + private ClientConfig(ModConfigSpec.Builder builder) { backend = builder.comment("Select the backend to use.") .define("backend", Backend.REGISTRY.getIdOrThrow(BackendManager.getDefaultBackend()).toString()); diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java index 38ad493bb..8db0f2558 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java @@ -3,35 +3,34 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; +import net.neoforged.fml.ModLoader; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; -import com.mojang.realmsclient.client.RealmsClient; import net.minecraft.client.Minecraft; -import net.minecraft.client.main.GameConfig; -import net.minecraft.server.packs.resources.ReloadInstance; import net.minecraft.server.packs.resources.ReloadableResourceManager; -import net.minecraftforge.fml.ModLoader; -@Mixin(Minecraft.class) +@Mixin(value = Minecraft.class, remap = false) abstract class MinecraftMixin { @Shadow @Final private ReloadableResourceManager resourceManager; - @Inject(method = "lambda$new$5", at = @At("HEAD")) - private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, Optional error, CallbackInfo ci) { + @Inject(method = "lambda$new$7", at = @At("HEAD")) + private void flywheel$onEndInitialResourceReload(@Coerce Object minecraft$gameloadcookie, Optional error, CallbackInfo ci) { ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error)); } - @Inject(method = "lambda$reloadResourcePacks$28", at = @At("HEAD")) - private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture future, Optional error, CallbackInfo ci) { + @Inject(method = "lambda$reloadResourcePacks$39", at = @At("HEAD")) + private void flywheel$onEndManualResourceReload(boolean bl, @Coerce Object minecraft$gameloadcookie, CompletableFuture completablefuture, Optional error, CallbackInfo ci) { ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error)); } } diff --git a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java index aa58d4c7a..1960e335f 100644 --- a/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java +++ b/forge/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java @@ -4,14 +4,14 @@ import java.util.Set; import java.util.function.Supplier; +import net.neoforged.fml.loading.LoadingModList; + import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import com.google.common.base.Suppliers; -import net.minecraftforge.fml.loading.LoadingModList; - public class SodiumMixinPlugin implements IMixinConfigPlugin { private static final Supplier IS_SODIUM_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById("rubidium") != null); diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 2dc330582..546372adf 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -14,22 +14,29 @@ authors = "Jozufozu, PepperCode1" displayURL = "${mod_homepage}" displayTest = "IGNORE_ALL_VERSION" +[[mixins]] +config = "flywheel.backend.mixins.json" +[[mixins]] +config = "flywheel.impl.mixins.json" +[[mixins]] +config = "flywheel.impl.sodium.mixins.json" + [[dependencies.${mod_id}]] modId = "minecraft" -mandatory = true +type = "required" versionRange = "${minecraft_maven_version_range}" side = "CLIENT" [[dependencies.${mod_id}]] -modId = "forge" -mandatory = true -versionRange = "${forge_version_range}" +modId = "neoforge" +type = "required" +versionRange = "${neoforge_version_range}" side = "CLIENT" +# Breaks dependency [[dependencies.${mod_id}]] -# This replicates a "breaks" dependency. -# There's a mixin crash with Rubidium <0.7.0. modId = "rubidium" -mandatory = false +type = "incompatible" +reason = "mixin crash with any version of rubidium under 0.7.0" versionRange = "[0.7.0,)" side = "CLIENT" diff --git a/gradle.properties b/gradle.properties index 3b9b3881f..d0b1d3fe5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,22 +12,21 @@ mod_issues = https://github.com/Jozufozu/Flywheel/issues mod_homepage = https://github.com/Jozufozu/Flywheel # Mod dependency declarations -minecraft_semver_version_range = >=1.20.1 <1.20.2 -minecraft_maven_version_range = [1.20.1,1.20.2) -fabric_api_version_range = >=0.86.0 -forge_version_range = [47.0.0,) +minecraft_semver_version_range = >=1.20.4 <1.20.5 +minecraft_maven_version_range = [1.20.4,1.20.5) +fabric_api_version_range = >=0.97.0 +neoforge_version_range = [20.4.234,) # General build dependency versions java_version = 17 arch_loom_version = 1.6-SNAPSHOT -cursegradle_version = 1.4.0 -parchment_version = 2023.09.03 +parchment_version = 2024.04.14 # Minecraft build dependency versions -minecraft_version = 1.20.1 -forge_version = 47.2.19 -fabric_loader_version = 0.15.9 -fabric_api_version = 0.92.1+1.20.1 +minecraft_version = 1.20.4 +neoforge_version = 20.4.234 +fabric_loader_version = 0.15.10 +fabric_api_version = 0.97.0+1.20.4 # Build dependency mod versions sodium_version = mc1.20.1-0.5.8 @@ -36,4 +35,4 @@ embeddium_version = 0.3.9+mc1.20.1 oculus_version = 1.20.1-1.6.15a # Publication info -artifact_minecraft_version = 1.20.1 +artifact_minecraft_version = 1.20.4 diff --git a/settings.gradle.kts b/settings.gradle.kts index cf8fd7a12..5bb943455 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,8 +2,8 @@ pluginManagement { repositories { gradlePluginPortal() mavenCentral() - maven("https://maven.minecraftforge.net/") { - name = "MinecraftForge" + maven("https://maven.neoforged.net/releases/") { + name = "NeoForged" } maven("https://maven.architectury.dev/") { name = "Architectury"