From 92c88d720f4a3c103e78257c2c65b1600698f9e2 Mon Sep 17 00:00:00 2001 From: Yasin Date: Mon, 20 May 2024 23:43:34 +0200 Subject: use bounding box instead of block size --- .../skyblocker/utils/render/RenderHelper.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/main/java/de/hysky/skyblocker/utils') diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java index 1b16b138..97c040c9 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java @@ -31,6 +31,7 @@ import net.minecraft.util.math.Box; import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.BlockView; import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Vector3f; @@ -60,6 +61,20 @@ public class RenderHelper { renderFilled(context, pos, colorComponents, alpha, throughWalls); renderBeaconBeam(context, pos, colorComponents); } + public static void renderFilled(WorldRenderContext context, Box boundingBox, float[] colorComponents, float alpha, boolean throughWalls) { + MatrixStack matrices = context.matrixStack(); + Vec3d camera = context.camera().getPos(); + + matrices.push(); + matrices.translate(-camera.x, -camera.y, -camera.z); + + VertexConsumerProvider consumers = context.consumers(); + VertexConsumer buffer = consumers.getBuffer(throughWalls ? SkyblockerRenderLayers.FILLED_THROUGH_WALLS : SkyblockerRenderLayers.FILLED); + + WorldRenderer.renderFilledBox(matrices, buffer, boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ, colorComponents[0], colorComponents[1], colorComponents[2], alpha); + + matrices.pop(); + } public static void renderFilled(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha, boolean throughWalls) { renderFilled(context, Vec3d.of(pos), ONE, colorComponents, alpha, throughWalls); @@ -459,4 +474,16 @@ public class RenderHelper { return null; } + + /** + * Retrieves the bounding box of a block in the world. + * + * @param world The client world. + * @param pos The position of the block. + * @return The bounding box of the block. + */ + public static Box getBlockBoundingBox(BlockView world, BlockPos pos) { + BlockState blockState = world.getBlockState(pos); + return blockState.getOutlineShape(world, pos).getBoundingBox().offset(pos); + } } -- cgit