Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from Sentropic/1.97
Browse files Browse the repository at this point in the history
1.97
  • Loading branch information
Sentropic authored Dec 20, 2020
2 parents 8f4097f + e9c5dd0 commit baaff66
Show file tree
Hide file tree
Showing 26 changed files with 557 additions and 187 deletions.
14 changes: 7 additions & 7 deletions editor/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,8 @@ function TargetLinear()
this.data.push(new AttributeValue("Range", "range", 5, 0)
.setTooltip('The max distance away any target can be in blocks')
);
this.data.push(new AttributeValue("Tolerance", "tolerance", 4, 0)
.setTooltip('How lenient the targeting is. Larger numbers allow easier targeting. It is essentially how wide a cone is which is where you are targeting.')
this.data.push(new AttributeValue("Tolerance", "tolerance", 0, 0)
.setTooltip('How much to expand the potential entity\'s hitbox in all directions, in blocks. This makes it easier to aim')
);
this.data.push(new ListValue("Group", "group", ["Ally", "Enemy", "Both"], "Enemy")
.setTooltip('The alignment of targets to get')
Expand Down Expand Up @@ -972,8 +972,8 @@ function TargetSingle()
this.data.push(new AttributeValue("Range", "range", 5, 0)
.setTooltip('The max distance away any target can be in blocks')
);
this.data.push(new AttributeValue("Tolerance", "tolerance", 4, 0)
.setTooltip('How lenient the targeting is. Larger numbers allow easier targeting. It is essentially how wide a cone is which is where you are targeting.')
this.data.push(new AttributeValue("Tolerance", "tolerance", 0, 0)
.setTooltip('How much to expand the potential entity\'s hitbox in all directions, in blocks. This makes it easier to aim')
);
this.data.push(new ListValue("Group", "group", ["Ally", "Enemy", "Both"], "Enemy")
.setTooltip('The alignment of targets to get')
Expand Down Expand Up @@ -1765,10 +1765,10 @@ function MechanicCommand()
this.description ='Executes a command for each of the targets.';

this.data.push(new StringValue('Command', 'command', '')
.setTooltip('The command to execute')
.setTooltip('The command to execute. {player} = caster\'s name, {target} = target\'s name, {targetUUID} = target\'s UUID (useful if targets are non players), &lc: "{", &rc: "}", &sq: "\'"')
);
this.data.push(new ListValue('Execute Type', 'type', [ 'Console', 'OP' ], 'OP')
.setTooltip('Console: executes the command from the console. OP: Only if the target is a player, will have them execute it while given a temporary OP permission (If server closes in the meantime, the permission might stay, not recommended!!). {player} = caster\'s name, {target} = target\'s name, {targetUUID} = target\'s UUID (useful if targets are non players), &lc: "{", &rc: "}"')
.setTooltip('Console: executes the command from the console. OP: Only if the target is a player, will have them execute it while given a temporary OP permission (If server closes in the meantime, the permission might stay, not recommended!!)')
);
}

Expand Down Expand Up @@ -2229,7 +2229,7 @@ function MechanicMessage()
this.description = 'Sends a message to each player target. To include numbers from Value mechanics, use the filters {<key>} where <key> is the key the value is stored under.'

this.data.push(new StringValue('Message', 'message', 'text')
.setTooltip('The message to display')
.setTooltip('The message to display. {player} = caster\'s name, {target} = target\'s name, {targetUUID} = target\'s UUID (useful if targets are non players), &lc: "{", &rc: "}", &sq: "\'"')
);
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.sucy.skill</groupId>
<artifactId>SkillAPI</artifactId>
<version>s1.96</version>
<version>s1.97</version>
<packaging>jar</packaging>

<name>SkillAPI</name>
Expand Down Expand Up @@ -109,7 +109,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/sucy/skill/SkillAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public void onEnable() {
listen(new DeathListener(), !VersionManager.isVersionAtLeast(11000));
listen(new LingeringPotionListener(), VersionManager.isVersionAtLeast(VersionManager.V1_9_0));
listen(new ExperienceListener(), settings.yieldsEnabled());
listen(new PluginChecker(), true);


// Set up tasks
if (settings.isManaEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sucy/skill/api/player/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.rit.sucy.config.Filter;
import com.rit.sucy.config.FilterType;
import com.rit.sucy.config.parse.DataSection;
import com.sucy.skill.api.TargetHelper;
import com.sucy.skill.api.target.TargetHelper;
import com.rit.sucy.version.VersionManager;
import com.rit.sucy.version.VersionPlayer;
import com.sucy.skill.SkillAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ public void applyLanded() {

/**
* Checks if the projectile collides with a given list of entities
* Returns true if another check should happen, false other wise
*/
protected void checkCollision(final boolean pierce) {
protected boolean checkCollision(final boolean pierce) {
for (LivingEntity entity : getColliding()) {
if (entity == thrower || hit.contains(entity.getEntityId())) {
continue;
Expand All @@ -202,9 +203,10 @@ protected void checkCollision(final boolean pierce) {

if (!pierce) {
cancel();
return;
return false;
}
}
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void run()
if (!isTraveling())
return;

checkCollision(pierce);
if (!checkCollision(pierce)) break;
}

// Particle along path
Expand Down
235 changes: 235 additions & 0 deletions src/main/java/com/sucy/skill/api/target/AABB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
package com.sucy.skill.api.target;

import com.google.common.base.Objects;
import org.bukkit.Location;
import org.bukkit.util.Vector;

/**
* Represents an axix-aligned bounding box.
*
* @author Kristian
*/
public class AABB {
public static class Vec3D {
/**
* Point with the coordinate (1, 1, 1).
*/
public static final Vec3D UNIT_MAX = new Vec3D(1, 1, 1);

/** X coordinate. */
public final double x;
/** Y coordinate. */
public final double y;
/** Z coordinate. */
public final double z;

/**
* Creates a new vector with the given coordinates.
* @param x the x
* @param y the y
* @param z the z
*/
public Vec3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}

/**
* Creates a new vector with the coordinates of the given vector.
* @param v vector to copy.
*/
public Vec3D(Vec3D v) {
this.x = v.x;
this.y = v.y;
this.z = v.z;
}

/**
* Construct a vector from a Bukkit location.
* @param loc - the Bukkit location.
*/
public static Vec3D fromLocation(Location loc) {
return new Vec3D(loc.getX(), loc.getY(), loc.getZ());
}

/**
* Construct a copy of our immutable vector from Bukkit's mutable vector.
* @param v - Bukkit vector.
* @return A copy of the given vector.
*/
public static Vec3D fromVector(Vector v) {
return new Vec3D(v.getX(), v.getY(), v.getZ());
}

/**
* Add vector v and returns result as new vector.
*
* @param v vector to add
* @return result as new vector
*/
public final Vec3D add(Vec3D v) {
return new Vec3D(x + v.x, y + v.y, z + v.z);
}

/**
* Scales vector uniformly and returns result as new vector.
*
* @param s scale factor
*
* @return new vector
*/
public Vec3D scale(double s) {
return new Vec3D(x * s, y * s, z * s);
}

/**
* Normalizes the vector so that its magnitude = 1.
* @return The normalized vector.
*/
public Vec3D normalize() {
double mag = Math.sqrt(x * x + y * y + z * z);

if (mag > 0)
return scale(1.0 / mag);
return this;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Vec3D) {
final Vec3D v = (Vec3D) obj;
return x == v.x && y == v.y && z == v.z;
}
return false;
}

@Override
public int hashCode() {
return Objects.hashCode(x, y, z);
}

public String toString() {
return String.format("{x: %g, y: %g, z: %g}", x, y, z);
}
}

public static class Ray3D extends Vec3D {
public final Vec3D dir;

public Ray3D(Vec3D origin, Vec3D direction) {
super(origin);
dir = direction.normalize();
}

/**
* Construct a 3D ray from a location.
* @param loc - the Bukkit location.
*/
public Ray3D(Location loc) {
this(Vec3D.fromLocation(loc), Vec3D.fromVector(loc.getDirection()));
}

public Vec3D getDirection() {
return dir;
}

public Vec3D getPointAtDistance(double dist) {
return add(dir.scale(dist));
}

public String toString() {
return "origin: " + super.toString() + " dir: " + dir;
}
}

private Vec3D max;
private Vec3D min;

/**
* Creates a new instance from a minimum point and a maximum point.
*/
public AABB(Vec3D min, Vec3D max) {
this.min = min;
this.max = max;
}

/**
* Create a new AABB from a given block.
* @param block - the block.
*/
public AABB(Location block) {
this(Vec3D.fromLocation(block), Vec3D.fromLocation(block).add(Vec3D.UNIT_MAX));
}

public Vec3D getMax() { return max; }
public Vec3D getMin() { return min; }

public void expand(double expand) {
min = min.add(new Vec3D(-expand, -expand, -expand));
max = max.add(new Vec3D(expand, expand, expand));
}

/**
* Calculates intersection with the given ray between a certain distance
* interval.
* <p>
* Ray-box intersection is using IEEE numerical properties to ensure the
* test is both robust and efficient, as described in:
* <br>
* <code>Amy Williams, Steve Barrus, R. Keith Morley, and Peter Shirley: "An
* Efficient and Robust Ray-Box Intersection Algorithm" Journal of graphics
* tools, 10(1):49-54, 2005</code>
*
* @param ray incident ray
* @param minDist
* @param maxDist
* @return intersection point on the bounding box (only the first is
* returned) or null if no intersection
*/
public Vec3D intersectsRay(Ray3D ray, float minDist, double maxDist) {
Vec3D invDir = new Vec3D(1f / ray.dir.x, 1f / ray.dir.y, 1f / ray.dir.z);

boolean signDirX = invDir.x < 0;
boolean signDirY = invDir.y < 0;
boolean signDirZ = invDir.z < 0;

Vec3D bbox = signDirX ? max : min;
double tmin = (bbox.x - ray.x) * invDir.x;
bbox = signDirX ? min : max;
double tmax = (bbox.x - ray.x) * invDir.x;
bbox = signDirY ? max : min;
double tymin = (bbox.y - ray.y) * invDir.y;
bbox = signDirY ? min : max;
double tymax = (bbox.y - ray.y) * invDir.y;

if ((tmin > tymax) || (tymin > tmax)) {
return null;
}
if (tymin > tmin) {
tmin = tymin;
}
if (tymax < tmax) {
tmax = tymax;
}

bbox = signDirZ ? max : min;
double tzmin = (bbox.z - ray.z) * invDir.z;
bbox = signDirZ ? min : max;
double tzmax = (bbox.z - ray.z) * invDir.z;

if ((tmin > tzmax) || (tzmin > tmax)) {
return null;
}
if (tzmin > tmin) {
tmin = tzmin;
}
if (tzmax < tmax) {
tmax = tzmax;
}
if ((tmin < maxDist) && (tmax > minDist)) {
return ray.getPointAtDistance(tmin);
}
return null;
}
}
Loading

0 comments on commit baaff66

Please sign in to comment.