diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java index af1fb3d3e4..00606da5be 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java @@ -10,8 +10,6 @@ import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.block.BlockModelRenderer; import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.util.BufferAllocator; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; @@ -19,14 +17,15 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.nio.ByteBuffer; - @Mixin(BlockModelRenderer.class) public abstract class BlockModelRendererMixin { - @Unique private final ThreadLocal alphas = new ThreadLocal<>(); + @Unique + private final ThreadLocal alphas = new ThreadLocal<>(); @Inject(method = "render(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V", at = @At("HEAD"), cancellable = true) private void onRender(BlockRenderView world, BakedModel model, BlockState state, BlockPos pos, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay, CallbackInfo info) { @@ -36,24 +35,9 @@ private void onRender(BlockRenderView world, BakedModel model, BlockState state, else alphas.set(alpha); } - @Inject(method = "renderQuad(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/model/BakedQuad;FFFFIIIII)V", at = @At("TAIL")) - private void onRenderQuad(BlockRenderView world, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, MatrixStack.Entry matrixEntry, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int light0, int light1, int light2, int light3, int overlay, CallbackInfo ci) { + @ModifyConstant(method = "renderQuad", constant = @Constant(floatValue = 1, ordinal = 3)) + private float renderQuad_modifyAlpha(float original) { int alpha = alphas.get(); - if (alpha != -1) rewriteBuffer(vertexConsumer, alpha); - } - - @Unique - private void rewriteBuffer(VertexConsumer vertexConsumer, int alpha) { - if (vertexConsumer instanceof BufferBuilderAccessor bufferBuilder) { - int i = bufferBuilder.getVertexFormat().getVertexSizeByte(); - try (BufferAllocator.CloseableBuffer allocatedBuffer = bufferBuilder.meteor$getAllocator().getAllocated()) { - if (allocatedBuffer != null) { - ByteBuffer buffer = allocatedBuffer.getBuffer(); - for (int l = 1; l <= 4; l++) { - buffer.put(buffer.capacity() - i * l + 15, (byte) (alpha)); - } - } - } - } + return alpha == -1 ? original : alpha / 255f; } }