Fixed the debug bounding box renderer

This commit is contained in:
Sollace 2019-12-10 00:30:43 +02:00
parent b5c5ad1d57
commit 6b8c38d214
3 changed files with 22 additions and 6 deletions

View file

@ -5,29 +5,45 @@ import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShapes;
import com.minelittlepony.pony.IPony;
public final class DebugBoundingBoxRenderer {
public static void render(IPony pony, LivingEntity entity, MatrixStack stack, VertexConsumerProvider renderContext) {
public static <T extends LivingEntity> void render(IPony pony, EntityRenderer<T> renderer, T entity, MatrixStack stack, VertexConsumerProvider renderContext, float tickDelta) {
MinecraftClient mc = MinecraftClient.getInstance();
if (!mc.getEntityRenderManager().shouldRenderHitboxes() || entity.squaredDistanceTo(mc.player) > 70) {
return;
}
Vec3d offset = renderer.getPositionOffset(entity, tickDelta);
stack.push();
stack.translate(-offset.x, -offset.y, -offset.z);
float yaw = MathHelper.lerp(tickDelta, entity.prevBodyYaw, entity.bodyYaw);
stack.multiply(Vector3f.NEGATIVE_Y.getDegreesQuaternion(yaw));
Box boundingBox = pony.getComputedBoundingBox(entity);
Vec3d cam = mc.gameRenderer.getCamera().getPos();
Vec3d pos = entity.getPos();
double x = - MathHelper.lerp(tickDelta, entity.lastRenderX, pos.x);
double y = - MathHelper.lerp(tickDelta, entity.lastRenderY, pos.y);
double z = - MathHelper.lerp(tickDelta, entity.lastRenderZ, pos.z);
VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getLines());
WorldRenderer.method_22983(stack, vertices, VoxelShapes.cuboid(boundingBox), -cam.x, -cam.y, -cam.z, 1, 1, 1, 1);
WorldRenderer.drawBox(stack, vertices, boundingBox.offset(x, y, z), 1, 1, 0, 1);
stack.pop();
}
}

View file

@ -83,7 +83,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
shadowSize = manager.getShadowScale();
super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
DebugBoundingBoxRenderer.render(manager.getPony(entity), entity, stack, renderContext);
DebugBoundingBoxRenderer.render(manager.getPony(entity), this, entity, stack, renderContext, tickDelta);
// Translate the shadow position after everything is done
// (shadows are drawn after us)

View file

@ -62,7 +62,7 @@ public abstract class PonyRenderer<T extends MobEntity, M extends EntityModel<T>
super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
DebugBoundingBoxRenderer.render(manager.getPony(entity), entity, stack, renderContext);
DebugBoundingBoxRenderer.render(manager.getPony(entity), this, entity, stack, renderContext, tickDelta);
}
@Override