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 e6326600b..332fa079b 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 @@ -2,6 +2,8 @@ import java.nio.ByteBuffer; +import com.mojang.blaze3d.vertex.MeshData; + import org.jetbrains.annotations.Nullable; import org.lwjgl.system.MemoryUtil; @@ -16,8 +18,8 @@ final class MeshHelper { private MeshHelper() { } - public static SimpleMesh blockVerticesToMesh(BufferBuilder.RenderedBuffer buffer, @Nullable String meshDescriptor) { - BufferBuilder.DrawState drawState = buffer.drawState(); + public static SimpleMesh blockVerticesToMesh(MeshData buffer, @Nullable String meshDescriptor) { + MeshData.DrawState drawState = buffer.drawState(); int vertexCount = drawState.vertexCount(); long srcStride = drawState.format().getVertexSize(); 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 2f8a09ca6..62667ab17 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 @@ -2,9 +2,10 @@ import java.util.Iterator; +import com.mojang.blaze3d.vertex.MeshData; + import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap; @@ -129,7 +130,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/MeshEmitter.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java index 268a6e1da..801f8b261 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 @@ -1,5 +1,10 @@ package dev.engine_room.flywheel.lib.model.baked; +import com.mojang.blaze3d.vertex.ByteBufferBuilder; +import com.mojang.blaze3d.vertex.MeshData; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import org.jetbrains.annotations.UnknownNullability; import com.mojang.blaze3d.vertex.BufferBuilder; @@ -8,16 +13,20 @@ import net.minecraft.client.renderer.RenderType; +import java.util.Map; + class MeshEmitter { private final RenderType renderType; - private final BufferBuilder bufferBuilder; + private final ByteBufferBuilder buffer; + private BufferBuilder bufferBuilder; private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer; private boolean currentShade; MeshEmitter(RenderType renderType) { this.renderType = renderType; - this.bufferBuilder = new BufferBuilder(renderType.bufferSize()); + this.buffer = new ByteBufferBuilder(renderType.bufferSize()); + this.bufferBuilder = new BufferBuilder(buffer, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { @@ -25,9 +34,7 @@ public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { } public void end() { - if (bufferBuilder.building()) { - emit(); - } + emit(); resultConsumer = null; } @@ -37,22 +44,22 @@ public BufferBuilder getBuffer(boolean shade) { } void prepareForGeometry(boolean shade) { - if (!bufferBuilder.building()) { - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - } else if (shade != currentShade) { + bufferBuilder = new BufferBuilder(buffer, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + + if (shade != currentShade) { emit(); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + bufferBuilder = new BufferBuilder(buffer, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); } currentShade = shade; } void emit() { - var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty(); + MeshData meshData = bufferBuilder.build(); - if (renderedBuffer != null) { - resultConsumer.accept(renderType, currentShade, renderedBuffer); - renderedBuffer.release(); + if (meshData != null) { + resultConsumer.accept(renderType, currentShade, meshData); + meshData.close(); } } } diff --git a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java index 21f802f07..7a6b6514a 100644 --- a/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java +++ b/fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/PartialModelEventHandler.java @@ -2,6 +2,8 @@ import java.util.List; +import net.minecraft.client.resources.model.ModelResourceLocation; + import org.jetbrains.annotations.ApiStatus; import dev.engine_room.flywheel.api.Flywheel; @@ -24,7 +26,7 @@ public static ResourceLocation[] onRegisterAdditional() { public static void onBakingCompleted(ModelManager manager) { for (PartialModel partial : PartialModel.ALL) { - partial.set(manager.getModel(partial.getLocation())); + partial.set(manager.getModel(ModelResourceLocation.inventory(partial.getLocation()))); } } diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java index 67354150d..756d37abe 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java @@ -73,9 +73,10 @@ private static void setupLib() { EndClientResourceReloadCallback.EVENT.register((minecraft, resourceManager, initialReload, error) -> ModelHolder.onEndClientResourceReload()); - ModelLoadingPlugin.register(ctx -> { - ctx.addModels(PartialModelEventHandler.onRegisterAdditional()); - }); + //fixme 1.21 porting +// ModelLoadingPlugin.register(ctx -> { +// ctx.addModels(PartialModelEventHandler.onRegisterAdditional()); +// }); ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(PartialModelEventHandler.ReloadListener.INSTANCE); }