Port to 1.20.4

This commit is contained in:
IThundxr 2024-05-05 11:05:33 -04:00
parent ee3958b140
commit 56b0fce44d
Failed to generate hash of commit
27 changed files with 129 additions and 88 deletions

View file

@ -7,8 +7,8 @@ plugins {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
mavenCentral() mavenCentral()
maven("https://maven.minecraftforge.net/") { maven("https://maven.neoforged.net/releases/") {
name = "MinecraftForge" name = "NeoForged"
} }
maven("https://maven.architectury.dev/") { maven("https://maven.architectury.dev/") {
name = "Architectury" name = "Architectury"

View file

@ -53,6 +53,8 @@ class SubprojectPlugin: Plugin<Project> {
val loom = project.the<LoomGradleExtensionAPI>() val loom = project.the<LoomGradleExtensionAPI>()
loom.silentMojangMappingsLicense() loom.silentMojangMappingsLicense()
// FIXME y tho? :(
loom.mixin.useLegacyMixinAp = true
loom.mixin.defaultRefmapName = "flywheel.refmap.json" loom.mixin.defaultRefmapName = "flywheel.refmap.json"
} }
@ -182,6 +184,6 @@ val processResourcesExpandProperties = listOf(
"minecraft_semver_version_range", "minecraft_semver_version_range",
"minecraft_maven_version_range", "minecraft_maven_version_range",
"fabric_api_version_range", "fabric_api_version_range",
"forge_version_range", "neoforge_version_range",
) )

View file

@ -102,7 +102,7 @@ abstract class LevelRendererMixin {
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); 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) { private void flywheel$onStage$afterTranslucentTerrain(CallbackInfo ci) {
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN);
} }
@ -113,6 +113,7 @@ abstract class LevelRendererMixin {
flywheel$dispatch(RenderStage.AFTER_PARTICLES); flywheel$dispatch(RenderStage.AFTER_PARTICLES);
} }
//fixme take a look over if this is still needed
@Group(name = "onStage$afterParticles") @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)) @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) { private void flywheel$onStage$afterParticles$forge(CallbackInfo ci) {

View file

@ -9,9 +9,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import dev.engine_room.flywheel.lib.visual.VisualizationHelper; import dev.engine_room.flywheel.lib.visual.VisualizationHelper;
import net.minecraft.world.level.block.entity.BlockEntity; 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 { 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) { private void flywheel$tryAddBlockEntity(@Coerce Object compileResults, BlockEntity blockEntity, CallbackInfo ci) {
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) { if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
ci.cancel(); ci.cancel();

View file

@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; 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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -30,14 +31,14 @@ abstract class MinecraftMixin {
FabricFlwConfig.INSTANCE.load(); FabricFlwConfig.INSTANCE.load();
} }
@Inject(method = "method_24040", at = @At("HEAD")) @Inject(method = "method_53522", at = @At("HEAD"))
private void flywheel$onEndInitialResourceReload(Optional<Throwable> error, CallbackInfo ci) { private void flywheel$onEndInitialResourceReload(@Coerce Object gameLoadCookie, Optional<Throwable> error, CallbackInfo ci) {
EndClientResourceReloadCallback.EVENT.invoker() EndClientResourceReloadCallback.EVENT.invoker()
.onEndClientResourceReload((Minecraft) (Object) this, resourceManager, true, error); .onEndClientResourceReload((Minecraft) (Object) this, resourceManager, true, error);
} }
@Inject(method = "method_24228", at = @At("HEAD")) @Inject(method = "method_24228", at = @At("HEAD"))
private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture<Void> future, private void flywheel$onEndManualResourceReload(boolean recovery, @Coerce Object gameLoadCookie, CompletableFuture<Void> future,
Optional<Throwable> error, CallbackInfo ci) { Optional<Throwable> error, CallbackInfo ci) {
EndClientResourceReloadCallback.EVENT.invoker() EndClientResourceReloadCallback.EVENT.invoker()
.onEndClientResourceReload((Minecraft) (Object) this, resourceManager, false, error); .onEndClientResourceReload((Minecraft) (Object) this, resourceManager, false, error);

View file

@ -22,7 +22,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) { private void flywheel$onClearLevel(CallbackInfo ci) {
if (level != null) { if (level != null) {
LevelAttached.invalidateLevel(level); LevelAttached.invalidateLevel(level);

View file

@ -61,12 +61,6 @@ defaultPackageInfos {
} }
loom { loom {
forge {
mixinConfig("flywheel.backend.mixins.json")
mixinConfig("flywheel.impl.mixins.json")
mixinConfig("flywheel.impl.sodium.mixins.json")
}
runs { runs {
configureEach { configureEach {
property("forge.logging.markers", "") property("forge.logging.markers", "")
@ -75,8 +69,12 @@ loom {
} }
} }
repositories {
maven("https://maven.neoforged.net/releases/")
}
dependencies { 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:embeddium:${property("embeddium_version")}")
modCompileOnly("maven.modrinth:oculus:${property("oculus_version")}") modCompileOnly("maven.modrinth:oculus:${property("oculus_version")}")

View file

@ -1 +1 @@
loom.platform = forge loom.platform = neoforge

View file

@ -1,6 +1,6 @@
package dev.engine_room.flywheel.api.event; package dev.engine_room.flywheel.api.event;
import net.minecraftforge.eventbus.api.Event; import net.neoforged.bus.api.Event;
/** /**
* This event is posted to the Forge event bus. * This event is posted to the Forge event bus.

View file

@ -4,8 +4,8 @@ import java.util.Optional;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraftforge.eventbus.api.Event; import net.neoforged.bus.api.Event;
import net.minecraftforge.fml.event.IModBusEvent; import net.neoforged.fml.event.IModBusEvent;
/** /**
* This event is posted to mod event buses. * This event is posted to mod event buses.

View file

@ -1,9 +1,10 @@
package dev.engine_room.flywheel.api.event; package dev.engine_room.flywheel.api.event;
import net.neoforged.bus.api.Event;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraftforge.eventbus.api.Event;
/** /**
* This event is posted to the Forge event bus. * This event is posted to the Forge event bus.

View file

@ -1,5 +1,7 @@
package dev.engine_room.flywheel.api.event; package dev.engine_room.flywheel.api.event;
import net.neoforged.bus.api.Event;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -7,7 +9,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.RenderBuffers; import net.minecraft.client.renderer.RenderBuffers;
import net.minecraftforge.eventbus.api.Event;
/** /**
* This event is posted to the Forge event bus. * This event is posted to the Forge event bus.

View file

@ -3,6 +3,9 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.Iterator; import java.util.Iterator;
import java.util.function.Function; 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 org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer;
@ -20,8 +23,6 @@ import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
final class BakedModelBufferer { final class BakedModelBufferer {
static final RenderType[] CHUNK_LAYERS = RenderType.chunkBufferLayers().toArray(RenderType[]::new); static final RenderType[] CHUNK_LAYERS = RenderType.chunkBufferLayers().toArray(RenderType[]::new);

View file

@ -2,6 +2,8 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -16,7 +18,6 @@ import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.ModelData;
public final class ForgeBakedModelBuilder extends BakedModelBuilder { public final class ForgeBakedModelBuilder extends BakedModelBuilder {
@Nullable @Nullable

View file

@ -2,6 +2,8 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -14,7 +16,6 @@ import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.ModelData;
public final class ForgeBlockModelBuilder extends BlockModelBuilder { public final class ForgeBlockModelBuilder extends BlockModelBuilder {
@Nullable @Nullable

View file

@ -3,6 +3,8 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -15,7 +17,6 @@ import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraftforge.client.model.data.ModelData;
public final class ForgeMultiBlockModelBuilder extends MultiBlockModelBuilder { public final class ForgeMultiBlockModelBuilder extends MultiBlockModelBuilder {
@Nullable @Nullable

View file

@ -2,11 +2,12 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.Map; import java.util.Map;
import net.neoforged.neoforge.client.event.ModelEvent;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.event.ModelEvent;
@ApiStatus.Internal @ApiStatus.Internal
public final class PartialModelEventHandler { public final class PartialModelEventHandler {

View file

@ -15,9 +15,8 @@ import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraftforge.client.event.RegisterClientCommandsEvent; import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; import net.neoforged.neoforge.common.ModConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
public final class FlwCommands { public final class FlwCommands {
private FlwCommands() { private FlwCommands() {
@ -26,7 +25,7 @@ public final class FlwCommands {
public static void registerClientCommands(RegisterClientCommandsEvent event) { public static void registerClientCommands(RegisterClientCommandsEvent event) {
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal("flywheel"); LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal("flywheel");
ConfigValue<String> backendValue = ForgeFlwConfig.INSTANCE.client.backend; ModConfigSpec.ConfigValue<String> backendValue = ForgeFlwConfig.INSTANCE.client.backend;
command.then(Commands.literal("backend") command.then(Commands.literal("backend")
.executes(context -> { .executes(context -> {
Backend backend = BackendManager.getBackend(); Backend backend = BackendManager.getBackend();
@ -56,7 +55,7 @@ public final class FlwCommands {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
}))); })));
BooleanValue limitUpdatesValue = ForgeFlwConfig.INSTANCE.client.limitUpdates; ModConfigSpec.BooleanValue limitUpdatesValue = ForgeFlwConfig.INSTANCE.client.limitUpdates;
command.then(Commands.literal("limitUpdates") command.then(Commands.literal("limitUpdates")
.executes(context -> { .executes(context -> {
if (limitUpdatesValue.get()) { if (limitUpdatesValue.get()) {

View file

@ -1,5 +1,7 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.flywheel.impl;
import net.neoforged.neoforge.common.NeoForge;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import dev.engine_room.flywheel.api.event.BeginFrameEvent; import dev.engine_room.flywheel.api.event.BeginFrameEvent;
@ -8,22 +10,21 @@ import dev.engine_room.flywheel.api.event.RenderContext;
import dev.engine_room.flywheel.api.event.RenderStage; import dev.engine_room.flywheel.api.event.RenderStage;
import dev.engine_room.flywheel.api.event.RenderStageEvent; import dev.engine_room.flywheel.api.event.RenderStageEvent;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraftforge.common.MinecraftForge;
public class FlwImplXplatImpl implements FlwImplXplat { public class FlwImplXplatImpl implements FlwImplXplat {
@Override @Override
public void dispatchBeginFrameEvent(RenderContext context) { public void dispatchBeginFrameEvent(RenderContext context) {
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(context)); NeoForge.EVENT_BUS.post(new BeginFrameEvent(context));
} }
@Override @Override
public void dispatchReloadLevelRendererEvent(@Nullable ClientLevel level) { public void dispatchReloadLevelRendererEvent(@Nullable ClientLevel level) {
MinecraftForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); NeoForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level));
} }
@Override @Override
public void dispatchRenderStageEvent(RenderContext context, RenderStage stage) { public void dispatchRenderStageEvent(RenderContext context, RenderStage stage) {
MinecraftForge.EVENT_BUS.post(new RenderStageEvent(context, stage)); NeoForge.EVENT_BUS.post(new RenderStageEvent(context, stage));
} }
@Override @Override

View file

@ -2,6 +2,9 @@ package dev.engine_room.flywheel.impl;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import net.neoforged.fml.ModList;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat; import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
@ -20,8 +23,6 @@ import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
public class FlwLibXplatImpl implements FlwLibXplat { public class FlwLibXplatImpl implements FlwLibXplat {
@Override @Override
@ -33,6 +34,7 @@ public class FlwLibXplatImpl implements FlwLibXplat {
field.setAccessible(true); field.setAccessible(true);
field.set(dispatcher, field.get(defaultDispatcher)); 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_"); ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_");
} catch (Exception e) { } catch (Exception e) {
FlwImpl.LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); FlwImpl.LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e);

View file

@ -1,5 +1,30 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.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.apache.maven.artifact.versioning.ArtifactVersion;
import org.jetbrains.annotations.UnknownNullability; import org.jetbrains.annotations.UnknownNullability;
@ -41,7 +66,7 @@ public final class FlywheelForge {
@UnknownNullability @UnknownNullability
private static ArtifactVersion version; private static ArtifactVersion version;
public FlywheelForge() { public FlywheelForge(IEventBus modEventBus) {
ModLoadingContext modLoadingContext = ModLoadingContext.get(); ModLoadingContext modLoadingContext = ModLoadingContext.get();
version = modLoadingContext version = modLoadingContext
@ -49,9 +74,7 @@ public final class FlywheelForge {
.getModInfo() .getModInfo()
.getVersion(); .getVersion();
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; IEventBus forgeEventBus = NeoForge.EVENT_BUS;
IEventBus modEventBus = FMLJavaModLoadingContext.get()
.getModEventBus();
ForgeFlwConfig.INSTANCE.registerSpecs(modLoadingContext); ForgeFlwConfig.INSTANCE.registerSpecs(modLoadingContext);
@ -86,23 +109,23 @@ public final class FlywheelForge {
forgeEventBus.addListener((CustomizeGuiOverlayEvent.DebugText e) -> { forgeEventBus.addListener((CustomizeGuiOverlayEvent.DebugText e) -> {
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
if (!minecraft.options.renderDebug) { if (!minecraft.getDebugOverlay().showDebugScreen()) {
return; return;
} }
FlwDebugInfo.addDebugInfo(minecraft, e.getRight()); FlwDebugInfo.addDebugInfo(minecraft, e.getRight());
}); });
modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error() != null));
modEventBus.addListener((FMLCommonSetupEvent e) -> { modEventBus.addListener((FMLCommonSetupEvent e) -> {
ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO);
ArgumentTypeInfos.registerByClass(DebugModeArgument.class, DebugModeArgument.INFO); ArgumentTypeInfos.registerByClass(DebugModeArgument.class, DebugModeArgument.INFO);
}); });
modEventBus.addListener((RegisterEvent e) -> { modEventBus.addListener((RegisterEvent e) -> {
if (e.getRegistryKey().equals(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES)) { if (e.getRegistryKey().equals(Registries.COMMAND_ARGUMENT_TYPE)) {
e.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("backend"), () -> BackendArgument.INFO); e.register(Registries.COMMAND_ARGUMENT_TYPE, Flywheel.rl("backend"), () -> BackendArgument.INFO);
e.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("debug_mode"), () -> DebugModeArgument.INFO); e.register(Registries.COMMAND_ARGUMENT_TYPE, Flywheel.rl("debug_mode"), () -> DebugModeArgument.INFO);
} }
}); });
} }

View file

@ -1,5 +1,9 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.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.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -7,18 +11,15 @@ import dev.engine_room.flywheel.api.backend.Backend;
import dev.engine_room.flywheel.api.backend.BackendManager; import dev.engine_room.flywheel.api.backend.BackendManager;
import net.minecraft.ResourceLocationException; import net.minecraft.ResourceLocationException;
import net.minecraft.resources.ResourceLocation; 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 { public class ForgeFlwConfig implements FlwConfig {
public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig(); public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig();
public final ClientConfig client; public final ClientConfig client;
private final ForgeConfigSpec clientSpec; private final ModConfigSpec clientSpec;
private ForgeFlwConfig() { private ForgeFlwConfig() {
Pair<ClientConfig, ForgeConfigSpec> clientPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); Pair<ClientConfig, ModConfigSpec> clientPair = new ModConfigSpec.Builder().configure(ClientConfig::new);
this.client = clientPair.getLeft(); this.client = clientPair.getLeft();
clientSpec = clientPair.getRight(); clientSpec = clientPair.getRight();
} }
@ -68,11 +69,11 @@ public class ForgeFlwConfig implements FlwConfig {
} }
public static class ClientConfig { public static class ClientConfig {
public final ForgeConfigSpec.ConfigValue<String> backend; public final ModConfigSpec.ConfigValue<String> backend;
public final ForgeConfigSpec.BooleanValue limitUpdates; public final ModConfigSpec.BooleanValue limitUpdates;
public final ForgeConfigSpec.IntValue workerThreads; public final ModConfigSpec.IntValue workerThreads;
private ClientConfig(ForgeConfigSpec.Builder builder) { private ClientConfig(ModConfigSpec.Builder builder) {
backend = builder.comment("Select the backend to use.") backend = builder.comment("Select the backend to use.")
.define("backend", Backend.REGISTRY.getIdOrThrow(BackendManager.getDefaultBackend()).toString()); .define("backend", Backend.REGISTRY.getIdOrThrow(BackendManager.getDefaultBackend()).toString());

View file

@ -4,10 +4,13 @@ import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import net.neoforged.fml.ModLoader;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; 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.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -17,12 +20,9 @@ import com.mojang.realmsclient.client.RealmsClient;
import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent;
import dev.engine_room.flywheel.impl.FlwImpl; import dev.engine_room.flywheel.impl.FlwImpl;
import net.minecraft.client.Minecraft; 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.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraftforge.fml.ModLoader;
@Mixin(Minecraft.class) @Mixin(value = Minecraft.class, remap = false)
abstract class MinecraftMixin { abstract class MinecraftMixin {
@Shadow @Shadow
@Final @Final
@ -35,13 +35,13 @@ abstract class MinecraftMixin {
return arg0; return arg0;
} }
@Inject(method = "lambda$new$5", at = @At("HEAD")) @Inject(method = "lambda$new$7", at = @At("HEAD"))
private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, Optional<Throwable> error, CallbackInfo ci) { private void flywheel$onEndInitialResourceReload(@Coerce Object minecraft$gameloadcookie, Optional<Throwable> error, CallbackInfo ci) {
ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error)); ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error));
} }
@Inject(method = "lambda$reloadResourcePacks$28", at = @At("HEAD")) @Inject(method = "lambda$reloadResourcePacks$39", at = @At("HEAD"))
private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture<Void> future, Optional<Throwable> error, CallbackInfo ci) { private void flywheel$onEndManualResourceReload(boolean bl, @Coerce Object minecraft$gameloadcookie, CompletableFuture<Void> completablefuture, Optional<Throwable> error, CallbackInfo ci) {
ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error)); ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error));
} }
} }

View file

@ -4,14 +4,14 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.neoforged.fml.loading.LoadingModList;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import net.minecraftforge.fml.loading.LoadingModList;
public class SodiumMixinPlugin implements IMixinConfigPlugin { public class SodiumMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> IS_SODIUM_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById("rubidium") != null); private static final Supplier<Boolean> IS_SODIUM_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById("rubidium") != null);

View file

@ -14,22 +14,29 @@ authors = "Jozufozu, PepperCode1"
displayURL = "${mod_homepage}" displayURL = "${mod_homepage}"
displayTest = "IGNORE_ALL_VERSION" 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}]] [[dependencies.${mod_id}]]
modId = "minecraft" modId = "minecraft"
mandatory = true type = "required"
versionRange = "${minecraft_maven_version_range}" versionRange = "${minecraft_maven_version_range}"
side = "CLIENT" side = "CLIENT"
[[dependencies.${mod_id}]] [[dependencies.${mod_id}]]
modId = "forge" modId = "neoforge"
mandatory = true type = "required"
versionRange = "${forge_version_range}" versionRange = "${neoforge_version_range}"
side = "CLIENT" side = "CLIENT"
# Breaks dependency
[[dependencies.${mod_id}]] [[dependencies.${mod_id}]]
# This replicates a "breaks" dependency.
# There's a mixin crash with Rubidium <0.7.0.
modId = "rubidium" modId = "rubidium"
mandatory = false type = "incompatible"
reason = "mixin crash with any version of rubidium under 0.7.0"
versionRange = "[0.7.0,)" versionRange = "[0.7.0,)"
side = "CLIENT" side = "CLIENT"

View file

@ -12,22 +12,21 @@ mod_issues = https://github.com/Jozufozu/Flywheel/issues
mod_homepage = https://github.com/Jozufozu/Flywheel mod_homepage = https://github.com/Jozufozu/Flywheel
# Mod dependency declarations # Mod dependency declarations
minecraft_semver_version_range = >=1.20.1 <1.20.2 minecraft_semver_version_range = >=1.20.4 <1.20.5
minecraft_maven_version_range = [1.20.1,1.20.2) minecraft_maven_version_range = [1.20.4,1.20.5)
fabric_api_version_range = >=0.86.0 fabric_api_version_range = >=0.97.0
forge_version_range = [47.0.0,) neoforge_version_range = [20.4.234,)
# General build dependency versions # General build dependency versions
java_version = 17 java_version = 17
arch_loom_version = 1.6-SNAPSHOT arch_loom_version = 1.6-SNAPSHOT
cursegradle_version = 1.4.0 parchment_version = 2024.04.14
parchment_version = 2023.09.03
# Minecraft build dependency versions # Minecraft build dependency versions
minecraft_version = 1.20.1 minecraft_version = 1.20.4
forge_version = 47.2.19 neoforge_version = 20.4.234
fabric_loader_version = 0.15.9 fabric_loader_version = 0.15.10
fabric_api_version = 0.92.1+1.20.1 fabric_api_version = 0.97.0+1.20.4
# Build dependency mod versions # Build dependency mod versions
sodium_version = mc1.20.1-0.5.8 sodium_version = mc1.20.1-0.5.8
@ -37,4 +36,4 @@ oculus_version = 1.20.1-1.6.15a
# Publication info # Publication info
group = dev.engine_room.flywheel group = dev.engine_room.flywheel
artifact_minecraft_version = 1.20.1 artifact_minecraft_version = 1.20.4

View file

@ -2,8 +2,8 @@ pluginManagement {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
mavenCentral() mavenCentral()
maven("https://maven.minecraftforge.net/") { maven("https://maven.neoforged.net/releases/") {
name = "MinecraftForge" name = "NeoForged"
} }
maven("https://maven.architectury.dev/") { maven("https://maven.architectury.dev/") {
name = "Architectury" name = "Architectury"