From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Wed, 23 Nov 2022 20:21:06 +0100 Subject: [PATCH] Check targeting range before getting visibility License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "Early return optimization for target finding" By: Paul Sauve As part of: Airplane (https://github.com/TECHNOVE/Airplane) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) * Airplane copyright * Airplane Copyright (C) 2020 Technove LLC This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java index 52982c1e6a4da36392569c791853279f5f9ac31a..b51a04d3e006bc770006cff790791bc0f6bee77d 100644 --- a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java +++ b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java @@ -75,9 +75,18 @@ public class TargetingConditions { } if (this.range > 0.0) { - double d = this.testInvisible ? target.getVisibilityPercent(tester) : 1.0; - double e = Math.max(this.range * d, 2.0); + // Gale start - Airplane - check targeting range before getting visibility + // d = invisibility percent, e = follow range adjusted for invisibility, f = distance double f = tester.distanceToSqr(target.getX(), target.getY(), target.getZ()); + double followRangeRaw = this.range; + + if (f > followRangeRaw * followRangeRaw) { // the actual follow range will always be this value or smaller, so if the distance is larger then it never will return true after getting invis + return false; + } + + double d = this.testInvisible ? target.getVisibilityPercent(tester) : 1.0; + double e = Math.max(followRangeRaw * d, 2.0); + // Gale end - Airplane - check targeting range before getting visibility if (f > e * e) { return false; }