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:
@@ -4,14 +4,11 @@ import net.fabricmc.api.ClientModInitializer;
|
|||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.*;
|
||||||
import net.minecraft.registry.tag.ItemTags;
|
import net.minecraft.registry.tag.ItemTags;
|
||||||
import net.minecraft.registry.tag.TagKey;
|
import net.minecraft.registry.tag.TagKey;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.Box;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
@@ -47,14 +44,6 @@ public class ElytraMace implements ClientModInitializer
|
|||||||
return index;
|
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
|
@Override
|
||||||
public void onInitializeClient()
|
public void onInitializeClient()
|
||||||
{
|
{
|
||||||
@@ -63,7 +52,7 @@ public class ElytraMace implements ClientModInitializer
|
|||||||
{
|
{
|
||||||
return;
|
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)
|
if (target == null || client.player.fallDistance < 1.5)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user