From 2697fc11d34075c323fe255e1748c412a2a1a876 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 8 Dec 2024 12:15:52 -0800 Subject: [PATCH] Inline platform-specific model builders --- .../flywheel/api/RenderContext.java | 2 - .../flywheel/lib/internal/FlwLibXplat.java | 10 ++- .../flywheel/lib/model/ModelUtil.java | 2 +- .../flywheel/lib/model/Models.java | 6 +- .../lib/model/baked/BakedModelBuilder.java | 19 +++--- .../lib/model/baked/BlockModelBuilder.java | 19 +++--- .../model/baked/MultiBlockModelBuilder.java | 19 +++--- .../model/baked/FabricBakedModelBuilder.java | 64 ------------------- .../model/baked/FabricBlockModelBuilder.java | 57 ----------------- .../baked/FabricMultiBlockModelBuilder.java | 57 ----------------- .../lib/model/baked/ModelBuilderImpl.java | 57 +++++++++++++++++ .../flywheel/impl/FlwLibXplatImpl.java | 20 +++--- .../lib/model/baked/ModelBuilderImpl.java | 57 +++++++++++++++++ .../baked/NeoForgeBakedModelBuilder.java | 64 ------------------- .../baked/NeoForgeBlockModelBuilder.java | 57 ----------------- .../baked/NeoForgeMultiBlockModelBuilder.java | 57 ----------------- .../flywheel/impl/FlwLibXplatImpl.java | 20 +++--- .../flywheel/FlywheelTestModClient.java | 8 +-- 18 files changed, 172 insertions(+), 423 deletions(-) delete mode 100644 fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBakedModelBuilder.java delete mode 100644 fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricBlockModelBuilder.java delete mode 100644 fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/FabricMultiBlockModelBuilder.java create mode 100644 fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java create mode 100644 neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/ModelBuilderImpl.java delete mode 100644 neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBakedModelBuilder.java delete mode 100644 neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBlockModelBuilder.java delete mode 100644 neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeMultiBlockModelBuilder.java 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 2a1e77c59..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; 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 e1557c784..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(); 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/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 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/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/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/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/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBakedModelBuilder.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBakedModelBuilder.java deleted file mode 100644 index 580a47f19..000000000 --- a/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBakedModelBuilder.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 NeoForgeBakedModelBuilder extends BakedModelBuilder { - public NeoForgeBakedModelBuilder(BakedModel bakedModel) { - super(bakedModel); - } - - @Override - public NeoForgeBakedModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public NeoForgeBakedModelBuilder blockState(BlockState blockState) { - super.blockState(blockState); - return this; - } - - @Override - public NeoForgeBakedModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public NeoForgeBakedModelBuilder 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/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBlockModelBuilder.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBlockModelBuilder.java deleted file mode 100644 index f80b5d356..000000000 --- a/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeBlockModelBuilder.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 NeoForgeBlockModelBuilder extends BlockModelBuilder { - public NeoForgeBlockModelBuilder(BlockState state) { - super(state); - } - - @Override - public NeoForgeBlockModelBuilder level(BlockAndTintGetter level) { - super.level(level); - return this; - } - - @Override - public NeoForgeBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public NeoForgeBlockModelBuilder 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/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeMultiBlockModelBuilder.java b/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeMultiBlockModelBuilder.java deleted file mode 100644 index 0621d1c15..000000000 --- a/neoforge/src/lib/java/dev/engine_room/flywheel/lib/model/baked/NeoForgeMultiBlockModelBuilder.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 NeoForgeMultiBlockModelBuilder extends MultiBlockModelBuilder { - public NeoForgeMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - super(level, positions); - } - - @Override - public NeoForgeMultiBlockModelBuilder poseStack(PoseStack poseStack) { - super.poseStack(poseStack); - return this; - } - - @Override - public NeoForgeMultiBlockModelBuilder enableFluidRendering() { - super.enableFluidRendering(); - return this; - } - - @Override - public NeoForgeMultiBlockModelBuilder 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/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java index 58e135b6e..605ca077d 100644 --- a/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java +++ b/neoforge/src/main/java/dev/engine_room/flywheel/impl/FlwLibXplatImpl.java @@ -5,22 +5,18 @@ 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.ModelBuilderImpl; import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.NeoForgeBakedModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.NeoForgeBlockModelBuilder; -import dev.engine_room.flywheel.lib.model.baked.NeoForgeMultiBlockModelBuilder; 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.client.resources.model.ModelResourceLocation; -import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; import net.neoforged.fml.util.ObfuscationReflectionHelper; public class FlwLibXplatImpl implements FlwLibXplat { @@ -48,17 +44,17 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() { } @Override - public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) { - return new NeoForgeBakedModelBuilder(bakedModel); + public SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) { + return ModelBuilderImpl.buildBakedModelBuilder(builder); } @Override - public BlockModelBuilder createBlockModelBuilder(BlockState state) { - return new NeoForgeBlockModelBuilder(state); + public SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) { + return ModelBuilderImpl.buildBlockModelBuilder(builder); } @Override - public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable positions) { - return new NeoForgeMultiBlockModelBuilder(level, positions); + public SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) { + return ModelBuilderImpl.buildMultiBlockModelBuilder(builder); } } diff --git a/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java b/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java index 3a2002661..0ecd54a87 100644 --- a/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java +++ b/neoforge/src/testMod/java/dev/engine_room/flywheel/FlywheelTestModClient.java @@ -1,14 +1,14 @@ package dev.engine_room.flywheel; -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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongepowered.asm.mixin.MixinEnvironment; import net.minecraft.client.Minecraft; +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 {