Use expanded bounding box for target selection

Replace predictive distance logic with a simpler bounding-box expansion when searching for nearby LivingEntity targets. The predictDistance method and unused imports (PlayerEntity, Box, Vec3d) were removed; getEntitiesByClass now uses client.player.getBoundingBox().expand(client.player.getAttributeValue(EntityAttributes.ENTITY_INTERACTION_RANGE) + client.player.getVelocity().length()) and a simpler predicate (exclude self). This simplifies target acquisition and avoids the previous predictive calculation.
This commit is contained in:
2026-02-17 02:05:25 +01:00
parent 98af11f893
commit ddb6545d73

View File

@@ -4,14 +4,11 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.*;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import java.util.Comparator;
@@ -47,14 +44,6 @@ public class ElytraMace implements ClientModInitializer
return index;
}
private double predictDistance(PlayerEntity source, LivingEntity target)
{
Vec3d difference = target.getEyePos().subtract(source.getEyePos());
Vec3d relativeVelocity = source.getVelocity().subtract(target.getVelocity());
double speed = relativeVelocity.dotProduct(difference.normalize());
return source.getAttributeValue(EntityAttributes.ENTITY_INTERACTION_RANGE) + speed * 2;
}
@Override
public void onInitializeClient()
{
@@ -63,7 +52,7 @@ public class ElytraMace implements ClientModInitializer
{
return;
}
LivingEntity target = client.world.getEntitiesByClass(LivingEntity.class, Box.of(client.player.getEyePos(), 10.0, 10.0, 10.0), e -> e != client.player && client.player.distanceTo(e) <= predictDistance(client.player, e)).stream().min(Comparator.comparingDouble(client.player::squaredDistanceTo)).orElse(null);
LivingEntity target = client.world.getEntitiesByClass(LivingEntity.class, client.player.getBoundingBox().expand(client.player.getAttributeValue(EntityAttributes.ENTITY_INTERACTION_RANGE) + client.player.getVelocity().length()), e -> e != client.player).stream().min(Comparator.comparingDouble(client.player::squaredDistanceTo)).orElse(null);
if (target == null || client.player.fallDistance < 1.5)
{
return;