Skip to content

Commit

Permalink
The wheel is indeed... flying!
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 6, 2024
1 parent eb3f7e0 commit ea4f05f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.ByteBuffer;

import com.mojang.blaze3d.vertex.MeshData;

import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.MemoryUtil;

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,26 +13,28 @@

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) {
this.resultConsumer = resultConsumer;
}

public void end() {
if (bufferBuilder.building()) {
emit();
}
emit();
resultConsumer = null;
}

Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ea4f05f

Please sign in to comment.