mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-14 22:43:56 +01:00
1.21 Port II
This commit is contained in:
parent
d587ec0ec8
commit
d0924175de
@ -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();
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"client": [
|
||||
"BlockEntityTypeMixin",
|
||||
"BufferBuilderAccessor",
|
||||
"ClientChunkCacheMixin",
|
||||
"ClientLevelMixin",
|
||||
"EntityTypeMixin",
|
||||
|
@ -3,21 +3,25 @@ package dev.engine_room.flywheel.lib.model.baked;
|
||||
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;
|
||||
|
||||
import dev.engine_room.flywheel.impl.mixin.BufferBuilderAccessor;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
class MeshEmitter {
|
||||
private final RenderType renderType;
|
||||
private final BufferBuilder bufferBuilder;
|
||||
private final ByteBufferBuilder byteBufferBuilder;
|
||||
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());
|
||||
this.bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
|
||||
}
|
||||
|
||||
public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) {
|
||||
@ -25,7 +29,7 @@ class MeshEmitter {
|
||||
}
|
||||
|
||||
public void end() {
|
||||
if (bufferBuilder.building()) {
|
||||
if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
|
||||
emit();
|
||||
}
|
||||
resultConsumer = null;
|
||||
@ -37,22 +41,22 @@ class MeshEmitter {
|
||||
}
|
||||
|
||||
void prepareForGeometry(boolean shade) {
|
||||
if (!bufferBuilder.building()) {
|
||||
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
|
||||
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
|
||||
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();
|
||||
var renderedBuffer = bufferBuilder.build();
|
||||
|
||||
if (renderedBuffer != null) {
|
||||
resultConsumer.accept(renderType, currentShade, renderedBuffer);
|
||||
renderedBuffer.release();
|
||||
renderedBuffer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,24 +3,28 @@ package dev.engine_room.flywheel.lib.model.baked;
|
||||
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;
|
||||
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.block.model.BakedQuad;
|
||||
|
||||
class MeshEmitter implements VertexConsumer {
|
||||
private final RenderType renderType;
|
||||
private final BufferBuilder bufferBuilder;
|
||||
private final ByteBufferBuilder byteBufferBuilder;
|
||||
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());
|
||||
this.bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
|
||||
}
|
||||
|
||||
public void prepare(BakedModelBufferer.ResultConsumer resultConsumer) {
|
||||
@ -28,7 +32,7 @@ class MeshEmitter implements VertexConsumer {
|
||||
}
|
||||
|
||||
public void end() {
|
||||
if (bufferBuilder.building()) {
|
||||
if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
|
||||
emit();
|
||||
}
|
||||
resultConsumer = null;
|
||||
@ -39,12 +43,12 @@ class MeshEmitter implements VertexConsumer {
|
||||
return bufferBuilder;
|
||||
}
|
||||
|
||||
private void prepareForGeometry(boolean shade) {
|
||||
if (!bufferBuilder.building()) {
|
||||
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
|
||||
void prepareForGeometry(boolean shade) {
|
||||
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
|
||||
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,11 +59,11 @@ class MeshEmitter implements VertexConsumer {
|
||||
}
|
||||
|
||||
private void emit() {
|
||||
var renderedBuffer = bufferBuilder.endOrDiscardIfEmpty();
|
||||
var renderedBuffer = bufferBuilder.build();
|
||||
|
||||
if (renderedBuffer != null) {
|
||||
resultConsumer.accept(renderType, currentShade, renderedBuffer);
|
||||
renderedBuffer.release();
|
||||
renderedBuffer.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user