diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b270af22..4b6f7adb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Build on: [ workflow_dispatch, pull_request, push ] env: - JAVA_VERSION: 17 + JAVA_VERSION: 21 jobs: build: @@ -43,13 +43,13 @@ jobs: path: | common/build/libs/ fabric/build/libs/ - forge/build/libs/ + neoforge/build/libs/ test: strategy: fail-fast: false matrix: - loader: [ forge, fabric ] + loader: [ neoforge, fabric ] needs: build runs-on: ubuntu-latest steps: diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 09e510ed6..fc9aab75d 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -8,8 +8,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/dev/engine_room/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt index 6c3230f0d..0b4756938 100644 --- a/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt +++ b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectPlugin.kt @@ -166,7 +166,7 @@ class SubprojectPlugin: Plugin { } } -val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml") +val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/neoforge.mods.toml") val processResourcesExpandProperties = listOf( "mod_id", @@ -180,6 +180,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/build.gradle.kts b/common/build.gradle.kts index 5aaf88778..37e3d43b5 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -9,7 +9,6 @@ plugins { val api = sourceSets.create("api") val lib = sourceSets.create("lib") val backend = sourceSets.create("backend") -val stubs = sourceSets.create("stubs") val main = sourceSets.getByName("main") transitiveSourceSets { @@ -26,11 +25,8 @@ transitiveSourceSets { rootCompile() compile(api, lib) } - sourceSet(stubs) { - rootCompile() - } sourceSet(main) { - compile(api, lib, backend, stubs) + compile(api, lib, backend) } sourceSet(sourceSets.getByName("test")) { implementation(api, lib, backend) @@ -46,7 +42,6 @@ jarSets { outgoing("commonApiOnly", api) outgoing("commonLib", lib) outgoing("commonBackend", backend) - outgoing("commonStubs", stubs) outgoing("commonImpl", main) // For publishing. @@ -77,6 +72,9 @@ jarSets { dependencies { modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") + modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-fabric") + modCompileOnly("maven.modrinth:iris:${property("iris_version")}-fabric") + testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") } diff --git a/common/src/api/java/dev/engine_room/flywheel/api/Flywheel.java b/common/src/api/java/dev/engine_room/flywheel/api/Flywheel.java index ef18b8b27..8193fa8e5 100644 --- a/common/src/api/java/dev/engine_room/flywheel/api/Flywheel.java +++ b/common/src/api/java/dev/engine_room/flywheel/api/Flywheel.java @@ -9,6 +9,6 @@ private Flywheel() { } public static ResourceLocation rl(String path) { - return new ResourceLocation(ID, path); + return ResourceLocation.fromNamespaceAndPath(ID, path); } } diff --git a/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java b/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java index 5fc9f68b5..5349ffc96 100644 --- a/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java +++ b/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java @@ -2,8 +2,6 @@ import org.joml.Matrix4fc; -import com.mojang.blaze3d.vertex.PoseStack; - import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; @@ -16,7 +14,7 @@ public interface RenderContext { RenderBuffers buffers(); - PoseStack stack(); + Matrix4fc modelView(); Matrix4fc projection(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java index 07e8a9e5c..ffe79c015 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java @@ -73,7 +73,7 @@ public static void update(RenderContext context) { var camY = (float) (cameraPos.y - renderOrigin.getY()); var camZ = (float) (cameraPos.z - renderOrigin.getZ()); - VIEW.set(context.stack().last().pose()); + VIEW.set(context.modelView()); VIEW.translate(-camX, -camY, -camZ); PROJECTION.set(context.projection()); VIEW_PROJECTION.set(context.viewProjection()); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/ShaderSources.java b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/ShaderSources.java index 4599871ae..3a7274cfa 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/ShaderSources.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/glsl/ShaderSources.java @@ -41,7 +41,7 @@ public ShaderSources(ResourceManager manager) { } private static ResourceLocation locationWithoutFlywheelPrefix(ResourceLocation loc) { - return new ResourceLocation(loc.getNamespace(), loc.getPath() + return ResourceLocation.fromNamespaceAndPath(loc.getNamespace(), loc.getPath() .substring(SHADER_DIR.length())); } diff --git a/common/src/backend/resources/flywheel.backend.mixins.json b/common/src/backend/resources/flywheel.backend.mixins.json index b2aa8632a..e67d7c981 100644 --- a/common/src/backend/resources/flywheel.backend.mixins.json +++ b/common/src/backend/resources/flywheel.backend.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "dev.engine_room.flywheel.backend.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "backend-flywheel.refmap.json", "client": [ "AbstractClientPlayerAccessor", diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibLink.java b/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibLink.java index c33ae35c1..203cca392 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibLink.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibLink.java @@ -21,7 +21,7 @@ public interface FlwLibLink { Map getModelPartChildren(ModelPart part); - void compileModelPart(ModelPart part, PoseStack.Pose pose, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha); + void compileModelPart(ModelPart part, PoseStack.Pose pose, VertexConsumer consumer, int light, int overlay, int color); Deque getPoseStack(PoseStack stack); diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibXplat.java b/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibXplat.java index fa58991ca..c2f0de713 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibXplat.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/internal/FlwLibXplat.java @@ -3,16 +3,14 @@ import org.jetbrains.annotations.UnknownNullability; import dev.engine_room.flywheel.api.internal.DependencyInjection; +import dev.engine_room.flywheel.lib.model.SimpleModel; import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder; import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder; import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelManager; -import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; public interface FlwLibXplat { FlwLibXplat INSTANCE = DependencyInjection.load(FlwLibXplat.class, "dev.engine_room.flywheel.impl.FlwLibXplatImpl"); @@ -22,9 +20,9 @@ public interface FlwLibXplat { BlockRenderDispatcher createVanillaBlockRenderDispatcher(); - BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel); + SimpleModel buildBakedModelBuilder(BakedModelBuilder builder); - BlockModelBuilder createBlockModelBuilder(BlockState state); + SimpleModel buildBlockModelBuilder(BlockModelBuilder builder); - MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions); + SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder); } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java index c559f66d0..a20448bdb 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java @@ -20,7 +20,7 @@ public final class ModelUtil { /** - * An alternative BlockRenderDispatcher that circumvents the Forge rendering pipeline to ensure consistency. + * An alternative BlockRenderDispatcher that circumvents the NeoForge rendering pipeline to ensure consistency. * Meant to be used for virtual rendering. */ public static final BlockRenderDispatcher VANILLA_RENDERER = FlwLibXplat.INSTANCE.createVanillaBlockRenderDispatcher(); @@ -60,7 +60,7 @@ public static Material getItemMaterial(RenderType renderType) { if (renderType == Sheets.translucentCullBlockSheet() || renderType == Sheets.translucentItemSheet()) { return Materials.CUTOUT_BLOCK; } - if (renderType == RenderType.glint() || renderType == RenderType.glintDirect()) { + if (renderType == RenderType.glint() || renderType == RenderType.glintTranslucent()) { return Materials.GLINT; } if (renderType == RenderType.entityGlint() || renderType == RenderType.entityGlintDirect()) { diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java index 9e0e3a813..5cad9497c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java @@ -20,9 +20,9 @@ * method with the same parameters will return the same object. */ public final class Models { - private static final ResourceReloadCache BLOCK_STATE = new ResourceReloadCache<>(it -> BlockModelBuilder.create(it) + private static final ResourceReloadCache BLOCK_STATE = new ResourceReloadCache<>(it -> new BlockModelBuilder(it) .build()); - private static final ResourceReloadCache PARTIAL = new ResourceReloadCache<>(it -> BakedModelBuilder.create(it.get()) + private static final ResourceReloadCache PARTIAL = new ResourceReloadCache<>(it -> new BakedModelBuilder(it.get()) .build()); private static final ResourceReloadCache, Model> TRANSFORMED_PARTIAL = new ResourceReloadCache<>(TransformedPartial::create); @@ -88,7 +88,7 @@ private record TransformedPartial(PartialModel partial, T key, BiConsumer materialFunc; - BakedModelBuilder(BakedModel bakedModel) { + public BakedModelBuilder(BakedModel bakedModel) { this.bakedModel = bakedModel; } - public static BakedModelBuilder create(BakedModel bakedModel) { - return FlwLibXplat.INSTANCE.createBakedModelBuilder(bakedModel); - } - public BakedModelBuilder level(BlockAndTintGetter level) { this.level = level; return this; @@ -55,5 +50,11 @@ public BakedModelBuilder materialFunc(BiFunction return this; } - public abstract SimpleModel build(); + public SimpleModel build() { + if (materialFunc == null) { + materialFunc = ModelUtil::getMaterial; + } + + return FlwLibXplat.INSTANCE.buildBakedModelBuilder(this); + } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BlockModelBuilder.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BlockModelBuilder.java index 4ef29359e..8186e197c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BlockModelBuilder.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BlockModelBuilder.java @@ -2,20 +2,19 @@ import java.util.function.BiFunction; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; import dev.engine_room.flywheel.lib.internal.FlwLibXplat; +import dev.engine_room.flywheel.lib.model.ModelUtil; import dev.engine_room.flywheel.lib.model.SimpleModel; import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -@ApiStatus.NonExtendable -public abstract class BlockModelBuilder { +public final class BlockModelBuilder { final BlockState state; @Nullable BlockAndTintGetter level; @@ -24,14 +23,10 @@ public abstract class BlockModelBuilder { @Nullable BiFunction materialFunc; - BlockModelBuilder(BlockState state) { + public BlockModelBuilder(BlockState state) { this.state = state; } - public static BlockModelBuilder create(BlockState state) { - return FlwLibXplat.INSTANCE.createBlockModelBuilder(state); - } - public BlockModelBuilder level(BlockAndTintGetter level) { this.level = level; return this; @@ -47,5 +42,11 @@ public BlockModelBuilder materialFunc(BiFunction return this; } - public abstract SimpleModel build(); + public SimpleModel build() { + if (materialFunc == null) { + materialFunc = ModelUtil::getMaterial; + } + + return FlwLibXplat.INSTANCE.buildBlockModelBuilder(this); + } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java index 05bff07e0..c0191fc4c 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.system.MemoryUtil; -import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.MeshData; import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.SimpleQuadMesh; @@ -16,15 +16,15 @@ final class MeshHelper { private MeshHelper() { } - public static SimpleQuadMesh blockVerticesToMesh(BufferBuilder.RenderedBuffer buffer, @Nullable String meshDescriptor) { - BufferBuilder.DrawState drawState = buffer.drawState(); + public static SimpleQuadMesh blockVerticesToMesh(MeshData data, @Nullable String meshDescriptor) { + MeshData.DrawState drawState = data.drawState(); int vertexCount = drawState.vertexCount(); long srcStride = drawState.format().getVertexSize(); VertexView vertexView = new NoOverlayVertexView(); long dstStride = vertexView.stride(); - ByteBuffer src = buffer.vertexBuffer(); + ByteBuffer src = data.vertexBuffer(); MemoryBlock dst = MemoryBlock.mallocTracked((long) vertexCount * dstStride); long srcPtr = MemoryUtil.memAddress(src); long dstPtr = dst.ptr(); diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MultiBlockModelBuilder.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MultiBlockModelBuilder.java index 5a495263e..2e99a6c77 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MultiBlockModelBuilder.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MultiBlockModelBuilder.java @@ -2,20 +2,19 @@ import java.util.function.BiFunction; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import com.mojang.blaze3d.vertex.PoseStack; import dev.engine_room.flywheel.api.material.Material; import dev.engine_room.flywheel.lib.internal.FlwLibXplat; +import dev.engine_room.flywheel.lib.model.ModelUtil; import dev.engine_room.flywheel.lib.model.SimpleModel; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; -@ApiStatus.NonExtendable -public abstract class MultiBlockModelBuilder { +public final class MultiBlockModelBuilder { final BlockAndTintGetter level; final Iterable positions; @Nullable @@ -24,15 +23,11 @@ public abstract class MultiBlockModelBuilder { @Nullable BiFunction materialFunc; - MultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { + public MultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { this.level = level; this.positions = positions; } - public static MultiBlockModelBuilder create(BlockAndTintGetter level, Iterable positions) { - return FlwLibXplat.INSTANCE.createMultiBlockModelBuilder(level, positions); - } - public MultiBlockModelBuilder poseStack(PoseStack poseStack) { this.poseStack = poseStack; return this; @@ -48,5 +43,11 @@ public MultiBlockModelBuilder materialFunc(BiFunction capacity) { + data = data.realloc(capacity * 2); } + + filledTexture = false; + filledNormal = false; + + long ptr = vertexPtr(); + MemoryUtil.memPutFloat(ptr, x); + MemoryUtil.memPutFloat(ptr + 4, y); + MemoryUtil.memPutFloat(ptr + 8, z); return this; } @Override - public VertexConsumer color(int red, int green, int blue, int alpha) { + public VertexConsumer setColor(int red, int green, int blue, int alpha) { // ignore color return this; } @Override - public VertexConsumer uv(float u, float v) { + public VertexConsumer setUv(float u, float v) { if (!filledTexture) { long ptr = vertexPtr(); MemoryUtil.memPutFloat(ptr + 12, u); @@ -52,19 +60,19 @@ public VertexConsumer uv(float u, float v) { } @Override - public VertexConsumer overlayCoords(int u, int v) { + public VertexConsumer setUv1(int u, int v) { // ignore overlay return this; } @Override - public VertexConsumer uv2(int u, int v) { + public VertexConsumer setUv2(int u, int v) { // ignore light return this; } @Override - public VertexConsumer normal(float x, float y, float z) { + public VertexConsumer setNormal(float x, float y, float z) { if (!filledNormal) { long ptr = vertexPtr(); MemoryUtil.memPutByte(ptr + 20, DataPacker.packNormI8(x)); @@ -75,44 +83,27 @@ public VertexConsumer normal(float x, float y, float z) { return this; } - @Override - public void endVertex() { - if (!filledPosition || !filledTexture || !filledNormal) { - throw new IllegalStateException("Not filled all elements of the vertex"); - } - - filledPosition = false; - filledTexture = false; - filledNormal = false; - vertexCount++; - - long byteSize = (vertexCount + 1) * STRIDE; - long capacity = data.size(); - if (byteSize > capacity) { - data = data.realloc(capacity * 2); - } - } - - @Override - public void defaultColor(int red, int green, int blue, int alpha) { - } - - @Override - public void unsetDefaultColor() { + private long vertexPtr() { + return data.ptr() + (vertexCount - 1) * STRIDE; } - private long vertexPtr() { - return data.ptr() + vertexCount * STRIDE; + private void endLastVertex() { + if (vertexCount != 0) { + if (!filledTexture || !filledNormal) { + throw new IllegalStateException("Missing elements in vertex"); + } + } } public MemoryBlock copyDataAndReset() { + endLastVertex(); + MemoryBlock dataCopy = MemoryBlock.mallocTracked(vertexCount * STRIDE); data.copyTo(dataCopy); vertexCount = 0; - filledPosition = false; - filledTexture = false; - filledNormal = false; + filledTexture = true; + filledNormal = true; return dataCopy; } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java index 8aca2b9be..0c45179f1 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceUtil.java @@ -16,7 +16,7 @@ private ResourceUtil() { } /** - * Same as {@link ResourceLocation#ResourceLocation(String)}, but defaults to Flywheel namespace. + * Same as {@link ResourceLocation#parse(String)}, but defaults to Flywheel namespace. */ public static ResourceLocation parseFlywheelDefault(String location) { String namespace = Flywheel.ID; @@ -30,7 +30,7 @@ public static ResourceLocation parseFlywheelDefault(String location) { } } - return new ResourceLocation(namespace, path); + return ResourceLocation.fromNamespaceAndPath(namespace, path); } /** diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/VertexTransformations.java b/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/VertexTransformations.java index bf06084a2..0267c7141 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/VertexTransformations.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/vertex/VertexTransformations.java @@ -8,8 +8,8 @@ private VertexTransformations() { } public static void retexture(MutableVertexList vertexList, int index, TextureAtlasSprite sprite) { - vertexList.u(index, sprite.getU(vertexList.u(index) * 16)); - vertexList.v(index, sprite.getV(vertexList.v(index) * 16)); + vertexList.u(index, sprite.getU(vertexList.u(index))); + vertexList.v(index, sprite.getV(vertexList.v(index))); } public static void retexture(MutableVertexList vertexList, TextureAtlasSprite sprite) { diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/ShadowComponent.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/ShadowComponent.java index 65a2d8dcd..0f8d0a97d 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/ShadowComponent.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/ShadowComponent.java @@ -42,7 +42,7 @@ * The shadow will be cast on blocks at most {@code min(radius, 2 * strength)} blocks below the entity.

*/ public final class ShadowComponent implements EntityComponent { - private static final ResourceLocation SHADOW_TEXTURE = new ResourceLocation("textures/misc/shadow.png"); + private static final ResourceLocation SHADOW_TEXTURE = ResourceLocation.withDefaultNamespace("textures/misc/shadow.png"); private static final Material SHADOW_MATERIAL = SimpleMaterial.builder() .texture(SHADOW_TEXTURE) .mipmap(false) diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplat.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplat.java index c8fb9fec1..898f8791d 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplat.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplat.java @@ -13,8 +13,4 @@ public interface FlwImplXplat { String getVersionStr(); FlwConfig getConfig(); - - boolean useSodium0_6Compat(); - - boolean useIrisCompat(); } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwLibLinkImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwLibLinkImpl.java index 1b1e19c2e..10244b19c 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwLibLinkImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwLibLinkImpl.java @@ -34,8 +34,8 @@ public Map getModelPartChildren(ModelPart part) { } @Override - public void compileModelPart(ModelPart part, PoseStack.Pose pose, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha) { - ((ModelPartAccessor) (Object) part).flywheel$compile(pose, consumer, light, overlay, red, green, blue, alpha); + public void compileModelPart(ModelPart part, PoseStack.Pose pose, VertexConsumer consumer, int light, int overlay, int color) { + ((ModelPartAccessor) (Object) part).flywheel$compile(pose, consumer, light, overlay, color); } @Override diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMod.java b/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMod.java index 725208bfa..8217cb963 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMod.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/compat/CompatMod.java @@ -5,7 +5,6 @@ public enum CompatMod { EMBEDDIUM("embeddium"), IRIS("iris"), - OCULUS("oculus"), SODIUM("sodium"); public final String id; diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/compat/IrisCompat.java b/common/src/main/java/dev/engine_room/flywheel/impl/compat/IrisCompat.java index 97fc5f5e5..7f6500536 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/compat/IrisCompat.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/compat/IrisCompat.java @@ -1,11 +1,10 @@ package dev.engine_room.flywheel.impl.compat; import dev.engine_room.flywheel.impl.FlwImpl; -import dev.engine_room.flywheel.impl.FlwImplXplat; import net.irisshaders.iris.api.v0.IrisApi; public final class IrisCompat { - public static final boolean ACTIVE = FlwImplXplat.INSTANCE.useIrisCompat(); + public static final boolean ACTIVE = CompatMod.IRIS.isLoaded; static { if (ACTIVE) { diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java b/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java index 76fa1d499..130272c43 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/compat/SodiumCompat.java @@ -4,7 +4,6 @@ import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer; import dev.engine_room.flywheel.impl.FlwImpl; -import dev.engine_room.flywheel.impl.FlwImplXplat; import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderHandler; import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderPredicate; @@ -12,11 +11,11 @@ import net.minecraft.world.level.block.entity.BlockEntityType; public final class SodiumCompat { - public static final boolean USE_0_6_COMPAT = FlwImplXplat.INSTANCE.useSodium0_6Compat(); + public static final boolean ACTIVE = CompatMod.SODIUM.isLoaded; static { - if (USE_0_6_COMPAT) { - FlwImpl.LOGGER.debug("Detected Sodium 0.6"); + if (ACTIVE) { + FlwImpl.LOGGER.debug("Detected Sodium"); } } @@ -25,7 +24,7 @@ private SodiumCompat() { @Nullable public static Object onSetBlockEntityVisualizer(BlockEntityType type, @Nullable BlockEntityVisualizer oldVisualizer, @Nullable BlockEntityVisualizer newVisualizer, @Nullable Object predicate) { - if (!USE_0_6_COMPAT) { + if (!ACTIVE) { return null; } @@ -49,7 +48,7 @@ public static Object onSetBlockEntityVisualizer(BlockEnt private static final class Internals { static Object addPredicate(BlockEntityType type) { - BlockEntityRenderPredicate predicate = (getter, pos, be) -> VisualizationHelper.tryAddBlockEntity(be); + BlockEntityRenderPredicate predicate = (getter, pos, be) -> !VisualizationHelper.tryAddBlockEntity(be); BlockEntityRenderHandler.instance().addRenderPredicate(type, predicate); return predicate; } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java index 1ee538a73..bf8e7c0c5 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java @@ -3,22 +3,19 @@ import org.joml.Matrix4f; import org.joml.Matrix4fc; -import com.mojang.blaze3d.vertex.PoseStack; - import dev.engine_room.flywheel.api.RenderContext; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; -public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, +public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, Matrix4fc modelView, Matrix4fc projection, Matrix4fc viewProjection, Camera camera, float partialTick) implements RenderContext { - public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) { + public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, Matrix4fc modelView, Matrix4f projection, Camera camera, float partialTick) { Matrix4f viewProjection = new Matrix4f(projection); - viewProjection.mul(stack.last() - .pose()); + viewProjection.mul(modelView); - return new RenderContextImpl(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); + return new RenderContextImpl(renderer, level, buffers, modelView, projection, viewProjection, camera, partialTick); } } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java index a3e178fac..c429dae95 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/BlockEntityTypeMixin.java @@ -28,7 +28,7 @@ abstract class BlockEntityTypeMixin implements BlockEntit @Override public void flywheel$setVisualizer(@Nullable BlockEntityVisualizer visualizer) { - if (SodiumCompat.USE_0_6_COMPAT) { + if (SodiumCompat.ACTIVE) { flywheel$sodiumPredicate = SodiumCompat.onSetBlockEntityVisualizer((BlockEntityType) (Object) this, flywheel$visualizer, visualizer, flywheel$sodiumPredicate); } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java index c7714b228..6e652343f 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java @@ -22,6 +22,7 @@ import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; @@ -51,8 +52,8 @@ abstract class LevelRendererMixin { // @Inject(method = "renderLevel", at = @At("HEAD")) @Inject(method = "renderLevel", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I")) - private void flywheel$beginRender(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) { - flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, poseStack, projectionMatrix, camera, partialTick); + private void flywheel$beginRender(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f modelMatrix, Matrix4f projectionMatrix, CallbackInfo ci) { + flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, modelMatrix, projectionMatrix, camera, deltaTracker.getGameTimeDeltaPartialTick(false)); VisualizationManager manager = VisualizationManager.get(level); if (manager != null) { @@ -102,8 +103,8 @@ abstract class LevelRendererMixin { } } - @Group(name = "afterParticles", min = 2, max = 2) - @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;F)V", shift = Shift.AFTER)) + @Group(name = "afterParticles", min = 2, max = 3) + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V", shift = Shift.AFTER)) private void flywheel$afterParticles$fabric(CallbackInfo ci) { if (flywheel$renderContext != null) { VisualizationManager manager = VisualizationManager.get(level); @@ -114,8 +115,8 @@ abstract class LevelRendererMixin { } @Group(name = "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$afterParticles$forge(CallbackInfo ci) { + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V", shift = Shift.AFTER)) + private void flywheel$afterParticles$neoforge(CallbackInfo ci) { if (flywheel$renderContext != null) { VisualizationManager manager = VisualizationManager.get(level); if (manager != null) { diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/ModelPartAccessor.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/ModelPartAccessor.java index 274e7a829..3beb76388 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/ModelPartAccessor.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/ModelPartAccessor.java @@ -17,5 +17,5 @@ public interface ModelPartAccessor { Map flywheel$children(); @Invoker("compile") - void flywheel$compile(PoseStack.Pose pose, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha); + void flywheel$compile(PoseStack.Pose pose, VertexConsumer buffer, int packedLight, int packedOverlay, int color); } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/fix/FixNormalScalingMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/fix/FixNormalScalingMixin.java deleted file mode 100644 index f6a9ca887..000000000 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/fix/FixNormalScalingMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.fix; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.At.Shift; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.mojang.blaze3d.vertex.PoseStack; - -@Mixin(PoseStack.class) -abstract class FixNormalScalingMixin { - /** - * Minecraft negates the normal matrix if all scales are equal and negative, but - * does not return afterward. This allows the rest of the method's logic to be - * applied, which negates the matrix again, resulting in the matrix being the - * same as in the beginning. - */ - @Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix3f;scale(F)Lorg/joml/Matrix3f;", shift = Shift.AFTER, remap = false), cancellable = true) - private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) { - ci.cancel(); - } - - /** - * Minecraft takes the inverse cube root of the product of all scales to provide a - * rough estimate for normalization so that it does not need to be done later. It - * does not make sense for this "normalization factor" to be negative though, as - * that would invert all normals. Additionally, Minecraft's fastInvCubeRoot method - * does not work for negative numbers. - */ - @ModifyArg(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;fastInvCubeRoot(F)F")) - private float flywheel$absInvCbrtInput(float input) { - return Math.abs(input); - } -} diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/SectionCompilerMixin.java similarity index 64% rename from common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java rename to common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/SectionCompilerMixin.java index 89546e170..c81c9c130 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/visualmanage/SectionCompilerMixin.java @@ -7,11 +7,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; +import net.minecraft.client.renderer.chunk.SectionCompiler; import net.minecraft.world.level.block.entity.BlockEntity; -@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$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) +@Mixin(SectionCompiler.class) +abstract class SectionCompilerMixin { + @Inject(method = "handleBlockEntity", 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/common/src/main/java/dev/engine_room/flywheel/vanilla/MinecartVisual.java b/common/src/main/java/dev/engine_room/flywheel/vanilla/MinecartVisual.java index b3c90cdef..2805fe7c1 100644 --- a/common/src/main/java/dev/engine_room/flywheel/vanilla/MinecartVisual.java +++ b/common/src/main/java/dev/engine_room/flywheel/vanilla/MinecartVisual.java @@ -30,7 +30,7 @@ import net.minecraft.world.phys.Vec3; public class MinecartVisual extends ComponentEntityVisual implements SimpleTickableVisual, SimpleDynamicVisual { - private static final ResourceLocation TEXTURE = new ResourceLocation("textures/entity/minecart.png"); + private static final ResourceLocation TEXTURE = ResourceLocation.withDefaultNamespace("textures/entity/minecart.png"); private static final Material MATERIAL = SimpleMaterial.builder() .texture(TEXTURE) .mipmap(false) diff --git a/common/src/main/resources/flywheel.impl.mixins.json b/common/src/main/resources/flywheel.impl.mixins.json index a1953a127..9b576d52d 100644 --- a/common/src/main/resources/flywheel.impl.mixins.json +++ b/common/src/main/resources/flywheel.impl.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "dev.engine_room.flywheel.impl.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "flywheel.refmap.json", "client": [ "BlockEntityTypeMixin", @@ -15,11 +15,10 @@ "PoseStackAccessor", "PoseStackMixin", "fix.FixFabulousDepthMixin", - "fix.FixNormalScalingMixin", "visualmanage.BlockEntityMixin", "visualmanage.LevelChunkMixin", "visualmanage.LevelRendererMixin", - "visualmanage.RebuildTaskMixin" + "visualmanage.SectionCompilerMixin" ], "injectors": { "defaultRequire": 1 diff --git a/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderHandler.java b/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderHandler.java deleted file mode 100644 index 5c4a588d7..000000000 --- a/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -// https://github.com/CaffeineMC/sodium-fabric/blob/e7643f4544f61180ed2f0ff4952d7daa2c1feaf4/common/src/api/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderHandler.java -// PolyForm Shield License 1.0.0 - -package net.caffeinemc.mods.sodium.api.blockentity; - -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Experimental -@ApiStatus.AvailableSince("0.6.0") -public interface BlockEntityRenderHandler { - BlockEntityRenderHandler INSTANCE = null; - - static BlockEntityRenderHandler instance() { - return INSTANCE; - } - - /** - * Adds a predicate to determine if a block entity should be rendered. - * - *

Upon chunk bake, block entities of the given type will have {@code shouldRender} evaluated. - *
If all predicates returns {@code true} (and the block entity has a renderer), the block entity will be - * added to the chunk for future rendering.

- * @param type The block entity type to associate the given predicate with. - * @param shouldRender The predicate for the block entity to evaluate. - */ - void addRenderPredicate(BlockEntityType type, BlockEntityRenderPredicate shouldRender); - - /** - * Removes a predicate added by {@code addRenderPredicate}. It must be the same object that was added. - * - * @param type The block entity type to associate the given predicate with. - * @param shouldRender The predicate to remove. - * @return If the predicate existed and was removed. - */ - boolean removeRenderPredicate(BlockEntityType type, BlockEntityRenderPredicate shouldRender); -} diff --git a/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderPredicate.java b/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderPredicate.java deleted file mode 100644 index 8734005f2..000000000 --- a/common/src/stubs/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderPredicate.java +++ /dev/null @@ -1,16 +0,0 @@ -// https://github.com/CaffeineMC/sodium-fabric/blob/e7643f4544f61180ed2f0ff4952d7daa2c1feaf4/common/src/api/java/net/caffeinemc/mods/sodium/api/blockentity/BlockEntityRenderPredicate.java -// PolyForm Shield License 1.0.0 - -package net.caffeinemc.mods.sodium.api.blockentity; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.entity.BlockEntity; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Experimental -@ApiStatus.AvailableSince("0.6.0") -@FunctionalInterface -public interface BlockEntityRenderPredicate { - boolean shouldRender(BlockGetter blockGetter, BlockPos blockPos, T entity); -} diff --git a/common/src/stubs/java/net/irisshaders/iris/api/v0/IrisApi.java b/common/src/stubs/java/net/irisshaders/iris/api/v0/IrisApi.java deleted file mode 100644 index 571667e1c..000000000 --- a/common/src/stubs/java/net/irisshaders/iris/api/v0/IrisApi.java +++ /dev/null @@ -1,114 +0,0 @@ -// https://github.com/IrisShaders/Iris/blob/20be7fc1ff8a48048cb4eb787e1299782bb1caa4/src/main/java/net/irisshaders/iris/api/v0/IrisApi.java -// GNU Lesser General Public License v3.0 - -package net.irisshaders.iris.api.v0; - -/** - * The entry point to the Iris API, major version 0. This is currently the latest - * version of the API. - * - * To access the API, use {@link #getInstance()}. - */ -public interface IrisApi { - /** - * @since API v0.0 - */ - static IrisApi getInstance() { - return null; - } - - /** - * Gets the minor revision of this API. This is incremented when - * new methods are added without breaking API. Mods can check this - * if they wish to check whether given API calls are available on - * the currently installed Iris version. - * - * @return The current minor revision. Currently, revision 2. - */ - int getMinorApiRevision(); - - /** - * Checks whether a shader pack is currently in use and being used - * for rendering. If there is no shader pack enabled or a shader - * pack failed to compile and is therefore not in use, this will - * return false. - * - *

Mods that need to enable custom workarounds for shaders - * should use this method. - * - * @return Whether shaders are being used for rendering. - * @since {@link #getMinorApiRevision() API v0.0} - */ - boolean isShaderPackInUse(); - - /** - * Checks whether the shadow pass is currently being rendered. - * - *

Generally, mods won't need to call this function for much. - * Mods should be fine with things being rendered multiple times - * each frame from different camera perspectives. Often, there's - * a better approach to fixing bugs than calling this function. - * - *

Pretty much the main legitimate use for this function that - * I've seen is in a mod like Immersive Portals, where it has - * very custom culling that doesn't work when the Iris shadow - * pass is active. - * - *

Naturally, this function can only return true if - * {@link #isShaderPackInUse()} returns true. - * - * @return Whether Iris is currently rendering the shadow pass. - * @since API v0.0 - */ - boolean isRenderingShadowPass(); - - /** - * Opens the main Iris GUI screen. It's up to Iris to decide - * what this screen is, but generally this is the shader selection - * screen. - * - * This method takes and returns Objects instead of any concrete - * Minecraft screen class to avoid referencing Minecraft classes. - * Nevertheless, the passed parent must either be null, or an - * object that is a subclass of the appropriate {@code Screen} - * class for the given Minecraft version. - * - * @param parent The parent screen, an instance of the appropriate - * {@code Screen} class. - * @return A {@code Screen} class for the main Iris GUI screen. - * @since API v0.0 - */ - Object openMainIrisScreenObj(Object parent); - - /** - * Gets the language key of the main screen. Currently, this - * is "options.iris.shaderPackSelection". - * - * @return the language key, for use with {@code TranslatableText} - * / {@code TranslatableComponent} - * @since API v0.0 - */ - String getMainScreenLanguageKey(); - -// /** -// * Gets a config object that can edit the Iris configuration. -// * @since API v0.0 -// */ -// IrisApiConfig getConfig(); - -// /** -// * Gets a text vertex sink to render into. -// * @param maxQuadCount Maximum amount of quads that will be rendered with this sink -// * @param bufferProvider An IntFunction that can provide a {@code ByteBuffer} with at minimum the bytes provided by the input parameter -// * @since API 0.1 -// */ -// IrisTextVertexSink createTextVertexSink(int maxQuadCount, IntFunction bufferProvider); - - /** - * Gets the sun path rotation used by the current shader pack. - * - * @return The sun path rotation as specified by the shader pack, or 0 if no shader pack is in use. - * @since API v0.2 - */ - float getSunPathRotation(); -} diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index b1b04dad8..acba756a2 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -10,7 +10,6 @@ plugins { val api = sourceSets.create("api") val lib = sourceSets.create("lib") val backend = sourceSets.create("backend") -val stubs = sourceSets.create("stubs") val main = sourceSets.getByName("main") val testMod = sourceSets.create("testMod") @@ -28,12 +27,7 @@ transitiveSourceSets { rootCompile() compile(api, lib) } - sourceSet(stubs) { - rootCompile() - } sourceSet(main) { - // Don't want stubs at runtime - compile(stubs) implementation(api, lib, backend) } sourceSet(testMod) { @@ -45,7 +39,7 @@ transitiveSourceSets { platform { commonProject = project(":common") - compileWithCommonSourceSets(api, lib, backend, stubs, main) + compileWithCommonSourceSets(api, lib, backend, main) setupLoomMod(api, lib, backend, main) setupLoomRuns() setupFatJar(api, lib, backend, main) @@ -82,11 +76,11 @@ dependencies { modImplementation("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") modApi("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}") - modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}") + modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-fabric") + modCompileOnly("maven.modrinth:iris:${property("iris_version")}-fabric") "forApi"(project(path = ":common", configuration = "commonApiOnly")) "forLib"(project(path = ":common", configuration = "commonLib")) "forBackend"(project(path = ":common", configuration = "commonBackend")) - "forStubs"(project(path = ":common", configuration = "commonStubs")) "forMain"(project(path = ":common", configuration = "commonImpl")) } diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java index 23c63a041..f6c6aa58b 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; +import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap; @@ -140,7 +140,7 @@ public static void bufferMultiBlock(BlockRenderDispatcher renderDispatcher, Iter } public interface ResultConsumer { - void accept(RenderType renderType, boolean shaded, RenderedBuffer data); + void accept(RenderType renderType, boolean shaded, MeshData data); } private static class ThreadLocalObjects { diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java deleted file mode 100644 index 9f90ba87e..000000000 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java +++ /dev/null @@ -1,64 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; - -public final class FabricBakedModelBuilder extends BakedModelBuilder { - public FabricBakedModelBuilder(BakedModel bakedModel) { - super(bakedModel); - } - - @Override - public FabricBakedModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public FabricBakedModelBuilder blockState(BlockState blockState) { - super.blockState(blockState); - return this; - } - - @Override - public FabricBakedModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public FabricBakedModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java deleted file mode 100644 index 58eae7b7d..000000000 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; - -public final class FabricBlockModelBuilder extends BlockModelBuilder { - public FabricBlockModelBuilder(BlockState state) { - super(state); - } - - @Override - public FabricBlockModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public FabricBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public FabricBlockModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java deleted file mode 100644 index 1420895eb..000000000 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; - -public final class FabricMultiBlockModelBuilder extends MultiBlockModelBuilder { - public FabricMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - super(level, positions); - } - - @Override - public FabricMultiBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public FabricMultiBlockModelBuilder enableFluidRendering() { - super.enableFluidRendering(); - return this; - } - - @Override - public FabricMultiBlockModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, renderFluids, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java index 268a6e1da..f981c3e03 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.UnknownNullability; import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.ByteBufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; @@ -10,14 +11,16 @@ class MeshEmitter { private final RenderType renderType; - private final BufferBuilder bufferBuilder; + private final ByteBufferBuilder byteBufferBuilder; + @UnknownNullability + private BufferBuilder bufferBuilder; private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer; private boolean currentShade; MeshEmitter(RenderType renderType) { this.renderType = renderType; - this.bufferBuilder = new BufferBuilder(renderType.bufferSize()); + this.byteBufferBuilder = new ByteBufferBuilder(renderType.bufferSize()); } public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { @@ -25,7 +28,7 @@ public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { } public void end() { - if (bufferBuilder.building()) { + if (bufferBuilder != null) { emit(); } resultConsumer = null; @@ -36,23 +39,24 @@ public BufferBuilder getBuffer(boolean shade) { return bufferBuilder; } - void prepareForGeometry(boolean shade) { - if (!bufferBuilder.building()) { - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + private void prepareForGeometry(boolean shade) { + if (bufferBuilder == null) { + bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } else if (shade != currentShade) { emit(); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } currentShade = shade; } - void emit() { - var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty(); + private void emit() { + var data = bufferBuilder.build(); + bufferBuilder = null; - if (renderedBuffer != null) { - resultConsumer.accept(renderType, currentShade, renderedBuffer); - renderedBuffer.release(); + if (data != null) { + resultConsumer.accept(renderType, currentShade, data); + data.close(); } } } diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java new file mode 100644 index 000000000..a3fba8e12 --- /dev/null +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java @@ -0,0 +1,57 @@ +package dev.engine_room.flywheel.lib.model.baked; + +import org.jetbrains.annotations.ApiStatus; + +import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; +import dev.engine_room.flywheel.api.model.Model; +import dev.engine_room.flywheel.lib.model.ModelUtil; +import dev.engine_room.flywheel.lib.model.SimpleModel; + +@ApiStatus.Internal +public final class ModelBuilderImpl { + private ModelBuilderImpl() { + } + + public static SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), builder.level, builder.bakedModel, builder.blockState, builder.poseStack, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + builder.bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } + + public static SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, builder.level, builder.state, builder.poseStack, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + builder.state + ",renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } + + public static SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, builder.positions.iterator(), builder.level, builder.poseStack, builder.renderFluids, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } +} diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/UniversalMeshEmitter.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/UniversalMeshEmitter.java index feb560bcc..5547b4791 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/UniversalMeshEmitter.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/UniversalMeshEmitter.java @@ -56,69 +56,54 @@ private void prepareForGeometry(RenderMaterial material) { } @Override - public VertexConsumer vertex(double x, double y, double z) { - currentDelegate.vertex(x, y, z); + public VertexConsumer addVertex(float x, float y, float z) { + currentDelegate.addVertex(x, y, z); return this; } @Override - public VertexConsumer color(int red, int green, int blue, int alpha) { - currentDelegate.color(red, green, blue, alpha); + public VertexConsumer setColor(int red, int green, int blue, int alpha) { + currentDelegate.setColor(red, green, blue, alpha); return this; } @Override - public VertexConsumer uv(float u, float v) { - currentDelegate.uv(u, v); + public VertexConsumer setUv(float u, float v) { + currentDelegate.setUv(u, v); return this; } @Override - public VertexConsumer overlayCoords(int u, int v) { - currentDelegate.overlayCoords(u, v); + public VertexConsumer setUv1(int u, int v) { + currentDelegate.setUv1(u, v); return this; } @Override - public VertexConsumer uv2(int u, int v) { - currentDelegate.uv2(u, v); + public VertexConsumer setUv2(int u, int v) { + currentDelegate.setUv2(u, v); return this; } @Override - public VertexConsumer normal(float x, float y, float z) { - currentDelegate.normal(x, y, z); + public VertexConsumer setNormal(float x, float y, float z) { + currentDelegate.setNormal(x, y, z); return this; } @Override - public void endVertex() { - currentDelegate.endVertex(); + public void addVertex(float x, float y, float z, int color, float u, float v, int packedOverlay, int packedLight, float normalX, float normalY, float normalZ) { + currentDelegate.addVertex(x, y, z, color, u, v, packedOverlay, packedLight, normalX, normalY, normalZ); } @Override - public void defaultColor(int red, int green, int blue, int alpha) { - currentDelegate.defaultColor(red, green, blue, alpha); + public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, float alpha, int packedLight, int packedOverlay) { + currentDelegate.putBulkData(pose, quad, red, green, blue, alpha, packedLight, packedOverlay); } @Override - public void unsetDefaultColor() { - currentDelegate.unsetDefaultColor(); - } - - @Override - public void vertex(float x, float y, float z, float red, float green, float blue, float alpha, float u, float v, int overlay, int light, float normalX, float normalY, float normalZ) { - currentDelegate.vertex(x, y, z, red, green, blue, alpha, u, v, overlay, light, normalX, normalY, normalZ); - } - - @Override - public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, int light, int overlay) { - currentDelegate.putBulkData(pose, quad, red, green, blue, light, overlay); - } - - @Override - public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float[] brightnesses, float red, float green, float blue, int[] lights, int overlay, boolean readExistingColor) { - currentDelegate.putBulkData(pose, quad, brightnesses, red, green, blue, lights, overlay, readExistingColor); + public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float[] brightness, float red, float green, float blue, float alpha, int[] lightmap, int packedOverlay, boolean readAlpha) { + currentDelegate.putBulkData(pose, quad, brightness, red, green, blue, alpha, lightmap, packedOverlay, readAlpha); } private class WrapperModel extends ForwardingBakedModel { diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java index 6027df0a4..8941c8b68 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java @@ -110,7 +110,7 @@ private void readBackend(JsonObject object) { if (backendJson instanceof JsonPrimitive primitive && primitive.isString()) { var value = primitive.getAsString(); try { - this.backend = Backend.REGISTRY.getOrThrow(new ResourceLocation(value)); + this.backend = Backend.REGISTRY.getOrThrow(ResourceLocation.parse(value)); return; } catch (ResourceLocationException e) { msg = "'backend' value '" + value + "' is not a valid resource location"; diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java index d1c346906..65225906f 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java @@ -1,8 +1,6 @@ package dev.engine_room.flywheel.impl; import dev.engine_room.flywheel.api.event.ReloadLevelRendererCallback; -import dev.engine_room.flywheel.impl.compat.CompatMod; -import dev.engine_room.flywheel.impl.compat.FabricSodiumCompat; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.multiplayer.ClientLevel; @@ -26,14 +24,4 @@ public String getVersionStr() { public FlwConfig getConfig() { return FabricFlwConfig.INSTANCE; } - - @Override - public boolean useSodium0_6Compat() { - return FabricSodiumCompat.USE_0_6_COMPAT; - } - - @Override - public boolean useIrisCompat() { - return CompatMod.IRIS.isLoaded; - } } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java index 13b13505a..43882a8b8 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java @@ -3,20 +3,16 @@ import org.jetbrains.annotations.UnknownNullability; import dev.engine_room.flywheel.lib.internal.FlwLibXplat; +import dev.engine_room.flywheel.lib.model.SimpleModel; import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder; import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.FabricBakedModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.FabricBlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.FabricMultiBlockModelBuilder; +import dev.engine_room.flywheel.lib.model.baked.ModelBuilderImpl; import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelManager; -import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; public class FlwLibXplatImpl implements FlwLibXplat { @Override @@ -31,17 +27,17 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { } @Override - public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) { - return new FabricBakedModelBuilder(bakedModel); + public SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) { + return ModelBuilderImpl.buildBakedModelBuilder(builder); } @Override - public BlockModelBuilder createBlockModelBuilder(BlockState state) { - return new FabricBlockModelBuilder(state); + public SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) { + return ModelBuilderImpl.buildBlockModelBuilder(builder); } @Override - public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - return new FabricMultiBlockModelBuilder(level, positions); + public SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) { + return ModelBuilderImpl.buildMultiBlockModelBuilder(builder); } } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/compat/FabricSodiumCompat.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/compat/FabricSodiumCompat.java deleted file mode 100644 index 4a6ee1da4..000000000 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/compat/FabricSodiumCompat.java +++ /dev/null @@ -1,48 +0,0 @@ -package dev.engine_room.flywheel.impl.compat; - -import java.util.Optional; - -import dev.engine_room.flywheel.impl.FlwImpl; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.Version; -import net.fabricmc.loader.api.VersionParsingException; -import net.fabricmc.loader.api.metadata.version.VersionPredicate; - -public final class FabricSodiumCompat { - public static final boolean USE_0_5_COMPAT; - public static final boolean USE_0_6_COMPAT; - - static { - boolean use0_5Compat = false; - boolean use0_6Compat = false; - - Optional optionalModContainer = FabricLoader.getInstance().getModContainer(CompatMod.SODIUM.id); - - if (optionalModContainer.isPresent()) { - ModContainer modContainer = optionalModContainer.get(); - Version sodiumVersion = modContainer.getMetadata().getVersion(); - - try { - VersionPredicate predicate0_5 = VersionPredicate.parse("~0.5.0"); - VersionPredicate predicate0_6 = VersionPredicate.parse(">=0.6.0-beta.2"); - use0_5Compat = predicate0_5.test(sodiumVersion); - use0_6Compat = predicate0_6.test(sodiumVersion); - } catch (VersionParsingException e) { - FlwImpl.LOGGER.debug("Failed to parse Sodium version predicates", e); - } - } - - USE_0_5_COMPAT = use0_5Compat; - USE_0_6_COMPAT = use0_6Compat; - } - - static { - if (USE_0_5_COMPAT) { - FlwImpl.LOGGER.debug("Detected Sodium 0.5"); - } - } - - private FabricSodiumCompat() { - } -} diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java index f96a68595..dcab8eeec 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java +++ b/fabric/src/main/java/dev/engine_room/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; @@ -30,14 +31,14 @@ abstract class MinecraftMixin { FabricFlwConfig.INSTANCE.load(); } - @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/dev/engine_room/flywheel/impl/mixin/fabric/MinecraftMixin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/fabric/MinecraftMixin.java index e7d8b7af2..f87736ad1 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/fabric/MinecraftMixin.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/fabric/MinecraftMixin.java @@ -15,15 +15,15 @@ abstract class MinecraftMixin { @Shadow public ClientLevel level; - @Inject(method = "setLevel(Lnet/minecraft/client/multiplayer/ClientLevel;)V", at = @At("HEAD")) + @Inject(method = "setLevel(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/client/gui/screens/ReceivingLevelScreen$Reason;)V", at = @At("HEAD")) private void flywheel$onSetLevel(CallbackInfo ci) { if (level != null) { LevelAttached.invalidateLevel(level); } } - @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) - private void flywheel$onClearLevel(CallbackInfo ci) { + @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + private void flywheel$onDisconnect(CallbackInfo ci) { if (level != null) { LevelAttached.invalidateLevel(level); } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java deleted file mode 100644 index 18b7772de..000000000 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; - -import dev.engine_room.flywheel.lib.visualization.VisualizationHelper; -import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.world.level.block.entity.BlockEntity; - -@Mixin(value = ChunkBuilderMeshingTask.class, remap = false) -abstract class ChunkBuilderMeshingTaskMixin { - @WrapOperation( - method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;getRenderer(Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderer;", - remap = true - ) - ) - @Nullable - private BlockEntityRenderer flywheel$wrapGetRenderer(BlockEntityRenderDispatcher instance, BlockEntity blockEntity, Operation> original) { - if (VisualizationHelper.tryAddBlockEntity(blockEntity)) { - return null; - } - return original.call(instance, blockEntity); - } -} diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java deleted file mode 100644 index d96386dad..000000000 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java +++ /dev/null @@ -1,46 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin.sodium; - -import java.util.List; -import java.util.Set; - -import org.jetbrains.annotations.Nullable; -import org.objectweb.asm.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import dev.engine_room.flywheel.impl.compat.FabricSodiumCompat; - -public class SodiumMixinPlugin implements IMixinConfigPlugin { - @Override - public void onLoad(String mixinPackage) { - } - - @Override - @Nullable - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return FabricSodiumCompat.USE_0_5_COMPAT; - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - } - - @Override - @Nullable - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - } -} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index d90f772c9..c96e8cf77 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -24,8 +24,7 @@ "mixins": [ "flywheel.backend.mixins.json", "flywheel.impl.mixins.json", - "flywheel.impl.fabric.mixins.json", - "flywheel.impl.sodium.mixins.json" + "flywheel.impl.fabric.mixins.json" ], "depends": { "minecraft": "${minecraft_semver_version_range}", @@ -33,7 +32,6 @@ "fabric-api": "${fabric_api_version_range}" }, "breaks": { - "sodium": ["<0.5.0", "~0.6.0- <0.6.0-beta.2"], - "embeddium": "*" + "sodium": "<0.6.0-beta.2" } } diff --git a/fabric/src/main/resources/flywheel.impl.fabric.mixins.json b/fabric/src/main/resources/flywheel.impl.fabric.mixins.json index ea3900fdd..43d75fb9d 100644 --- a/fabric/src/main/resources/flywheel.impl.fabric.mixins.json +++ b/fabric/src/main/resources/flywheel.impl.fabric.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "dev.engine_room.flywheel.impl.mixin.fabric", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "flywheel.refmap.json", "client": [ "DebugScreenOverlayMixin", diff --git a/fabric/src/main/resources/flywheel.impl.sodium.mixins.json b/fabric/src/main/resources/flywheel.impl.sodium.mixins.json deleted file mode 100644 index 7820cb594..000000000 --- a/fabric/src/main/resources/flywheel.impl.sodium.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "dev.engine_room.flywheel.impl.mixin.sodium", - "compatibilityLevel": "JAVA_17", - "refmap": "flywheel.refmap.json", - "plugin": "dev.engine_room.flywheel.impl.mixin.sodium.SodiumMixinPlugin", - "client": [ - "ChunkBuilderMeshingTaskMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/forge/gradle.properties b/forge/gradle.properties deleted file mode 100644 index a58ba1416..000000000 --- a/forge/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -loom.platform = forge diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java deleted file mode 100644 index b349a32bf..000000000 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBakedModelBuilder.java +++ /dev/null @@ -1,78 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; - -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; - -public final class ForgeBakedModelBuilder extends BakedModelBuilder { - @Nullable - private ModelData modelData; - - public ForgeBakedModelBuilder(BakedModel bakedModel) { - super(bakedModel); - } - - @Override - public ForgeBakedModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public ForgeBakedModelBuilder blockState(BlockState blockState) { - super.blockState(blockState); - return this; - } - - @Override - public ForgeBakedModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public ForgeBakedModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - public ForgeBakedModelBuilder modelData(ModelData modelData) { - this.modelData = modelData; - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - if (modelData == null) { - modelData = ModelData.EMPTY; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, modelData, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java deleted file mode 100644 index 0c0ab4fd0..000000000 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeBlockModelBuilder.java +++ /dev/null @@ -1,71 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; - -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -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 - private ModelData modelData; - - public ForgeBlockModelBuilder(BlockState state) { - super(state); - } - - @Override - public ForgeBlockModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public ForgeBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public ForgeBlockModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - public ForgeBlockModelBuilder modelData(ModelData modelData) { - this.modelData = modelData; - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - if (modelData == null) { - modelData = ModelData.EMPTY; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, modelData, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java b/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java deleted file mode 100644 index 183e03d84..000000000 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ForgeMultiBlockModelBuilder.java +++ /dev/null @@ -1,72 +0,0 @@ -package dev.engine_room.flywheel.lib.model.baked; - -import java.util.function.BiFunction; -import java.util.function.Function; - -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.vertex.PoseStack; - -import dev.engine_room.flywheel.api.material.Material; -import dev.engine_room.flywheel.api.model.Mesh; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.ModelUtil; -import dev.engine_room.flywheel.lib.model.SimpleModel; -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 - private Function modelDataLookup; - - public ForgeMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - super(level, positions); - } - - @Override - public ForgeMultiBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public ForgeMultiBlockModelBuilder enableFluidRendering() { - super.enableFluidRendering(); - return this; - } - - @Override - public ForgeMultiBlockModelBuilder materialFunc(BiFunction materialFunc) { - super.materialFunc(materialFunc); - return this; - } - - public ForgeMultiBlockModelBuilder modelDataLookup(Function modelDataLookup) { - this.modelDataLookup = modelDataLookup; - return this; - } - - @Override - public SimpleModel build() { - if (materialFunc == null) { - materialFunc = ModelUtil::getMaterial; - } - if (modelDataLookup == null) { - modelDataLookup = pos -> ModelData.EMPTY; - } - - var builder = ChunkLayerSortedListBuilder.getThreadLocal(); - - BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, modelDataLookup, renderFluids, (renderType, shaded, data) -> { - Material material = materialFunc.apply(renderType, shaded); - if (material != null) { - Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); - builder.add(renderType, new Model.ConfiguredMesh(material, mesh)); - } - }); - - return new SimpleModel(builder.build()); - } -} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java b/forge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java deleted file mode 100644 index 78e99c9e0..000000000 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package dev.engine_room.flywheel.impl; - -import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; -import dev.engine_room.flywheel.impl.compat.CompatMod; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.loading.LoadingModList; - -public class FlwImplXplatImpl implements FlwImplXplat { - @Override - public boolean isModLoaded(String modId) { - return LoadingModList.get().getModFileById(modId) != null; - } - - @Override - public void dispatchReloadLevelRendererEvent(ClientLevel level) { - MinecraftForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); - } - - @Override - public String getVersionStr() { - return FlywheelForge.version().toString(); - } - - @Override - public FlwConfig getConfig() { - return ForgeFlwConfig.INSTANCE; - } - - @Override - public boolean useSodium0_6Compat() { - return CompatMod.SODIUM.isLoaded && !CompatMod.EMBEDDIUM.isLoaded; - } - - @Override - public boolean useIrisCompat() { - return CompatMod.IRIS.isLoaded || CompatMod.OCULUS.isLoaded; - } -} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java b/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java deleted file mode 100644 index cb8874dab..000000000 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java +++ /dev/null @@ -1,132 +0,0 @@ -package dev.engine_room.flywheel.impl; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.jetbrains.annotations.UnknownNullability; - -import dev.engine_room.flywheel.api.Flywheel; -import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; -import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; -import dev.engine_room.flywheel.backend.compile.FlwProgramsReloader; -import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; -import dev.engine_room.flywheel.impl.compat.EmbeddiumCompat; -import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; -import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; -import dev.engine_room.flywheel.lib.util.LevelAttached; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; -import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; -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.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() { - ModLoadingContext modLoadingContext = ModLoadingContext.get(); - - version = modLoadingContext - .getActiveContainer() - .getModInfo() - .getVersion(); - - IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; - IEventBus modEventBus = FMLJavaModLoadingContext.get() - .getModEventBus(); - - ForgeFlwConfig.INSTANCE.registerSpecs(modLoadingContext); - - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FlywheelForge.clientInit(forgeEventBus, modEventBus)); - } - - private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) { - registerImplEventListeners(forgeEventBus, modEventBus); - registerLibEventListeners(forgeEventBus, modEventBus); - registerBackendEventListeners(forgeEventBus, modEventBus); - - CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString); - FlwImpl.init(); - - EmbeddiumCompat.init(); - } - - private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { - forgeEventBus.addListener((ReloadLevelRendererEvent e) -> BackendManagerImpl.onReloadLevelRenderer(e.level())); - - forgeEventBus.addListener((TickEvent.LevelTickEvent e) -> { - // Make sure we don't tick on the server somehow. - if (e.phase == TickEvent.Phase.END && e.side == LogicalSide.CLIENT) { - VisualizationEventHandler.onClientTick(Minecraft.getInstance(), e.level); - } - }); - forgeEventBus.addListener((EntityJoinLevelEvent e) -> VisualizationEventHandler.onEntityJoinLevel(e.getLevel(), e.getEntity())); - forgeEventBus.addListener((EntityLeaveLevelEvent e) -> VisualizationEventHandler.onEntityLeaveLevel(e.getLevel(), e.getEntity())); - - forgeEventBus.addListener(FlwCommands::registerClientCommands); - - forgeEventBus.addListener((CustomizeGuiOverlayEvent.DebugText e) -> { - Minecraft minecraft = Minecraft.getInstance(); - - if (!minecraft.options.renderDebug) { - return; - } - - FlwDebugInfo.addDebugInfo(minecraft, e.getRight()); - }); - - modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); - - modEventBus.addListener((FMLCommonSetupEvent e) -> { - ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); - ArgumentTypeInfos.registerByClass(DebugModeArgument.class, DebugModeArgument.INFO); - ArgumentTypeInfos.registerByClass(LightSmoothnessArgument.class, LightSmoothnessArgument.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); - e.register(ForgeRegistries.Keys.COMMAND_ARGUMENT_TYPES, Flywheel.rl("light_smoothness"), () -> LightSmoothnessArgument.INFO); - } - }); - } - - private static void registerLibEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { - forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.invalidateLevel(e.getLevel())); - - modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadCache.onEndClientResourceReload()); - modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadHolder.onEndClientResourceReload()); - - modEventBus.addListener(PartialModelEventHandler::onRegisterAdditional); - modEventBus.addListener(PartialModelEventHandler::onBakingCompleted); - } - - private static void registerBackendEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { - forgeEventBus.addListener((ReloadLevelRendererEvent e) -> Uniforms.onReloadLevelRenderer()); - - modEventBus.addListener((RegisterClientReloadListenersEvent e) -> { - e.registerReloadListener(FlwProgramsReloader.INSTANCE); - }); - } - - public static ArtifactVersion version() { - return version; - } -} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java b/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java deleted file mode 100644 index 99ca5d570..000000000 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.engine_room.flywheel.impl.mixin; - -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -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.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.mojang.realmsclient.client.RealmsClient; - -import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; -import dev.engine_room.flywheel.impl.FlwImpl; -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) -abstract class MinecraftMixin { - @Shadow - @Final - private ReloadableResourceManager resourceManager; - - // Inject at invoke cannot be used in constructors in vanilla Mixin, so use ModifyArg instead. - @ModifyArg(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;"), index = 0) - private Executor flywheel$onBeginInitialResourceReload(Executor arg0) { - FlwImpl.freezeRegistries(); - return arg0; - } - - @Inject(method = "lambda$new$5", at = @At("HEAD")) - private void flywheel$onEndInitialResourceReload(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig gameConfig, 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) { - ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error)); - } -} diff --git a/gradle.properties b/gradle.properties index 57a9985e6..04b470b9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,28 +12,30 @@ mod_issues = https://github.com/Engine-Room/Flywheel/issues mod_homepage = https://github.com/Engine-Room/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.21.1 <1.21.2 +minecraft_maven_version_range = [1.21.1,1.21.2) +fabric_api_version_range = >=0.105.0 +neoforge_version_range = [21.1.66,) # General build dependency versions -java_version = 17 +java_version = 21 arch_loom_version = 1.7.412 cursegradle_version = 1.4.0 -parchment_minecraft_version = 1.20.1 -parchment_version = 2023.09.03 +parchment_minecraft_version = 1.21 +parchment_version = 2024.07.07 # 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.21.1 +neoforge_version = 21.1.66 +fabric_loader_version = 0.16.5 +fabric_api_version = 0.105.0+1.21.1 # Build dependency mod versions -sodium_version = mc1.20.1-0.5.11 -embeddium_version = 0.3.25+mc1.20.1 +sodium_version = mc1.21.1-0.6.0-beta.4 +iris_version = 1.8.0-beta.8+1.21.1 +# There is no oculus for 1.21.1 so we will only support iris +embeddium_version = 1.0.11+mc1.21.1 # Publication info group = dev.engine_room.flywheel -artifact_minecraft_version = 1.20.1 +artifact_minecraft_version = 1.21.1 diff --git a/forge/build.gradle.kts b/neoforge/build.gradle.kts similarity index 80% rename from forge/build.gradle.kts rename to neoforge/build.gradle.kts index 6900fd197..9ef36d2f9 100644 --- a/forge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -10,7 +10,6 @@ plugins { val api = sourceSets.create("api") val lib = sourceSets.create("lib") val backend = sourceSets.create("backend") -val stubs = sourceSets.create("stubs") val main = sourceSets.getByName("main") val testMod = sourceSets.create("testMod") @@ -28,11 +27,8 @@ transitiveSourceSets { rootCompile() compile(api, lib) } - sourceSet(stubs) { - rootCompile() - } sourceSet(main) { - compile(api, lib, backend, stubs) + compile(api, lib, backend) } sourceSet(testMod) { rootCompile() @@ -43,7 +39,7 @@ transitiveSourceSets { platform { commonProject = project(":common") - compileWithCommonSourceSets(api, lib, backend, stubs, main) + compileWithCommonSourceSets(api, lib, backend, main) setupLoomMod(api, lib, backend, main) setupLoomRuns() setupFatJar(api, lib, backend, main) @@ -75,11 +71,6 @@ loom { add(backend, "backend-flywheel.refmap.json") } - forge { - mixinConfig("flywheel.backend.mixins.json") - mixinConfig("flywheel.impl.mixins.json") - } - runs { configureEach { property("forge.logging.markers", "") @@ -88,14 +79,20 @@ 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:sodium:${property("sodium_version")}-neoforge") + modCompileOnly("maven.modrinth:iris:${property("iris_version")}-neoforge") modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}") "forApi"(project(path = ":common", configuration = "commonApiOnly")) "forLib"(project(path = ":common", configuration = "commonLib")) "forBackend"(project(path = ":common", configuration = "commonBackend")) - "forStubs"(project(path = ":common", configuration = "commonStubs")) "forMain"(project(path = ":common", configuration = "commonImpl")) } diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 000000000..2e6ed7676 --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform = neoforge diff --git a/forge/src/api/java/dev/engine_room/flywheel/api/event/EndClientResourceReloadEvent.java b/neoforge/src/api/java/dev/engine_room/flywheel/api/event/EndClientResourceReloadEvent.java similarity index 92% rename from forge/src/api/java/dev/engine_room/flywheel/api/event/EndClientResourceReloadEvent.java rename to neoforge/src/api/java/dev/engine_room/flywheel/api/event/EndClientResourceReloadEvent.java index 8e102c4ba..bacc99531 100644 --- a/forge/src/api/java/dev/engine_room/flywheel/api/event/EndClientResourceReloadEvent.java +++ b/neoforge/src/api/java/dev/engine_room/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/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java b/neoforge/src/api/java/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java similarity index 77% rename from forge/src/api/java/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java rename to neoforge/src/api/java/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java index 157826619..1af467d83 100644 --- a/forge/src/api/java/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java +++ b/neoforge/src/api/java/dev/engine_room/flywheel/api/event/ReloadLevelRendererEvent.java @@ -1,10 +1,10 @@ package dev.engine_room.flywheel.api.event; import net.minecraft.client.multiplayer.ClientLevel; -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 NeoForge event bus. */ public final class ReloadLevelRendererEvent extends Event { private final ClientLevel level; diff --git a/forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java b/neoforge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java similarity index 100% rename from forge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java rename to neoforge/src/backend/java/dev/engine_room/flywheel/backend/FlwBackendXplatImpl.java diff --git a/forge/src/backend/java/dev/engine_room/flywheel/backend/compile/FlwProgramsReloader.java b/neoforge/src/backend/java/dev/engine_room/flywheel/backend/compile/FlwProgramsReloader.java similarity index 100% rename from forge/src/backend/java/dev/engine_room/flywheel/backend/compile/FlwProgramsReloader.java rename to neoforge/src/backend/java/dev/engine_room/flywheel/backend/compile/FlwProgramsReloader.java diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java similarity index 86% rename from forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java rename to neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java index b67ac8b7f..79c26ba63 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java +++ b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/BakedModelBufferer.java @@ -1,11 +1,10 @@ package dev.engine_room.flywheel.lib.model.baked; import java.util.Iterator; -import java.util.function.Function; import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; +import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.ItemBlockRenderTypes; @@ -21,8 +20,8 @@ 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; +import net.neoforged.neoforge.client.ChunkRenderTypeSet; +import net.neoforged.neoforge.client.model.data.ModelData; final class BakedModelBufferer { static final RenderType[] CHUNK_LAYERS = RenderType.chunkBufferLayers().toArray(RenderType[]::new); @@ -33,7 +32,7 @@ final class BakedModelBufferer { private BakedModelBufferer() { } - public static void bufferSingle(ModelBlockRenderer blockRenderer, @Nullable BlockAndTintGetter level, BakedModel model, @Nullable BlockState state, @Nullable PoseStack poseStack, ModelData modelData, ResultConsumer resultConsumer) { + public static void bufferSingle(ModelBlockRenderer blockRenderer, @Nullable BlockAndTintGetter level, BakedModel model, @Nullable BlockState state, @Nullable PoseStack poseStack, ResultConsumer resultConsumer) { ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get(); if (level == null) { if (state == null) { @@ -51,7 +50,7 @@ public static void bufferSingle(ModelBlockRenderer blockRenderer, @Nullable Bloc RandomSource random = objects.random; MeshEmitter[] emitters = objects.emitters; - modelData = model.getModelData(level, BlockPos.ZERO, state, modelData); + ModelData modelData = model.getModelData(level, BlockPos.ZERO, state, level.getModelData(BlockPos.ZERO)); random.setSeed(42L); ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData); @@ -69,15 +68,15 @@ public static void bufferSingle(ModelBlockRenderer blockRenderer, @Nullable Bloc } } - public static void bufferBlock(BlockRenderDispatcher renderDispatcher, @Nullable BlockAndTintGetter level, BlockState state, @Nullable PoseStack poseStack, ModelData modelData, ResultConsumer resultConsumer) { + public static void bufferBlock(BlockRenderDispatcher renderDispatcher, @Nullable BlockAndTintGetter level, BlockState state, @Nullable PoseStack poseStack, ResultConsumer resultConsumer) { if (state.getRenderShape() != RenderShape.MODEL) { return; } - bufferSingle(renderDispatcher.getModelRenderer(), level, renderDispatcher.getBlockModel(state), state, poseStack, modelData, resultConsumer); + bufferSingle(renderDispatcher.getModelRenderer(), level, renderDispatcher.getBlockModel(state), state, poseStack, resultConsumer); } - public static void bufferMultiBlock(BlockRenderDispatcher renderDispatcher, Iterator posIterator, BlockAndTintGetter level, @Nullable PoseStack poseStack, Function modelDataLookup, boolean renderFluids, ResultConsumer resultConsumer) { + public static void bufferMultiBlock(BlockRenderDispatcher renderDispatcher, Iterator posIterator, BlockAndTintGetter level, @Nullable PoseStack poseStack, boolean renderFluids, ResultConsumer resultConsumer) { ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get(); if (poseStack == null) { poseStack = objects.identityPoseStack; @@ -116,8 +115,7 @@ public static void bufferMultiBlock(BlockRenderDispatcher renderDispatcher, Iter if (state.getRenderShape() == RenderShape.MODEL) { long seed = state.getSeed(pos); BakedModel model = renderDispatcher.getBlockModel(state); - ModelData modelData = modelDataLookup.apply(pos); - modelData = model.getModelData(level, pos, state, modelData); + ModelData modelData = model.getModelData(level, pos, state, level.getModelData(pos)); random.setSeed(seed); ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData); @@ -141,7 +139,7 @@ public static void bufferMultiBlock(BlockRenderDispatcher renderDispatcher, Iter } public interface ResultConsumer { - void accept(RenderType renderType, boolean shaded, RenderedBuffer data); + void accept(RenderType renderType, boolean shaded, MeshData data); } private static class ThreadLocalObjects { diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java similarity index 100% rename from forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java rename to neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ChunkLayerSortedListBuilder.java diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java similarity index 58% rename from forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java rename to neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java index e878ae95c..2378a8b56 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java +++ b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.UnknownNullability; import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.ByteBufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -13,22 +14,24 @@ class MeshEmitter implements VertexConsumer { private final RenderType renderType; - private final BufferBuilder bufferBuilder; + private final ByteBufferBuilder byteBufferBuilder; + @UnknownNullability + private BufferBuilder bufferBuilder; private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer; private boolean currentShade; - MeshEmitter(RenderType renderType) { - this.renderType = renderType; - this.bufferBuilder = new BufferBuilder(renderType.bufferSize()); - } + MeshEmitter(RenderType renderType) { + this.renderType = renderType; + this.byteBufferBuilder = new ByteBufferBuilder(renderType.bufferSize()); + } public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { this.resultConsumer = resultConsumer; } public void end() { - if (bufferBuilder.building()) { + if (bufferBuilder != null) { emit(); } resultConsumer = null; @@ -40,11 +43,11 @@ public BufferBuilder unwrap(boolean shade) { } private void prepareForGeometry(boolean shade) { - if (!bufferBuilder.building()) { - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + if (bufferBuilder == null) { + bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } else if (shade != currentShade) { emit(); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } currentShade = shade; @@ -55,20 +58,15 @@ private void prepareForGeometry(BakedQuad quad) { } private void emit() { - var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty(); + var data = bufferBuilder.build(); + bufferBuilder = null; - if (renderedBuffer != null) { - resultConsumer.accept(renderType, currentShade, renderedBuffer); - renderedBuffer.release(); + if (data != null) { + resultConsumer.accept(renderType, currentShade, data); + data.close(); } } - @Override - public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, int light, int overlay) { - prepareForGeometry(quad); - bufferBuilder.putBulkData(pose, quad, red, green, blue, light, overlay); - } - @Override public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, float alpha, int light, int overlay, boolean readExistingColor) { prepareForGeometry(quad); @@ -76,9 +74,9 @@ public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float gr } @Override - public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float[] brightnesses, float red, float green, float blue, int[] lights, int overlay, boolean readExistingColor) { + public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, float alpha, int packedLight, int packedOverlay) { prepareForGeometry(quad); - bufferBuilder.putBulkData(pose, quad, brightnesses, red, green, blue, lights, overlay, readExistingColor); + bufferBuilder.putBulkData(pose, quad, red, green, blue, alpha, packedLight, packedOverlay); } @Override @@ -88,47 +86,32 @@ public void putBulkData(PoseStack.Pose pose, BakedQuad quad, float[] brightnesse } @Override - public VertexConsumer vertex(double x, double y, double z) { - throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); - } - - @Override - public VertexConsumer color(int red, int green, int blue, int alpha) { - throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); - } - - @Override - public VertexConsumer uv(float u, float v) { - throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); - } - - @Override - public VertexConsumer overlayCoords(int u, int v) { + public VertexConsumer addVertex(float x, float y, float z) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } @Override - public VertexConsumer uv2(int u, int v) { + public VertexConsumer setColor(int red, int green, int blue, int alpha) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } @Override - public VertexConsumer normal(float x, float y, float z) { + public VertexConsumer setUv(float u, float v) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } @Override - public void endVertex() { + public VertexConsumer setUv1(int u, int v) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } @Override - public void defaultColor(int red, int green, int blue, int alpha) { + public VertexConsumer setUv2(int u, int v) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } @Override - public void unsetDefaultColor() { + public VertexConsumer setNormal(float normalX, float normalY, float normalZ) { throw new UnsupportedOperationException("MeshEmitter only supports putBulkData!"); } } diff --git a/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java new file mode 100644 index 000000000..a3fba8e12 --- /dev/null +++ b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java @@ -0,0 +1,57 @@ +package dev.engine_room.flywheel.lib.model.baked; + +import org.jetbrains.annotations.ApiStatus; + +import dev.engine_room.flywheel.api.material.Material; +import dev.engine_room.flywheel.api.model.Mesh; +import dev.engine_room.flywheel.api.model.Model; +import dev.engine_room.flywheel.lib.model.ModelUtil; +import dev.engine_room.flywheel.lib.model.SimpleModel; + +@ApiStatus.Internal +public final class ModelBuilderImpl { + private ModelBuilderImpl() { + } + + public static SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), builder.level, builder.bakedModel, builder.blockState, builder.poseStack, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + builder.bakedModel + ",renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } + + public static SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, builder.level, builder.state, builder.poseStack, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + builder.state + ",renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } + + public static SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) { + var builder1 = ChunkLayerSortedListBuilder.getThreadLocal(); + + BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, builder.positions.iterator(), builder.level, builder.poseStack, builder.renderFluids, (renderType, shaded, data) -> { + Material material = builder.materialFunc.apply(renderType, shaded); + if (material != null) { + Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded); + builder1.add(renderType, new Model.ConfiguredMesh(material, mesh)); + } + }); + + return new SimpleModel(builder1.build()); + } +} diff --git a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java similarity index 65% rename from forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java rename to neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java index d39cb6e92..d87eee208 100644 --- a/forge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java +++ b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java @@ -5,8 +5,9 @@ import org.jetbrains.annotations.ApiStatus; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.event.ModelEvent; +import net.neoforged.neoforge.client.event.ModelEvent; @ApiStatus.Internal public final class PartialModelEventHandler { @@ -15,16 +16,16 @@ private PartialModelEventHandler() { public static void onRegisterAdditional(ModelEvent.RegisterAdditional event) { for (ResourceLocation modelLocation : PartialModel.ALL.keySet()) { - event.register(modelLocation); + event.register(ModelResourceLocation.standalone(modelLocation)); } } public static void onBakingCompleted(ModelEvent.BakingCompleted event) { PartialModel.populateOnInit = true; - Map models = event.getModels(); + Map models = event.getModels(); for (PartialModel partial : PartialModel.ALL.values()) { - partial.bakedModel = models.get(partial.modelLocation()); + partial.bakedModel = models.get(ModelResourceLocation.standalone(partial.modelLocation())); } } } diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java similarity index 92% rename from forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java rename to neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java index 8aeb9e45f..cda79c23e 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwCommands.java @@ -18,9 +18,9 @@ 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.BooleanValue; +import net.neoforged.neoforge.common.ModConfigSpec.ConfigValue; public final class FlwCommands { private FlwCommands() { @@ -29,7 +29,7 @@ private FlwCommands() { public static void registerClientCommands(RegisterClientCommandsEvent event) { LiteralArgumentBuilder command = Commands.literal("flywheel"); - ConfigValue backendValue = ForgeFlwConfig.INSTANCE.client.backend; + ConfigValue backendValue = NeoForgeFlwConfig.INSTANCE.client.backend; command.then(Commands.literal("backend") .executes(context -> { Backend backend = BackendManager.currentBackend(); @@ -59,7 +59,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { return Command.SINGLE_SUCCESS; }))); - BooleanValue limitUpdatesValue = ForgeFlwConfig.INSTANCE.client.limitUpdates; + BooleanValue limitUpdatesValue = NeoForgeFlwConfig.INSTANCE.client.limitUpdates; command.then(Commands.literal("limitUpdates") .executes(context -> { if (limitUpdatesValue.get()) { @@ -84,7 +84,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { return Command.SINGLE_SUCCESS; }))); - var lightSmoothnessValue = ForgeFlwConfig.INSTANCE.client.backendConfig.lightSmoothness; + var lightSmoothnessValue = NeoForgeFlwConfig.INSTANCE.client.backendConfig.lightSmoothness; command.then(Commands.literal("lightSmoothness") .then(Commands.argument("mode", LightSmoothnessArgument.INSTANCE) .executes(context -> { @@ -98,7 +98,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) { return Command.SINGLE_SUCCESS; }))); - var useLightDirectionsValue = ForgeFlwConfig.INSTANCE.client.backendConfig.useLightDirections; + var useLightDirectionsValue = NeoForgeFlwConfig.INSTANCE.client.backendConfig.useLightDirections; command.then(Commands.literal("useLightDirections") .executes(context -> { if (useLightDirectionsValue.get()) { diff --git a/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java new file mode 100644 index 000000000..f754fc992 --- /dev/null +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwImplXplatImpl.java @@ -0,0 +1,28 @@ +package dev.engine_room.flywheel.impl; + +import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; +import net.minecraft.client.multiplayer.ClientLevel; +import net.neoforged.fml.loading.LoadingModList; +import net.neoforged.neoforge.common.NeoForge; + +public class FlwImplXplatImpl implements FlwImplXplat { + @Override + public boolean isModLoaded(String modId) { + return LoadingModList.get().getModFileById(modId) != null; + } + + @Override + public void dispatchReloadLevelRendererEvent(ClientLevel level) { + NeoForge.EVENT_BUS.post(new ReloadLevelRendererEvent(level)); + } + + @Override + public String getVersionStr() { + return FlywheelNeoForge.version().toString(); + } + + @Override + public FlwConfig getConfig() { + return NeoForgeFlwConfig.INSTANCE; + } +} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java similarity index 64% rename from forge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java rename to neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java index 363e51382..605ca077d 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java @@ -5,28 +5,25 @@ import org.jetbrains.annotations.UnknownNullability; import dev.engine_room.flywheel.lib.internal.FlwLibXplat; +import dev.engine_room.flywheel.lib.model.SimpleModel; import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder; import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.ForgeBakedModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.ForgeBlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder; +import dev.engine_room.flywheel.lib.model.baked.ModelBuilderImpl; import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelManager; -import net.minecraft.core.BlockPos; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fml.util.ObfuscationReflectionHelper; +import net.neoforged.fml.util.ObfuscationReflectionHelper; public class FlwLibXplatImpl implements FlwLibXplat { @Override @UnknownNullability public BakedModel getBakedModel(ModelManager modelManager, ResourceLocation location) { - return modelManager.getModel(location); + return modelManager.getModel(ModelResourceLocation.standalone(location)); } @Override @@ -38,7 +35,7 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { field.setAccessible(true); field.set(dispatcher, field.get(defaultDispatcher)); } - ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "f_110900_"); + ObfuscationReflectionHelper.setPrivateValue(BlockRenderDispatcher.class, dispatcher, new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()), "modelRenderer"); } catch (Exception e) { FlwImpl.LOGGER.error("Failed to initialize vanilla BlockRenderDispatcher!", e); return defaultDispatcher; @@ -47,17 +44,17 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { } @Override - public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) { - return new ForgeBakedModelBuilder(bakedModel); + public SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) { + return ModelBuilderImpl.buildBakedModelBuilder(builder); } @Override - public BlockModelBuilder createBlockModelBuilder(BlockState state) { - return new ForgeBlockModelBuilder(state); + public SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) { + return ModelBuilderImpl.buildBlockModelBuilder(builder); } @Override - public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - return new ForgeMultiBlockModelBuilder(level, positions); + public SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) { + return ModelBuilderImpl.buildMultiBlockModelBuilder(builder); } } diff --git a/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlywheelNeoForge.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlywheelNeoForge.java new file mode 100644 index 000000000..4b11ec71e --- /dev/null +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlywheelNeoForge.java @@ -0,0 +1,120 @@ +package dev.engine_room.flywheel.impl; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.jetbrains.annotations.UnknownNullability; + +import dev.engine_room.flywheel.api.Flywheel; +import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; +import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; +import dev.engine_room.flywheel.backend.compile.FlwProgramsReloader; +import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; +import dev.engine_room.flywheel.impl.compat.EmbeddiumCompat; +import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; +import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; +import dev.engine_room.flywheel.lib.util.LevelAttached; +import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; +import net.minecraft.client.Minecraft; +import net.minecraft.commands.synchronization.ArgumentTypeInfos; +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.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +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.entity.EntityJoinLevelEvent; +import net.neoforged.neoforge.event.entity.EntityLeaveLevelEvent; +import net.neoforged.neoforge.event.level.LevelEvent; +import net.neoforged.neoforge.event.tick.LevelTickEvent; +import net.neoforged.neoforge.registries.RegisterEvent; + +@Mod(value = Flywheel.ID, dist = Dist.CLIENT) +public final class FlywheelNeoForge { + @UnknownNullability + private static ArtifactVersion version; + + public FlywheelNeoForge(IEventBus modEventBus, ModContainer modContainer) { + version = modContainer + .getModInfo() + .getVersion(); + + IEventBus gameEventBus = NeoForge.EVENT_BUS; + + NeoForgeFlwConfig.INSTANCE.registerSpecs(modContainer); + + registerImplEventListeners(gameEventBus, modEventBus); + registerLibEventListeners(gameEventBus, modEventBus); + registerBackendEventListeners(gameEventBus, modEventBus); + + CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString); + FlwImpl.init(); + + EmbeddiumCompat.init(); + } + + private static void registerImplEventListeners(IEventBus gameEventBus, IEventBus modEventBus) { + gameEventBus.addListener((ReloadLevelRendererEvent e) -> BackendManagerImpl.onReloadLevelRenderer(e.level())); + + gameEventBus.addListener((LevelTickEvent.Post e) -> { + // Make sure we don't tick on the server somehow. + if (e.getLevel().isClientSide()) { + VisualizationEventHandler.onClientTick(Minecraft.getInstance(), e.getLevel()); + } + }); + gameEventBus.addListener((EntityJoinLevelEvent e) -> VisualizationEventHandler.onEntityJoinLevel(e.getLevel(), e.getEntity())); + gameEventBus.addListener((EntityLeaveLevelEvent e) -> VisualizationEventHandler.onEntityLeaveLevel(e.getLevel(), e.getEntity())); + + gameEventBus.addListener(FlwCommands::registerClientCommands); + + gameEventBus.addListener((CustomizeGuiOverlayEvent.DebugText e) -> { + Minecraft minecraft = Minecraft.getInstance(); + + if (!minecraft.getDebugOverlay().showDebugScreen()) { + return; + } + + FlwDebugInfo.addDebugInfo(minecraft, e.getRight()); + }); + + modEventBus.addListener((EndClientResourceReloadEvent e) -> BackendManagerImpl.onEndClientResourceReload(e.error().isPresent())); + + modEventBus.addListener((FMLCommonSetupEvent e) -> { + ArgumentTypeInfos.registerByClass(BackendArgument.class, BackendArgument.INFO); + ArgumentTypeInfos.registerByClass(DebugModeArgument.class, DebugModeArgument.INFO); + ArgumentTypeInfos.registerByClass(LightSmoothnessArgument.class, LightSmoothnessArgument.INFO); + }); + modEventBus.addListener((RegisterEvent e) -> { + 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); + e.register(Registries.COMMAND_ARGUMENT_TYPE, Flywheel.rl("light_smoothness"), () -> LightSmoothnessArgument.INFO); + } + }); + } + + private static void registerLibEventListeners(IEventBus gameEventBus, IEventBus modEventBus) { + gameEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.invalidateLevel(e.getLevel())); + + modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadCache.onEndClientResourceReload()); + modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadHolder.onEndClientResourceReload()); + + modEventBus.addListener(PartialModelEventHandler::onRegisterAdditional); + modEventBus.addListener(PartialModelEventHandler::onBakingCompleted); + } + + private static void registerBackendEventListeners(IEventBus gameEventBus, IEventBus modEventBus) { + gameEventBus.addListener((ReloadLevelRendererEvent e) -> Uniforms.onReloadLevelRenderer()); + + modEventBus.addListener((RegisterClientReloadListenersEvent e) -> { + e.registerReloadListener(FlwProgramsReloader.INSTANCE); + }); + } + + public static ArtifactVersion version() { + return version; + } +} diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/NeoForgeFlwConfig.java similarity index 76% rename from forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java rename to neoforge/src/main/java/dev/engine_room/flywheel/impl/NeoForgeFlwConfig.java index 2b50aadb1..5418d184a 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/NeoForgeFlwConfig.java @@ -9,18 +9,18 @@ import dev.engine_room.flywheel.backend.compile.LightSmoothness; 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; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.ModConfigSpec; -public class ForgeFlwConfig implements FlwConfig { - public static final ForgeFlwConfig INSTANCE = new ForgeFlwConfig(); +public class NeoForgeFlwConfig implements FlwConfig { + public static final NeoForgeFlwConfig INSTANCE = new NeoForgeFlwConfig(); public final ClientConfig client; - private final ForgeConfigSpec clientSpec; + private final ModConfigSpec clientSpec; - private ForgeFlwConfig() { - Pair clientPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); + private NeoForgeFlwConfig() { + Pair clientPair = new ModConfigSpec.Builder().configure(ClientConfig::new); this.client = clientPair.getLeft(); clientSpec = clientPair.getRight(); } @@ -40,7 +40,7 @@ public Backend backend() { private static Backend parseBackend(String idStr) { ResourceLocation backendId; try { - backendId = new ResourceLocation(idStr); + backendId = ResourceLocation.parse(idStr); } catch (ResourceLocationException e) { FlwImpl.CONFIG_LOGGER.warn("'backend' value '{}' is not a valid resource location", idStr); return null; @@ -70,18 +70,18 @@ public BackendConfig backendConfig() { return client.backendConfig; } - public void registerSpecs(ModLoadingContext context) { + public void registerSpecs(ModContainer context) { context.registerConfig(ModConfig.Type.CLIENT, clientSpec); } 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; public final ForgeBackendConfig backendConfig; - private ClientConfig(ForgeConfigSpec.Builder builder) { + private ClientConfig(ModConfigSpec.Builder builder) { backend = builder.comment("Select the backend to use.") .define("backend", () -> Backend.REGISTRY.getIdOrThrow(BackendManager.defaultBackend()).toString(), o -> o != null && String.class.isAssignableFrom(o.getClass())); @@ -100,10 +100,10 @@ private ClientConfig(ForgeConfigSpec.Builder builder) { } public static class ForgeBackendConfig implements BackendConfig { - public final ForgeConfigSpec.EnumValue lightSmoothness; - public final ForgeConfigSpec.BooleanValue useLightDirections; + public final ModConfigSpec.EnumValue lightSmoothness; + public final ModConfigSpec.BooleanValue useLightDirections; - public ForgeBackendConfig(ForgeConfigSpec.Builder builder) { + public ForgeBackendConfig(ModConfigSpec.Builder builder) { lightSmoothness = builder.comment("How smooth flywheel's shader-based lighting should be. May have a large performance impact.") .defineEnum("lightSmoothness", LightSmoothness.SMOOTH); diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/compat/EmbeddiumCompat.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/compat/EmbeddiumCompat.java similarity index 100% rename from forge/src/main/java/dev/engine_room/flywheel/impl/compat/EmbeddiumCompat.java rename to neoforge/src/main/java/dev/engine_room/flywheel/impl/compat/EmbeddiumCompat.java diff --git a/neoforge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java new file mode 100644 index 000000000..50950fbab --- /dev/null +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/mixin/MinecraftMixin.java @@ -0,0 +1,40 @@ +package dev.engine_room.flywheel.impl.mixin; + +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +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 dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; +import dev.engine_room.flywheel.impl.FlwImpl; +import net.minecraft.client.Minecraft; +import net.minecraft.server.packs.resources.ReloadableResourceManager; +import net.neoforged.fml.ModLoader; + +@Mixin(Minecraft.class) +abstract class MinecraftMixin { + @Shadow + @Final + private ReloadableResourceManager resourceManager; + + @Inject(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;")) + private void flywheel$onBeginInitialResourceReload(CallbackInfo ci) { + FlwImpl.freezeRegistries(); + } + + @Inject(method = "lambda$new$8", at = @At("HEAD"), remap = false) + private void flywheel$onEndInitialResourceReload(@Coerce Object gameLoadCookie, Optional error, CallbackInfo ci) { + ModLoader.postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error)); + } + + @Inject(method = "lambda$reloadResourcePacks$21", at = @At("HEAD"), remap = false) + private void flywheel$onEndManualResourceReload(boolean recovery, @Coerce Object gameLoadCookie, CompletableFuture completablefuture, Optional error, CallbackInfo ci) { + ModLoader.postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error)); + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 65% rename from forge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml index 766bbfe9f..39f3ab61a 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -# The loader version doesn't matter. Modify the Forge and/or Minecraft version ranges instead. +# The loader version doesn't matter. Modify the NeoForge and/or Minecraft version ranges instead. loaderVersion = "[0,)" license = "${mod_license}" issueTrackerURL = "${mod_issues}" @@ -14,26 +14,25 @@ authors = "Jozufozu, PepperCode1" displayURL = "${mod_homepage}" displayTest = "IGNORE_ALL_VERSION" +[[mixins]] +config = "flywheel.backend.mixins.json" +[[mixins]] +config = "flywheel.impl.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}" -side = "CLIENT" - -[[dependencies.${mod_id}]] -modId = "embeddium" -mandatory = false -versionRange = "[0.3.25,)" +modId = "neoforge" +type = "required" +versionRange = "${neoforge_version_range}" side = "CLIENT" [[dependencies.${mod_id}]] modId = "sodium" -mandatory = false +type = "optional" versionRange = "[0.6.0-beta.2,)" side = "CLIENT" diff --git a/forge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta similarity index 74% rename from forge/src/main/resources/pack.mcmeta rename to neoforge/src/main/resources/pack.mcmeta index ae03c9b7f..77bed856b 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/neoforge/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { "description": "${mod_name} resources", - "pack_format": 15 + "pack_format": 34 } } diff --git a/forge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java b/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java similarity index 50% rename from forge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java rename to neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java index f04eb604f..0ecd54a87 100644 --- a/forge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java +++ b/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java @@ -5,10 +5,10 @@ import org.spongepowered.asm.mixin.MixinEnvironment; import net.minecraft.client.Minecraft; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.loading.FMLLoader; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.neoforge.client.event.ClientTickEvent; +import net.neoforged.neoforge.common.NeoForge; @Mod("flywheel_testmod") public class FlywheelTestModClient { @@ -18,16 +18,14 @@ public class FlywheelTestModClient { public FlywheelTestModClient() { LOGGER.info("Starting {} on Dist: {}", NAME, FMLLoader.getDist()); - MinecraftForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent e) -> { - if (e.phase == TickEvent.Phase.END) { - LOGGER.info("Running mixin audit"); - MixinEnvironment.getCurrentEnvironment() - .audit(); + NeoForge.EVENT_BUS.addListener((ClientTickEvent.Post e) -> { + LOGGER.info("Running mixin audit"); + MixinEnvironment.getCurrentEnvironment() + .audit(); - LOGGER.info("Stopping client"); - Minecraft.getInstance() - .stop(); - } + LOGGER.info("Stopping client"); + Minecraft.getInstance() + .stop(); }); } } diff --git a/forge/src/testMod/resources/META-INF/mods.toml b/neoforge/src/testMod/resources/META-INF/neoforge.mods.toml similarity index 100% rename from forge/src/testMod/resources/META-INF/mods.toml rename to neoforge/src/testMod/resources/META-INF/neoforge.mods.toml diff --git a/settings.gradle.kts b/settings.gradle.kts index cdaa0ff9f..3286aa3f5 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" @@ -17,4 +17,4 @@ rootProject.name = "Flywheel" include("common") include("fabric") -include("forge") +include("neoforge")