mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
58 lines
2.8 KiB
Diff
58 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
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 <paul@technove.co>
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/targeting/TargetingConditions.java b/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
|
|
index 2f8920d8ee765d057a22d76f24f7d7dc1b0b17ca..17a08a3af468093668a41f154c2beb69c6617efa 100644
|
|
--- a/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
|
|
+++ b/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(entity) : 1.0;
|
|
- double max = Math.max(this.range * d, 2.0);
|
|
+ // Gale start - Airplane - check targeting range before getting visibility
|
|
+ // d = invisibility percent, max = follow range adjusted for invisibility, d1 = distance
|
|
double d1 = entity.distanceToSqr(target.getX(), target.getY(), target.getZ());
|
|
+ double followRangeRaw = this.range;
|
|
+
|
|
+ if (d1 > 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(entity) : 1.0;
|
|
+ double max = Math.max(followRangeRaw * d, 2.0);
|
|
+ // Gale end - Airplane - check targeting range before getting visibility
|
|
if (d1 > max * max) {
|
|
return false;
|
|
}
|