metadata
This commit is contained in:
@@ -56,7 +56,7 @@ public class BakedBlockEntityModel {
|
|||||||
entity.setWorld(MinecraftClient.getInstance().world);
|
entity.setWorld(MinecraftClient.getInstance().world);
|
||||||
if (renderer != null) {
|
if (renderer != null) {
|
||||||
try {
|
try {
|
||||||
renderer.render(entity, 0.0f, new MatrixStack(), layer->map.computeIfAbsent(layer, rl -> new LayerConsumer(rl, new ReuseVertexConsumer())).consumer, 0, 0, new Vec3d(0,0,0));
|
renderer.render(entity, 0.0f, new MatrixStack(), layer->map.computeIfAbsent(layer, rl -> new LayerConsumer(rl, new ReuseVertexConsumer().setDefaultMeta(ModelTextureBakery.getMetaFromLayer(rl)))).consumer, 0, 0, new Vec3d(0,0,0));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error("Unable to bake block entity: " + entity, e);
|
Logger.error("Unable to bake block entity: " + entity, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,28 @@ public class ModelTextureBakery {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getMetaFromLayer(RenderLayer layer) {
|
||||||
|
boolean hasDiscard = layer == RenderLayer.getCutout() ||
|
||||||
|
layer == RenderLayer.getCutoutMipped() ||
|
||||||
|
layer == RenderLayer.getTripwire();
|
||||||
|
|
||||||
|
boolean isMipped = layer == RenderLayer.getCutoutMipped() ||
|
||||||
|
layer == RenderLayer.getSolid() ||
|
||||||
|
layer == RenderLayer.getTranslucent() ||
|
||||||
|
layer == RenderLayer.getTripwire();
|
||||||
|
|
||||||
|
int meta = hasDiscard?1:0;
|
||||||
|
meta |= isMipped?2:0;
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
private void bakeBlockModel(BlockState state, RenderLayer layer) {
|
private void bakeBlockModel(BlockState state, RenderLayer layer) {
|
||||||
var model = MinecraftClient.getInstance()
|
var model = MinecraftClient.getInstance()
|
||||||
.getBakedModelManager()
|
.getBakedModelManager()
|
||||||
.getBlockModels()
|
.getBlockModels()
|
||||||
.getModel(state);
|
.getModel(state);
|
||||||
|
|
||||||
boolean hasDiscard = layer == RenderLayer.getCutout() ||
|
int meta = getMetaFromLayer(layer);
|
||||||
layer == RenderLayer.getCutoutMipped() ||
|
|
||||||
layer == RenderLayer.getTripwire();
|
|
||||||
|
|
||||||
for (Direction direction : new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, null}) {
|
for (Direction direction : new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, null}) {
|
||||||
for (var part : model.getParts(new LocalRandom(42L))) {
|
for (var part : model.getParts(new LocalRandom(42L))) {
|
||||||
@@ -58,7 +71,6 @@ public class ModelTextureBakery {
|
|||||||
for (var quad : quads) {
|
for (var quad : quads) {
|
||||||
//TODO: add meta specifiying quad has a tint
|
//TODO: add meta specifiying quad has a tint
|
||||||
|
|
||||||
int meta = hasDiscard?1:0;
|
|
||||||
this.vc.quad(quad, meta);
|
this.vc.quad(quad, meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +78,8 @@ public class ModelTextureBakery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void bakeFluidState(BlockState state, int face) {
|
private void bakeFluidState(BlockState state, RenderLayer layer, int face) {
|
||||||
|
this.vc.setDefaultMeta(getMetaFromLayer(layer));//Set the meta while baking
|
||||||
MinecraftClient.getInstance().getBlockRenderManager().renderFluid(BlockPos.ORIGIN, new BlockRenderView() {
|
MinecraftClient.getInstance().getBlockRenderManager().renderFluid(BlockPos.ORIGIN, new BlockRenderView() {
|
||||||
@Override
|
@Override
|
||||||
public float getBrightness(Direction direction, boolean shaded) {
|
public float getBrightness(Direction direction, boolean shaded) {
|
||||||
@@ -131,6 +144,7 @@ public class ModelTextureBakery {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}, this.vc, state, state.getFluidState());
|
}, this.vc, state, state.getFluidState());
|
||||||
|
this.vc.setDefaultMeta(0);//Reset default meta
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldReturnAirForFluid(BlockPos pos, int face) {
|
private static boolean shouldReturnAirForFluid(BlockPos pos, int face) {
|
||||||
@@ -220,7 +234,7 @@ public class ModelTextureBakery {
|
|||||||
var mat = new Matrix4f();
|
var mat = new Matrix4f();
|
||||||
for (int i = 0; i < VIEWS.length; i++) {
|
for (int i = 0; i < VIEWS.length; i++) {
|
||||||
this.vc.reset();
|
this.vc.reset();
|
||||||
this.bakeFluidState(state, i);
|
this.bakeFluidState(state, layer, i);
|
||||||
if (this.vc.isEmpty()) continue;
|
if (this.vc.isEmpty()) continue;
|
||||||
BudgetBufferRenderer.setup(this.vc.getAddress(), this.vc.quadCount(), blockTextureId);
|
BudgetBufferRenderer.setup(this.vc.getAddress(), this.vc.quadCount(), blockTextureId);
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,22 @@ public final class ReuseVertexConsumer implements VertexConsumer {
|
|||||||
private MemoryBuffer buffer = new MemoryBuffer(8192);
|
private MemoryBuffer buffer = new MemoryBuffer(8192);
|
||||||
private long ptr;
|
private long ptr;
|
||||||
private int count;
|
private int count;
|
||||||
|
private int defaultMeta;
|
||||||
|
|
||||||
public ReuseVertexConsumer() {
|
public ReuseVertexConsumer() {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReuseVertexConsumer setDefaultMeta(int meta) {
|
||||||
|
this.defaultMeta = meta;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReuseVertexConsumer vertex(float x, float y, float z) {
|
public ReuseVertexConsumer vertex(float x, float y, float z) {
|
||||||
this.ensureCanPut();
|
this.ensureCanPut();
|
||||||
this.ptr += VERTEX_FORMAT_SIZE; this.count++; //Goto next vertex
|
this.ptr += VERTEX_FORMAT_SIZE; this.count++; //Goto next vertex
|
||||||
|
this.meta(this.defaultMeta);
|
||||||
MemoryUtil.memPutFloat(this.ptr, x);
|
MemoryUtil.memPutFloat(this.ptr, x);
|
||||||
MemoryUtil.memPutFloat(this.ptr + 4, y);
|
MemoryUtil.memPutFloat(this.ptr + 4, y);
|
||||||
MemoryUtil.memPutFloat(this.ptr + 8, z);
|
MemoryUtil.memPutFloat(this.ptr + 8, z);
|
||||||
@@ -90,6 +97,7 @@ public final class ReuseVertexConsumer implements VertexConsumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ReuseVertexConsumer reset() {
|
public ReuseVertexConsumer reset() {
|
||||||
|
this.defaultMeta = 0;//RESET THE DEFAULT META
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
this.ptr = this.buffer.address - VERTEX_FORMAT_SIZE;//the thing is first time this gets incremented by FORMAT_STRIDE
|
this.ptr = this.buffer.address - VERTEX_FORMAT_SIZE;//the thing is first time this gets incremented by FORMAT_STRIDE
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ in vec2 texCoord;
|
|||||||
out vec4 colour;
|
out vec4 colour;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
colour = texture(tex, texCoord);
|
colour = texture(tex, texCoord, ((~metadata>>1)&1u)*-16.0f);
|
||||||
if (colour.a < 0.001f && ((metadata&1u)!=0)) {
|
if (colour.a < 0.001f && ((metadata&1u)!=0)) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user