Skip to content

Commit

Permalink
smoooooooooooth
Browse files Browse the repository at this point in the history
  • Loading branch information
RedthMC committed Aug 16, 2024
1 parent 0fae4cd commit 96605b9
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public void renderPlayerEvent(RenderPlayerEvent.Post event) {
} else {
//target mode
if (!isLooking(event.entityPlayer)) return;
AxisAlignedBB aabb = getAABB(event.entityPlayer, event.partialRenderTick);
renderBox(aabb, Config.boxColor);

}

AxisAlignedBB aabb = getAABB(event.entityPlayer, event.partialRenderTick);
renderBox(aabb, Config.boxColor);
}

private void renderBox(AxisAlignedBB aabb, OneColor color) {
Expand Down Expand Up @@ -105,9 +105,13 @@ private static void renderCube(AxisAlignedBB aabb) {
}

private static AxisAlignedBB getAABB(Entity target, float partialTicks) {

Vec3 cameraPosRelToEntity = mc.thePlayer.getPositionEyes(partialTicks).subtract(getLerpedPos(mc.thePlayer, partialTicks));
AxisAlignedBB boxAtOrigin = target.getEntityBoundingBox().offset(-mc.thePlayer.posX, -mc.thePlayer.posY, -mc.thePlayer.posZ);
Vec3 lerpedPos = getLerpedPos(mc.thePlayer, partialTicks);
Vec3 targetLerpOffset = getLerpedPos(target, partialTicks);
Vec3 cameraPosRelToEntity = mc.thePlayer.getPositionEyes(partialTicks).subtract(lerpedPos);
AxisAlignedBB boxAtOrigin = target.getEntityBoundingBox()
.offset(-lerpedPos.xCoord, -lerpedPos.yCoord, -lerpedPos.zCoord)
.offset(-target.posX, -target.posY, -target.posZ)
.offset(targetLerpOffset.xCoord, targetLerpOffset.yCoord, targetLerpOffset.zCoord);
float halfRange = Config.size / 2;
AxisAlignedBB shrunkenTargetBox = boxAtOrigin.contract(halfRange, halfRange, halfRange);
Vec3 bestHitPos = pointClampedIntoBox(cameraPosRelToEntity, shrunkenTargetBox);
Expand All @@ -124,6 +128,10 @@ private static Vec3 getLerpedPos(Entity entity, float partialTicks) {
return new Vec3(entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks, entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks, entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks);
}

private static Vec3 getLerpOffset(Entity entity, float partialTicks) {
return new Vec3((entity.posX - entity.prevPosX) * (double) partialTicks, (entity.posY - entity.prevPosY) * (double) partialTicks, (entity.posZ - entity.prevPosZ) * (double) partialTicks);
}

private static Vec3 pointClampedIntoBox(Vec3 point, AxisAlignedBB box) {
double x = MathHelper.clamp_double(point.xCoord, box.minX, box.maxX);
double y = MathHelper.clamp_double(point.yCoord, box.minY, box.maxY);
Expand Down

0 comments on commit 96605b9

Please sign in to comment.