mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-15 06:54:21 +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",
|
"refmap": "flywheel.refmap.json",
|
||||||
"client": [
|
"client": [
|
||||||
"BlockEntityTypeMixin",
|
"BlockEntityTypeMixin",
|
||||||
|
"BufferBuilderAccessor",
|
||||||
"ClientChunkCacheMixin",
|
"ClientChunkCacheMixin",
|
||||||
"ClientLevelMixin",
|
"ClientLevelMixin",
|
||||||
"EntityTypeMixin",
|
"EntityTypeMixin",
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user