mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-12 11:21:15 +01:00
Use interactAt instead of interact
This commit is contained in:
parent
f3f6da3127
commit
b54ab55efe
@ -12,27 +12,16 @@ public class UseEntityListener {
|
||||
|
||||
public static void useEntityListener(ClientInteractEntityPacket packet, Player player) {
|
||||
final Entity entity = Entity.getEntity(packet.targetId());
|
||||
if (entity == null)
|
||||
if (entity == null || !entity.isViewer(player) || player.getDistance(entity) > 4)
|
||||
return;
|
||||
|
||||
ClientInteractEntityPacket.Type type = packet.type();
|
||||
|
||||
// Player cannot interact with entities he cannot see
|
||||
if (!entity.isViewer(player))
|
||||
return;
|
||||
|
||||
if (type instanceof ClientInteractEntityPacket.Attack) {
|
||||
if (entity instanceof LivingEntity && ((LivingEntity) entity).isDead()) // Can't attack dead entities
|
||||
return;
|
||||
EntityAttackEvent entityAttackEvent = new EntityAttackEvent(player, entity);
|
||||
EventDispatcher.call(entityAttackEvent);
|
||||
} else if (type instanceof ClientInteractEntityPacket.Interact interact) {
|
||||
PlayerEntityInteractEvent playerEntityInteractEvent = new PlayerEntityInteractEvent(player, entity, interact.hand());
|
||||
EventDispatcher.call(playerEntityInteractEvent);
|
||||
} else {
|
||||
// TODO find difference with INTERACT
|
||||
//PlayerEntityInteractEvent playerEntityInteractEvent = new PlayerEntityInteractEvent(player, entity, packet.hand);
|
||||
//player.callEvent(PlayerEntityInteractEvent.class, playerEntityInteractEvent);
|
||||
EventDispatcher.call(new EntityAttackEvent(player, entity));
|
||||
} else if (type instanceof ClientInteractEntityPacket.InteractAt interactAt) {
|
||||
EventDispatcher.call(new PlayerEntityInteractEvent(player, entity, interactAt.hand()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user