Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public static void lookAt(LookAnchor entityAnchor, Object target, @Nullable Floa
}
} else if (entity instanceof Mob) {
mobLookAt(target, headRotationSpeed, maxHeadPitch, (Mob) entity);
} else {
if (target instanceof Vector vector) {
Location loc = entity.getEyeLocation().add(vector);
entity.lookAt(loc.getX(), loc.getY(), loc.getZ(), entityAnchor);
Comment on lines +110 to +112
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little suspicious of this. Can you explain + test this case to me and why living entities act different?

} else if (target instanceof LivingEntity targetEntity) {
Location loc = entityAnchor == LookAnchor.EYES ? targetEntity.getEyeLocation() : targetEntity.getLocation();
entity.lookAt(loc.getX(), loc.getY(), loc.getZ(), entityAnchor);
} else if (target instanceof Entity targetEntity) {
Location loc = targetEntity.getLocation();
entity.lookAt(loc.getX(), loc.getY(), loc.getZ(), entityAnchor);
} else if (target instanceof Location location) {
entity.lookAt(location.getX(), location.getY(), location.getZ(), entityAnchor);
}
}
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/main/java/ch/njol/skript/effects/EffLook.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.PaperEntityUtils;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
Expand All @@ -14,9 +13,11 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;

@Name("Look At")
@Description("Forces the mob(s) or player(s) to look at an entity, vector or location. Vanilla max head pitches range from 10 to 50.")
@Description("Forces living entities to look at an entity, vector or location. Vanilla max head pitches range from 10 to 50.")
Comment thread
CJH3139 marked this conversation as resolved.
Outdated
@Example("force the player to look towards event-entity's feet")
@Example("""
on entity explosion:
Expand All @@ -29,18 +30,25 @@
@Since("2.7")
public class EffLook extends Effect {

static {
Skript.registerEffect(EffLook.class,
"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) " +
"%entity%'s (feet:feet|eyes) [(at|with) [head] [rotation] speed %-number%] " +
"[[and] max[imum] [head] pitch %-number%]",
public static void register(SyntaxRegistry registry) {
registry.register(
SyntaxRegistry.EFFECT,
SyntaxInfo.builder(EffLook.class)
.addPatterns(
"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) " +
Comment thread
CJH3139 marked this conversation as resolved.
Outdated
"%entity%'s (feet:feet|eyes) [(at|with) [head] [rotation] speed %-number%] " +
"[[and] max[imum] [head] pitch %-number%]",

"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) " +
"[the] (feet:feet|eyes) of %entity% [(at|with) [head] [rotation] speed %-number%] " +
"[[and] max[imum] [head] pitch %-number%]",
"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) " +
"[the] (feet:feet|eyes) of %entity% [(at|with) [head] [rotation] speed %-number%] " +
"[[and] max[imum] [head] pitch %-number%]",

"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) %vector/location/entity% " +
"[(at|with) [head] [rotation] speed %-number%] [[and] max[imum] [head] pitch %-number%]");
"(force|make) %livingentities% [to] (face [towards]|look [(at|towards)]) %vector/location/entity% " +
"[(at|with) [head] [rotation] speed %-number%] [[and] max[imum] [head] pitch %-number%]"
)
.supplier(EffLook::new)
.build()
);
}

private LookAnchor anchor = LookAnchor.EYES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.skriptlang.skript.bukkit.entity;

import ch.njol.skript.Skript;
import ch.njol.skript.effects.EffLook;
import ch.njol.skript.entity.SimpleEntityData;
import org.bukkit.entity.AbstractNautilus;
import org.skriptlang.skript.addon.AddonModule;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected void loadSelf(SkriptAddon addon) {
}

register(addon,
EffLook::register,
ExprDeathMessage::register
);
}
Expand Down