Skip to content

Commit

Permalink
in reach color
Browse files Browse the repository at this point in the history
  • Loading branch information
RedthMC committed Aug 16, 2024
1 parent 96605b9 commit 1a48e60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class Config extends cc.polyfrost.oneconfig.config.Config {
)
public static OneColor boxColor = new OneColor(168, 45, 45, 255);

@Color(
name = "Box Color in Reach"
)
public static OneColor inReachColor = new OneColor(45, 168, 45, 255);

@Slider(
name = "Box Size",
min = 0.05f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public void renderPlayerEvent(RenderPlayerEvent.Post event) {
//range mode
double distance = event.entityPlayer.getDistanceSq(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
if (distance > Config.range * Config.range) return;
AxisAlignedBB aabb = getAABB(event.entityPlayer, event.partialRenderTick);
renderBox(aabb, Config.boxColor);

} else {
//target mode
Expand All @@ -40,7 +38,11 @@ public void renderPlayerEvent(RenderPlayerEvent.Post event) {
}

AxisAlignedBB aabb = getAABB(event.entityPlayer, event.partialRenderTick);
renderBox(aabb, Config.boxColor);
if (mc.pointedEntity == event.entityPlayer) {
renderBox(aabb, Config.inReachColor);
} else {
renderBox(aabb, Config.boxColor);
}
}

private void renderBox(AxisAlignedBB aabb, OneColor color) {
Expand All @@ -51,12 +53,14 @@ private void renderBox(AxisAlignedBB aabb, OneColor color) {
GlStateManager.disableTexture2D();
GlStateManager.depthMask(true);
GlStateManager.disableLighting();
GlStateManager.enableCull();
GlStateManager.disableCull();
GlStateManager.disableDepth();
if (color.getAlpha() > 0.0F) {
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
renderCube(aabb);
}
GlStateManager.enableCull();
GlStateManager.enableDepth();
GlStateManager.enableLighting();
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
Expand Down Expand Up @@ -116,9 +120,22 @@ private static AxisAlignedBB getAABB(Entity target, float partialTicks) {
AxisAlignedBB shrunkenTargetBox = boxAtOrigin.contract(halfRange, halfRange, halfRange);
Vec3 bestHitPos = pointClampedIntoBox(cameraPosRelToEntity, shrunkenTargetBox);



return new AxisAlignedBB(bestHitPos.xCoord, bestHitPos.yCoord, bestHitPos.zCoord, bestHitPos.xCoord, bestHitPos.yCoord, bestHitPos.zCoord).expand(halfRange, halfRange, halfRange);
}

private static boolean isInReach(Entity target, float partialTicks) {
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);
return cameraPosRelToEntity.squareDistanceTo(pointClampedIntoBox(cameraPosRelToEntity, boxAtOrigin)) > 3.0 * 3.0;
}

private static boolean isLooking(Entity target) {
Vec3 vec = new Vec3(mc.thePlayer.getLookVec().xCoord * Config.range, mc.thePlayer.getLookVec().yCoord * Config.range, mc.thePlayer.getLookVec().zCoord * Config.range);
return target.getEntityBoundingBox().calculateIntercept(mc.thePlayer.getPositionEyes(1.0f), mc.thePlayer.getPositionEyes(1.0F).add(vec)) != null;
Expand Down

0 comments on commit 1a48e60

Please sign in to comment.