1.21 Port II

This commit is contained in:
IThundxr 2024-07-10 11:44:52 -04:00
parent d587ec0ec8
commit d0924175de
No known key found for this signature in database
GPG Key ID: E291EC97BAF935E6
4 changed files with 41 additions and 20 deletions

View File

@ -0,0 +1,12 @@
package dev.engine_room.flywheel.impl.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import com.mojang.blaze3d.vertex.BufferBuilder;
@Mixin(BufferBuilder.class)
public interface BufferBuilderAccessor {
@Accessor("building")
boolean flywheel$getBuilding();
}

View File

@ -6,6 +6,7 @@
"refmap": "flywheel.refmap.json", "refmap": "flywheel.refmap.json",
"client": [ "client": [
"BlockEntityTypeMixin", "BlockEntityTypeMixin",
"BufferBuilderAccessor",
"ClientChunkCacheMixin", "ClientChunkCacheMixin",
"ClientLevelMixin", "ClientLevelMixin",
"EntityTypeMixin", "EntityTypeMixin",

View File

@ -3,21 +3,25 @@ package dev.engine_room.flywheel.lib.model.baked;
import org.jetbrains.annotations.UnknownNullability; import org.jetbrains.annotations.UnknownNullability;
import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
import dev.engine_room.flywheel.impl.mixin.BufferBuilderAccessor;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
class MeshEmitter { class MeshEmitter {
private final RenderType renderType; private final RenderType renderType;
private final BufferBuilder bufferBuilder; private final ByteBufferBuilder byteBufferBuilder;
private BufferBuilder bufferBuilder;
private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer; private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer;
private boolean currentShade; private boolean currentShade;
MeshEmitter(RenderType renderType) { MeshEmitter(RenderType renderType) {
this.renderType = renderType; this.renderType = renderType;
this.bufferBuilder = new BufferBuilder(renderType.bufferSize()); this.byteBufferBuilder = new ByteBufferBuilder(renderType.bufferSize());
this.bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} }
public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) {
@ -25,7 +29,7 @@ class MeshEmitter {
} }
public void end() { public void end() {
if (bufferBuilder.building()) { if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
emit(); emit();
} }
resultConsumer = null; resultConsumer = null;
@ -37,22 +41,22 @@ class MeshEmitter {
} }
void prepareForGeometry(boolean shade) { void prepareForGeometry(boolean shade) {
if (!bufferBuilder.building()) { if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) { } else if (shade != currentShade) {
emit(); emit();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} }
currentShade = shade; currentShade = shade;
} }
void emit() { void emit() {
var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty(); var renderedBuffer = bufferBuilder.build();
if (renderedBuffer != null) { if (renderedBuffer != null) {
resultConsumer.accept(renderType, currentShade, renderedBuffer); resultConsumer.accept(renderType, currentShade, renderedBuffer);
renderedBuffer.release(); renderedBuffer.close();
} }
} }
} }

View File

@ -3,32 +3,36 @@ package dev.engine_room.flywheel.lib.model.baked;
import org.jetbrains.annotations.UnknownNullability; import org.jetbrains.annotations.UnknownNullability;
import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
import dev.engine_room.flywheel.impl.mixin.BufferBuilderAccessor;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BakedQuad;
class MeshEmitter implements VertexConsumer { class MeshEmitter implements VertexConsumer {
private final RenderType renderType; private final RenderType renderType;
private final BufferBuilder bufferBuilder; private final ByteBufferBuilder byteBufferBuilder;
private BufferBuilder bufferBuilder;
private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer; private BakedModelBufferer.@UnknownNullability ResultConsumer resultConsumer;
private boolean currentShade; private boolean currentShade;
MeshEmitter(RenderType renderType) { MeshEmitter(RenderType renderType) {
this.renderType = renderType; this.renderType = renderType;
this.bufferBuilder = new BufferBuilder(renderType.bufferSize()); this.byteBufferBuilder = new ByteBufferBuilder(renderType.bufferSize());
} this.bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
}
public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) { public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) {
this.resultConsumer = resultConsumer; this.resultConsumer = resultConsumer;
} }
public void end() { public void end() {
if (bufferBuilder.building()) { if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
emit(); emit();
} }
resultConsumer = null; resultConsumer = null;
@ -39,12 +43,12 @@ class MeshEmitter implements VertexConsumer {
return bufferBuilder; return bufferBuilder;
} }
private void prepareForGeometry(boolean shade) { void prepareForGeometry(boolean shade) {
if (!bufferBuilder.building()) { if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) { } else if (shade != currentShade) {
emit(); emit();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} }
currentShade = shade; currentShade = shade;
@ -55,11 +59,11 @@ class MeshEmitter implements VertexConsumer {
} }
private void emit() { private void emit() {
var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty(); var renderedBuffer = bufferBuilder.build();
if (renderedBuffer != null) { if (renderedBuffer != null) {
resultConsumer.accept(renderType, currentShade, renderedBuffer); resultConsumer.accept(renderType, currentShade, renderedBuffer);
renderedBuffer.release(); renderedBuffer.close();
} }
} }