Initial commit

This commit is contained in:
bi0qaw 2017-11-15 21:14:06 +01:00
commit 93b170b404
52 changed files with 4088 additions and 0 deletions

71
pom.xml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.bi0qaw</groupId>
<artifactId>biosphere2</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bensku-repo</id>
<url>https://raw.githubusercontent.com/bensku/mvn-repo/master</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo</url>
</repository>
<repository>
<id>destroystokyo-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>jitpack-repo</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!--Skript-->
<dependency>
<groupId>ch.njol</groupId>
<artifactId>skript</artifactId>
<version>2.2-dev32</version>
<scope>compile</scope>
</dependency>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,74 @@
package io.github.bi0qaw.biosphere;
import io.github.bi0qaw.biosphere.expression.*;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.type.FrameType;
import io.github.bi0qaw.biosphere.util.Frame;
public class Biosphere extends JavaPlugin {
private static Biosphere plugin;
public void onEnable(){
plugin = this;
Skript.registerAddon(this);
new FrameType();
Skript.registerExpression(ExprDegToRad.class, Number.class, ExpressionType.PROPERTY, "%number% [in] rad[ian]");
Skript.registerExpression(ExprRadToDeg.class, Number.class, ExpressionType.PROPERTY, "%number% [in] deg[ree]");
Skript.registerExpression(ExprFrameFromEntity.class, Frame.class, ExpressionType.SIMPLE, new String[]{"frame of %entity%", "%entity%['s] frame"});
Skript.registerExpression(ExprFrameFromYawPitch.class, Frame.class, ExpressionType.SIMPLE, "frame with yaw %number% and pitch %number%");
Skript.registerExpression(ExprFrameYawPitch.class, Number.class, ExpressionType.PROPERTY, "frame (0¦yaw|1¦pitch) of %frame%");
Skript.registerExpression(ExprLocationCircle.class, Location.class, ExpressionType.SIMPLE, "circle[s] at %locations%[ with] radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationCube.class, Location.class, ExpressionType.SIMPLE, "cube[s] at %locations% with radius %number%");
Skript.registerExpression(ExprLocationCubeOutline.class, Location.class, ExpressionType.SIMPLE, "cube[s] outline[s] at %locations% with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationCylinderLoc.class, Location.class, ExpressionType.SIMPLE, "cylinder coordinate[s] at %locations% with radius %number%(,| and) yaw %number%(,| and) height %number%");
Skript.registerExpression(ExprLocationHelix.class, Location.class, ExpressionType.SIMPLE, "heli(x|xes|ces) at %locations% with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationLine.class, Location.class, ExpressionType.SIMPLE, "line[s] from %locations% to %location% with density %number%");
Skript.registerExpression(ExprLocationLineLoc.class, Location.class, ExpressionType.SIMPLE, "line[ar] (coordinate[s]|position[s]|location[s]) %number% from %locations% to %location%");
Skript.registerExpression(ExprLocationLinkAll.class, Location.class, ExpressionType.SIMPLE, "%locations% (linked|connected) with density %number%");
Skript.registerExpression(ExprLocationMidpoint.class, Location.class, ExpressionType.SIMPLE, "[location ]midpoint of %locations%");
Skript.registerExpression(ExprLocationMove.class, Location.class, ExpressionType.SIMPLE, new String[]{"%locations% with center %location% (moved|shifted) to %location%", "%locations% with center %location% (moved|shifted) to %location%"});
Skript.registerExpression(ExprLocationOffset.class, Location.class, ExpressionType.SIMPLE, "%locations% offset by %vectors%");
Skript.registerExpression(ExprLocationPolygon.class, Location.class, ExpressionType.SIMPLE, "polygon[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%");
Skript.registerExpression(ExprLocationPolygonOutline.class, Location.class, ExpressionType.SIMPLE, "polygon[s] outline[s] at %locations% with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationReflection.class, Location.class, ExpressionType.SIMPLE, "%locations% (mirrored|reflected) at %location%[ (in|with) direction [of ]%-vector%]");
Skript.registerExpression(ExprLocationRotate.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around %vector% at %location% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprLocationRotXYZ.class, Location.class, ExpressionType.SIMPLE, "%locations% rotated around (1¦x|2¦y|3¦z)(-| )axis at %location% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprLocationScale.class, Location.class, ExpressionType.SIMPLE, "%locations% scaled at %location% by %number%[ (in|with|and) direction %-vector%]");
Skript.registerExpression(ExprLocationSphere.class, Location.class, ExpressionType.SIMPLE, "sphere[s] at %locations% with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprLocationSphereLoc.class, Location.class, ExpressionType.SIMPLE, "spher(e|ic[al]) (coordinate[s]|position[s]|location[s]) at %locations% with radius %number%(,| and) yaw %number%(,| and) pitch %number%");
Skript.registerExpression(ExprLocationSphereRand.class, Location.class, ExpressionType.SIMPLE, "random sphere[s] at %locations% with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorCircle.class, Vector.class, ExpressionType.SIMPLE, "[vector ]circle with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorCube.class, Vector.class, ExpressionType.SIMPLE, "[vector ]cube with radius %number%");
Skript.registerExpression(ExprVectorCubeOutline.class, Vector.class, ExpressionType.SIMPLE, "[vector ]cube outline with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorHelix.class, Vector.class, ExpressionType.SIMPLE, "[vector ]helix with radius %number%(,| and) height %number%(,| and) step[(height|size)] %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorInFrame.class, Vector.class, ExpressionType.SIMPLE, "[vector ]%vectors% in %frame%");
Skript.registerExpression(ExprVectorLine.class, Vector.class, ExpressionType.SIMPLE, "[vector ]line with length %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorLineBetweenVectors.class, Vector.class, ExpressionType.SIMPLE, "vector line between %vector% and %vector% with density %number%");
Skript.registerExpression(ExprVectorLinkAll.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (linked|connected) with density %number%");
Skript.registerExpression(ExprVectorMidpoint.class, Vector.class, ExpressionType.SIMPLE, "vector midpoint of %vectors%");
Skript.registerExpression(ExprVectorMove.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% moved by %vector%");
Skript.registerExpression(ExprVectorPolygon.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%");
Skript.registerExpression(ExprVectorPolygonOutline.class, Vector.class, ExpressionType.SIMPLE, "[vector ]polygon outline with %integer% (vertex|vertices|vertexes|points)(,| and) radius %number%(,|and) density %number%");
Skript.registerExpression(ExprVectorReflection.class, Vector.class, ExpressionType.SIMPLE, "vector[s] %vectors% (mirrored|reflected) at %vector%[ (in|with) direction [of ]%-vector%]");
Skript.registerExpression(ExprVectorRotate.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around %vector% (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprVectorRotateXYZ.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% rotated around (1¦x|2¦y|3¦z)(-| )axis (with angle|by) %number%[ degree[s]]");
Skript.registerExpression(ExprVectorScale.class, Vector.class, ExpressionType.SIMPLE, "[vector[s] ]%vectors% scaled by %number%[ (in|with|and) direction %-vector%]");
Skript.registerExpression(ExprVectorSphere.class, Vector.class, ExpressionType.SIMPLE, "[vector ]sphere with radius %number%(,| and) density %number%");
Skript.registerExpression(ExprVectorSphereRand.class, Vector.class, ExpressionType.SIMPLE, "[vector ]random sphere with radius %number%(,| and) density %number%");
}
public static Biosphere getPlugin() {
return plugin;
}
}

View File

@ -0,0 +1,49 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Degree to Radian")
@Description("Converts degree to radian")
@Examples({"#returns PI", "set {_num} to 180 in radian" })
public class ExprDegToRad extends SimpleExpression<Number>{
private Expression<Number> degree;
@Override
public Class<? extends Number> getReturnType() {
return Number.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
degree = (Expression<Number>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return degree.toString(e, arg1) + " in radian";
}
@Override
@Nullable
protected Number[] get(Event e) {
return new Double[]{ degree.getSingle(e).doubleValue() * Math.PI / 180.0};
}
}

View File

@ -0,0 +1,57 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.VectorMath;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import io.github.bi0qaw.biosphere.util.Frame;
@Name("Frame of Entity")
@Description("Gives the reference frame of an entity. The reference frame is used to get locations with respect to the entities orientation.")
@Examples({"set {_frame} to frame of player",
"show happy villager at player's head offset by vector 1, 2, 3 in {_frame}",
"#shows a happy villager particle at the location 1 in front, 2 above and 3 blocks to the right of the player's head",
"set {_circle::*} to circle with radius 1 and density 5",
"show happy villager at player's head offset by {_circle::*} in {_frame}",
"#shows a halo around the player's head that follows the movement of the head"})
public class ExprFrameFromEntity extends SimpleExpression<Frame> {
private Expression<Entity> entity;
@Override
protected Frame[] get(Event event) {
Entity e = entity.getSingle(event);
float yaw = e.getLocation().getYaw();
float pitch = e.getLocation().getPitch();
yaw = VectorMath.fromNotchYaw(yaw);
pitch = VectorMath.fromNotchPitch(pitch);
return new Frame[] {new Frame().setFromYawPitch(yaw, pitch)};
}
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Frame> getReturnType() {
return Frame.class;
}
@Override
public String toString(Event event, boolean b) {
return "frame of " + entity.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
entity = (Expression<Entity>) expressions[0];
return true;
}
}

View File

@ -0,0 +1,57 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import io.github.bi0qaw.biosphere.util.Frame;
import io.github.bi0qaw.biosphere.util.VectorMath;
@Name("Frame from Yaw and Pitch")
@Description("Creates a reference frame from a yaw and a pitch.")
@Examples({"set {_frame} to frame with yaw 90 and pitch -45",
"set {_circle::*} to circle with radius 1 and density 5 in {_frame}",
"show happy villager at player's head offset by {_circle::*}",
"#shows a particle circle at the player's head with a yaw of 90 and pitch of -45"})
public class ExprFrameFromYawPitch extends SimpleExpression<Frame> {
Expression<Number> yaw;
Expression<Number> pitch;
@Override
protected Frame[] get(Event event) {
float y = yaw.getSingle(event).floatValue();
float p = pitch.getSingle(event).floatValue();
y = VectorMath.fromSkriptYaw(y);
p = VectorMath.fromSkriptPitch(p);
y = VectorMath.wrapYaw(y);
p = VectorMath.wrapPitch(p);
return new Frame[] {new Frame().setFromYawPitch(y, p)};
}
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Frame> getReturnType() {
return Frame.class;
}
@Override
public String toString(Event event, boolean b) {
return "frame with yaw " + yaw.toString(event, b) + " and pitch " + pitch.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
yaw = (Expression<Number>) expressions[0];
pitch = (Expression<Number>) expressions[1];
return true;
}
}

View File

@ -0,0 +1,109 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import io.github.bi0qaw.biosphere.util.Frame;
import io.github.bi0qaw.biosphere.util.VectorMath;
@Name("Frame Yaw and Pitch")
@Description("Yaw and pitch of a frame. Mainly used to rotate or incline reference frames")
@Examples({"set {_frame} to frame from yaw 90 and pitch -45",
"set {_yaw} to frame yaw of {_frame} #{_yaw} is now equal to 90",
"add 90 to frame yaw of {_frame}",
"set {_yaw} to frame yaw of {_frame} #{_yaw} is now equal to 180"})
public class ExprFrameYawPitch extends SimplePropertyExpression<Frame, Number>{
private int mark;
private final static String[] type = new String[] {"yaw", "pitch"};
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
super.init(expressions, i, kleenean, parseResult);
mark = parseResult.mark;
return true;
}
@Override
protected String getPropertyName() {
return "frame " + type[mark];
}
@Override
public Number convert(Frame frame) {
if (frame != null) {
switch (mark) {
case 0:
return VectorMath.skriptYaw(frame.getYaw());
case 1:
return VectorMath.skriptPitch(frame.getPitch());
default:
break;
}
}
return null;
}
@Override
public Class<? extends Number> getReturnType() {
return Number.class;
}
@Override
public Class<Frame>[] acceptChange(Changer.ChangeMode mode) {
if ((mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) && getExpr().isSingle() && Changer.ChangerUtils.acceptsChange(getExpr(), Changer.ChangeMode.SET, Frame.class))
return new Class[] { Number.class };
return null;
}
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
Frame f = getExpr().getSingle(e);
if (f == null){
return;
}
float v = ((Number) delta[0]).floatValue();
float yaw = f.getYaw();
float pitch = f.getPitch();
switch (mode) {
case REMOVE:
v = -v;
case ADD:
if (mark == 0){
yaw += v;
} else if (mark == 1){
pitch -= v; //negative because skript pitch is upside down and we are adding the value to the non-skript pitch
}
yaw = VectorMath.wrapYaw(yaw);
pitch = VectorMath.wrapPitch(pitch);
f = f.setFromYawPitch(yaw, pitch);
getExpr().change(e, new Frame[]{f}, Changer.ChangeMode.SET);
break;
case SET:
if (mark == 0){
yaw = VectorMath.wrapYaw(v);
yaw = VectorMath.fromSkriptYaw(yaw);
} else if (mark == 1){
pitch = VectorMath.wrapPitch(v);
pitch = VectorMath.fromSkriptPitch(pitch);
}
f = f.setFromYawPitch(yaw, pitch);
getExpr().change(e, new Frame[]{f}, Changer.ChangeMode.SET);
break;
case REMOVE_ALL:
case DELETE:
case RESET:
assert false;
}
}
}

View File

@ -0,0 +1,59 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Circle")
@Description("Creates a list of locations in the shape of a circle. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples("show happy villager at circle at player's head with radius 1 and density 5")
public class ExprLocationCircle extends SimpleExpression<Location> {
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "circle at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getCircle(locations.getArray(e), r, d);
}
}

View File

@ -0,0 +1,55 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Cube")
@Description("Creates a list of locations in the shape of a cube (only the corners!). To get a list of locations including the cube edges use cube outline.")
@Examples("show happy villager at cube at player's head with radius 1")
public class ExprLocationCube extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "cube at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
return LocationLib.getCube(locations.getArray(e), r);
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Cube Outline")
@Description("Creates a list of locations in the shape of a cube, including the corners and vertices of the cube. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples("show happy villager at cube outline at player's head with radius 1 and density 5")
public class ExprLocationCubeOutline extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "cube outline at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getCubeOutline(locations.getArray(e), r, d);
}
}

View File

@ -0,0 +1,62 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorMath;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Cylinder Coordinate")
@Description("Gives locations in a cylindrical coordinate system.")
@Examples({"set {_loc} to cylinder coordinate at player with radius 5, yaw 90 and height 5",
"#gives the location 5 blocks in the negative x-direction and 5 blocks above the player"})
public class ExprLocationCylinderLoc extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> yaw;
private Expression<Number> height;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
yaw = (Expression<Number>) expr[2];
height = (Expression<Number>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "cylinder coordinate at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + ", yaw " + yaw.toString(arg0, arg1) + " and height " + height.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
float y = yaw.getSingle(e).floatValue();
double h = height.getSingle(e).doubleValue();
y = VectorMath.fromSkriptYaw(y);
y = VectorMath.wrapYaw((y));
return LocationLib.getCylindricalCoordinate(locations.getArray(e), r, y, h);
}
}

View File

@ -0,0 +1,65 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Helix")
@Description("Creates a list of locations in the shape of a helix. The step parameter determines how many blocks the helix will go upwards in one rotation. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"show happy villager at helix at player's head with radius 2, height 3, step 1 and density 5",
"#shows a helix at the player's head with a height of 3 blocks that makes a total of 3 rotations"})
public class ExprLocationHelix extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> height;
private Expression<Number> step;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
height = (Expression<Number>) expr[2];
step = (Expression<Number>) expr[3];
density = (Expression<Number>) expr[4];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "helix at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + ", height " + height.toString(arg0, arg1) + ", step " + step.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double h = height.getSingle(e).doubleValue();
double s = step.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getHelix(locations.getArray(e), r, h, s, d);
}
}

View File

@ -0,0 +1,61 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
@Name("Location Line")
@Description("Creates a list of locations in the shape of a line. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples("show happy villager at line between player's head and location 5 in front of player's head with density 5")
public class ExprLocationLine extends SimpleExpression<Location>{
private Expression<Location> location1;
private Expression<Location> location2;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
location1 = (Expression<Location>) expr[0];
location2 = (Expression<Location>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "line from " + location1.toString(arg0, arg1) + " to " + location2.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double d = density.getSingle(e).doubleValue();
return LocationLib.getLine(location1.getArray(e), location2.getSingle(e), d);
}
}

View File

@ -0,0 +1,61 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import io.github.bi0qaw.biosphere.util.VectorMath;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Line Coordinate")
@Description("Gives a location on the line between two locations. The number parameter describes how far the point is from the first location. A value of 0 corresponds the the start (first location). A value of 1 corresponds to the end (location 2). 0.5 is the midpoint between the two locations.")
@Examples({"show happy villager at line coordinate 0.2 between player and location 10 in front of player",
"#shows a particle 2 blocks in front of the player"})
public class ExprLocationLineLoc extends SimpleExpression<Location> {
private Expression<Number> point;
private Expression<Location> location1;
private Expression<Location> location2;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return location1.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
point = (Expression<Number>) expr[0];
location1 = (Expression<Location>) expr[1];
location2 = (Expression<Location>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "line coordinate " + point.toString(arg0, arg1) + " from " + location1.toString(arg0, arg1) + " to " + location2.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double p = point.getSingle(e).doubleValue();
return LocationLib.getLineCoordinate(location1.getArray(e), location2.getSingle(e), p);
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Link All")
@Description("Creates a list of locations linking multiple locations with lines. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_circle::*} to circle at player with radius 5 and density 0.2",
"#gets the points in the shape of a circle around the player",
"set {_linked::*} to {_circle::*} linked with density 2",
"#connects all points on the circle with lines",
"show happy villager at {_linked::*}"})
public class ExprLocationLinkAll extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return locations.toString(arg0, arg1) + " linked with density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double d = density.getSingle(e).doubleValue();
return LocationLib.linkAll(locations.getArray(e), d);
}
}

View File

@ -0,0 +1,54 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Midpoint")
@Description("Gives the midpoint between locations.")
@Examples({"show happy villager at midpoint between player and location 5 in front of player",
"#shows a particle at the location 2.5 in front of the player"})
public class ExprLocationMidpoint extends SimpleExpression<Location>{
private Expression<Location> locations;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "midpoint of " + locations.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
return new Location[] {LocationLib.midpoint(locations.getArray(e))};
}
}

View File

@ -0,0 +1,59 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Move")
@Description("Moves a list of locations from one location to another.")
@Examples({"set {_circle::*} to circle at player with radius 1 and density 5",
"set {_moved::*} to {_circle::*} with center player moved to location 5 in front of player",
"show happy villager at {_moved::*}"})
public class ExprLocationMove extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Location> center;
private Expression<Location> point;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
center = (Expression<Location>) expr[1];
point = (Expression<Location>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "move " + locations.toString(arg0, arg1) + " with center " + center.toString(arg0, arg1) + " to " + locations.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
Vector delta = point.getSingle(e).toVector().subtract(center.getSingle(e).toVector());
return LocationLib.offset(locations.getArray(e), delta);
}
}

View File

@ -0,0 +1,53 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.LocationLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
@Name("Location Offset")
@Description("Calculates the offset of locations from vectors.")
@Examples({"set {_circle::*} to circle with radius 1 and density 5",
"#creates a list of vectors in the shape of a circle",
"set {_offset::*} to player's head offset by {_circle::*}",
"#gives a list of locations around the player's head in the shape of a circle",
"show happy villager at {_offset::*}"})
public class ExprLocationOffset extends SimpleExpression<Location> {
private Expression<Location> locations;
private Expression<Vector> vectors;
@Override
public boolean isSingle() {
return locations.isSingle() && vectors.isSingle();
}
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public String toString(Event event, boolean b) {
return locations.toString() + " offset by " + vectors.toString();
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
locations = (Expression<Location>) expressions[0];
vectors = (Expression<Vector>) expressions[1];
return true;
}
@Override
protected Location[] get(Event event) {
return LocationLib.offset(locations.getArray(event), vectors.getAll(event));
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Polygon")
@Description("Creates a list of locations in the shape of a polygon (only the corners!). If you want a polygon with edges use polygon outline.")
@Examples({"set {_polygon::*} to polygon at player with 3 points and radius 3",
"show happy villager at {_polygon::*}",
"#shows particles in the shape of a triangle at the player"})
public class ExprLocationPolygon extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Integer> points;
private Expression<Number> radius;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
points = (Expression<Integer>) expr[1];
radius = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "polygon at " + locations.toString(arg0, arg1) + " with " + points.toString(arg0, arg1) + " points and radius " + radius.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
int p = points.getSingle(e).intValue();
double r = radius.getSingle(e).doubleValue();
return LocationLib.getPolygon(locations.getArray(e), p, r);
}
}

View File

@ -0,0 +1,62 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Polygon Outline")
@Description("Creates a list of locations in the shape of a polygon including corners and edges. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples("show happy villager at polygon outline at player with 6 points, radius 3 and density 5")
public class ExprLocationPolygonOutline extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Integer> points;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
points = (Expression<Integer>) expr[1];
radius = (Expression<Number>) expr[2];
density = (Expression<Number>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return null;
}
@Override
@Nullable
protected Location[] get(Event e) {
int p = points.getSingle(e).intValue();
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getPolygonOutline(locations.getArray(e), p, r, d);
}
}

View File

@ -0,0 +1,69 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Reflection")
@Description("Mirrors locations in another location. The direction parameter applies an additional scaling for each axis.")
@Examples({"set {_point} to location 5 in front of player mirrored at player",
"show happy villager at {_point}",
"#shows a particle 5 blocks behind the player"})
public class ExprLocationReflection extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Location> point;
private Expression<Vector> direction;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult parseResult) {
locations = (Expression<Location>) expr[0];
point = (Expression<Location>) expr[1];
direction = (Expression<Vector>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
if (direction == null) {
return locations.toString(e, arg1) + " reflected at " + point.toString(e, arg1);
}
else {
return locations.toString(e, arg1) + " reflected at " + point.toString(e, arg1) + " in direction " + direction.toString(e, arg1);
}
}
@Override
@Nullable
protected Location[] get(Event e) {
if(direction == null) {
return LocationLib.pointReflection(locations.getArray(e), point.getSingle(e));
}
else {
return LocationLib.reflection(locations.getArray(e), point.getSingle(e), direction.getSingle(e));
}
}
}

View File

@ -0,0 +1,70 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Rotate XYZ")
@Description("Rotates locations around a rotation center and rotation axis by an angle.")
@Examples({"set {_point} to location 5 in front of player",
"set {_point} to {_point} rotated around y-axis at player with angle 180"})
public class ExprLocationRotXYZ extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Location> center;
private Expression<Number> angle;
private int axis;
private String[] axisStr = new String[] {"x", "y", "z"};
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult parseResult) {
locations = (Expression<Location>) expr[0];
center = (Expression<Location>) expr[1];
angle = (Expression<Number>) expr[2];
axis = parseResult.mark;
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return locations.toString(e, arg1) + " rotated around " + axisStr[axis] + "-axis at " + center.toString(e, arg1) + " with angle " + angle.toString(e, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and LocationLib anti-clockwise rotation
if (axis == 1) {
return LocationLib.rotateX(locations.getArray(e), center.getSingle(e), a);
}
else if (axis == 2) {
return LocationLib.rotateY(locations.getArray(e), center.getSingle(e), a);
}
else {
return LocationLib.rotateZ(locations.getArray(e), center.getSingle(e), a);
}
}
}

View File

@ -0,0 +1,66 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Rotate")
@Description("Rotates locations around a rotation center and a rotation axis by an angle.")
@Examples({"set {_point} to location 5 in front of player",
"set {_point} to {_point} rotated around vector 0, 1, 0 at player with angle 180",
"show happy villager at {_point}",
"#shows a particle at the location 5 behind the player",
"#vector 0, 1, 0 creates a vector along the y-axis, which is used as the rotation axis"})
public class ExprLocationRotate extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Vector> axis;
private Expression<Location> center;
private Expression<Number> angle;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, SkriptParser.ParseResult parseResult) {
locations = (Expression<Location>) expr[0];
axis = (Expression<Vector>) expr[1];
center = (Expression<Location>) expr[2];
angle = (Expression<Number>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return locations.toString(arg0, arg1) + " rotated around " + axis.toString(arg0, arg1) + " at " + center.toString(arg0, arg1) + " with angle " + angle.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and LocationLib anti-clockwise rotation
Vector ax = axis.getSingle(e).clone().normalize();
return LocationLib.rotate(locations.getArray(e), center.getSingle(e), ax, a);
}
}

View File

@ -0,0 +1,78 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.util.Vector;
@Name("Location Scale")
@Description("Scales locations from a center by a scaling factor. The direction parameter adds an additional scaling along the x-, y- and z-axis.")
@Examples({"set {_circle::*} to circle at player with radius 1 and density 5",
"set {_bigcircle::*} to {_circle::*} scaled at player by 2",
"#Makes the circle 2 times bigger.",
"set {_ellipse::*} to {_circle::*} scaled at player by 1 in direction vector 1, 1, 2",
"#Makes the circle 2 times bigger in the z-direction but does not change the x- and y-coordinates. This creates an ellipse.",
"show happy villager at {_circle::*}",
"show happy villager at {_bigcircle::*}",
"show happy villager at {_ellipse::*}"})
public class ExprLocationScale extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Location> center;
private Expression<Number> factor;
private Expression<Vector> direction;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult parseResult) {
locations = (Expression<Location>) expr[0];
center = (Expression<Location>) expr[1];
factor = (Expression<Number>) expr[2];
direction = (Expression<Vector>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
if (direction == null) {
return locations.toString(arg0, arg1) + " scaled with center " + center.toString(arg0, arg1) + " by " + factor.toString(arg0, arg1);
}
else {
return locations.toString(arg0, arg1) + " scaled with center " + center.toString(arg0, arg1) + " by " + factor.toString(arg0, arg1) + " in direction " + direction.toString(arg0, arg1);
}
}
@Override
@Nullable
protected Location[] get(Event e) {
double f = factor.getSingle(e).doubleValue();
if (direction == null) {
return LocationLib.scale(locations.getArray(e), center.getSingle(e), f);
}
else {
return LocationLib.scaleDirectional(locations.getArray(e), center.getSingle(e), direction.getSingle(e), f);
}
}
}

View File

@ -0,0 +1,59 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Sphere")
@Description("Creates a list of locations in the shape of a sphere. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples("show happy villager at sphere at player with radius 1 and density 5")
public class ExprLocationSphere extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "sphere at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getSphere(locations.getArray(e), r, d);
}
}

View File

@ -0,0 +1,69 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import io.github.bi0qaw.biosphere.util.VectorMath;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Sphere Coordinate")
@Description("Gives locations in a spherical coordinate system.")
@Examples({"set {_loc} to spherical coordinate at player with radius 3, yaw 90 and pitch -45",
"show happy villager at {_loc}",
"#shows a particle at the location 3 in the negative x direction (because of yaw = 90) and a little bit above the player (because of pitch = -45)"})
public class ExprLocationSphereLoc extends SimpleExpression<Location>{
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> yaw;
private Expression<Number> pitch;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return locations.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
yaw = (Expression<Number>) expr[2];
pitch = (Expression<Number>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "sphere coordinate at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1) + ", yaw " + yaw.toString(arg0, arg1) + " and pitch " + pitch.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
float y = yaw.getSingle(e).floatValue();
float p = pitch.getSingle(e).floatValue();
y = VectorMath.fromSkriptYaw(y);
y = VectorMath.wrapYaw(y + 180);
p = VectorMath.fromSkriptPitch(p);
p = VectorMath.wrapPitch(p);
p = p - 90;
return LocationLib.getSphericalCoordinates(locations.getArray(e), r, y, p);
}
}

View File

@ -0,0 +1,58 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import io.github.bi0qaw.biosphere.util.LocationLib;
import io.github.bi0qaw.biosphere.util.TrigLib;
import org.bukkit.Location;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Location Random Sphere")
@Description("Creates a list of locations in the shape of a sphere. The locations are randomly distributed on the sphere surface.")
@Examples("show happy villager at random sphere at player with radius 1 and density 5")
public class ExprLocationSphereRand extends SimpleExpression<Location> {
private Expression<Location> locations;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
locations = (Expression<Location>) expr[0];
radius = (Expression<Number>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "random sphere at " + locations.toString(arg0, arg1) + " with density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Location[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return LocationLib.getRandomSphere(locations.getArray(e), r, d);
}
}

View File

@ -0,0 +1,50 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
@Name("Radian to Degree")
@Description("Converts radian to degree")
@Examples({"set {_num} to 3.14159 in degree",
"#{_num} is now equal to 180"})
public class ExprRadToDeg extends SimpleExpression<Number>{
private Expression<Number> radian;
@Override
public Class<? extends Number> getReturnType() {
return Number.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
radian = (Expression<Number>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return radian.toString(e, arg1) + " in degree";
}
@Override
@Nullable
protected Number[] get(Event e) {
return new Double[]{ radian.getSingle(e).doubleValue() * 180 / Math.PI};
}
}

View File

@ -0,0 +1,55 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Circle")
@Description("Creates a list of vectors in the shape of a circle")
@Examples({"set {_circle::*} to circle with radius 1 and density 5",
"show happy villager at player's head offset by {_circle::*}"})
public class ExprVectorCircle extends SimpleExpression<Vector> {
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "circle with radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
int n = (int) (radius.getSingle(e).doubleValue() * 2 * Math.PI * density.getSingle(e).doubleValue());
double r = radius.getSingle(e).doubleValue();
return VectorLib.getPolygon(n, r);
}
}

View File

@ -0,0 +1,52 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Cube")
@Description("Creates a list of vectors in the shape of a cube (only the corners!). To get a list of locations including the cube edges use cube outline.")
@Examples({"set {_cube::*} to cube with radius 1",
"show happy villager at player's head offset by {_cube::*}"})
public class ExprVectorCube extends SimpleExpression<Vector>{
private Expression<Number> radius;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "cube with radius " + radius.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
return VectorLib.getCube(r);
}
}

View File

@ -0,0 +1,53 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Cube Outline")
@Description("Creates a list of vectors in the shape of a polygon including corners and edges. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_cubeoutline::*} to cube outline with radius 1 and density 5",
"show happy villager at player's head offset by {_cubeoutline::*}"})
public class ExprVectorCubeOutline extends SimpleExpression<Vector> {
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "cube outline with radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getCubeOutline(r, d);
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Helix")
@Description("Creates a list of vectors in the shape of a helix. The step parameter determines how many blocks the helix will go upwards in one rotation. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_helix::*} to helix with radius 2, height 3, step 1 and density 5",
"show happy villager at player's head offset by {_helix::*}"})
public class ExprVectorHelix extends SimpleExpression<Vector>{
private Expression<Number> radius;
private Expression<Number> height;
private Expression<Number> step;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
height = (Expression<Number>) expr[1];
step = (Expression<Number>) expr[2];
density = (Expression<Number>) expr[3];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "helix with radius " + radius.toString(arg0, arg1) + ", height " + height.toString(arg0, arg1) + ", step " + step.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double h = height.getSingle(e).doubleValue();
double s = step.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getHelix(r, h, s, d);
}
}

View File

@ -0,0 +1,59 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.Frame;
@Name("Vector in Frame")
@Description("Converts a vector in a reference frame to the standard Minecraft coordinates.")
@Examples({"set {_vector} to vector 5, 0, 0 in frame of player",
"#Gives a vector that points 5 blocks in the player's direction",
"set {_circle::*} to circle with radius 1 and density 5 in frame of player",
"#Gives a list of vectors in the shape of a circle around the player's head with the correct yaw and pitch"})
public class ExprVectorInFrame extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Frame> frame;
@Override
protected Vector[] get(Event event) {
Frame f = frame.getSingle(event);
Vector[] v = vectors.getArray(event);
Vector[] transformed = new Vector[v.length];
int i = 0;
for (Vector vec: v) {
transformed[i] = f.transform(vec.clone());
i++;
}
return transformed;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public String toString(Event event, boolean b) {
return vectors.toString(event, b) + " in " + frame.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expressions[0];
frame = (Expression<Frame>) expressions[1];
return true;
}
}

View File

@ -0,0 +1,56 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Line")
@Description("Creates a list of vectors in the shape of a line. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_line::*} to line with length 1 and density 5",
"show happy villager at player offset by {_line::*}",
"#shows a particle line that goes from the player to the location 1 block in the x-direction from the player"})
public class ExprVectorLine extends SimpleExpression<Vector> {
private Expression<Number> length;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
length = (Expression<Number>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "line with length " + length.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
double l = length.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getLine(l, d);
}
}

View File

@ -0,0 +1,53 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.bi0qaw.biosphere.util.VectorLib;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
@Name("Vector Line Between Vectors")
@Description("Creates a list of vectors in the shape of a line between the two given vectors. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_line::*} to vector line between vector 1, 2, 3 and vector 3, 2, 1",
"show happy villager at player offset by {_line::*}"})
public class ExprVectorLineBetweenVectors extends SimpleExpression<Vector> {
private Expression<Vector> vector1;
private Expression<Vector> vector2;
private Expression<Number> density;
@Override
public boolean isSingle() {
return false;
}
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public String toString(Event event, boolean b) {
return "vector line between " + vector1.toString(event, b) + " and " + vector2.toString(event, b) + " with density " + density.toString(event, b);
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
vector1 = (Expression<Vector>) expressions[0];
vector2 = (Expression<Vector>) expressions[1];
density = (Expression<Number>) expressions[2];
return true;
}
@Override
protected Vector[] get(Event event) {
double d = density.getSingle(event).doubleValue();
return VectorLib.getLine(vector1.getSingle(event), vector2.getSingle(event), d);
}
}

View File

@ -0,0 +1,55 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Link All")
@Description("Creates a list of vectors linking multiple vectors with lines. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_circle::*} to circle with radius 5 and density 0.2",
"set {_linked::*} to {_circle::*} linked with density 2",
"#connects all points on the circle with lines",
"show happy villager at player offset by {_linked::*}"})
public class ExprVectorLinkAll extends SimpleExpression<Vector>{
private Expression<Vector> vectors;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
vectors = (Expression<Vector>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "all vectors " + vectors.toString() + " linked with density " + density.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
return VectorLib.linkAll(vectors.getArray(e), density.getSingle(e).doubleValue());
}
}

View File

@ -0,0 +1,52 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Midpoint")
@Description("Gives the midpoint between vectors.")
@Examples({"set {_circle::*} to circle with radius 1 and density 5",
"set {_midpoint} to vector midpoint of {_circle::*}",
"#{_midpoint} is a vector pointing to the center of the circle"})
public class ExprVectorMidpoint extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
vectors = (Expression<Vector>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "vector midpoint of " + vectors.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
return new Vector[] {VectorLib.midpoint(vectors.getArray(e))};
}
}

View File

@ -0,0 +1,59 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Offset")
@Description("Offset vectors by other vectors.")
@Examples({"set {_circle::*} to circle with radius 1 and density 5",
"set {_offset::*} to {_circle::*} offset by vector 1, 2, 3",
"#Moves the circle from the origin (vector 0, 0, 0) to the position at 1, 2, 3"})
public class ExprVectorMove extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Vector> offset;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
vectors = (Expression<Vector>) expr[0];
offset = (Expression<Vector>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return vectors.toString() + " moved by " + offset.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
Vector[] o = offset.getAll(e);
Vector totalOffset = new Vector();
for (Vector v: o) {
totalOffset.add(v);
}
return VectorLib.offset(vectors.getArray(e).clone(), totalOffset);
}
}

View File

@ -0,0 +1,56 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Polygon")
@Description("Creates a list of vectors in the shape of a polygon (only the corners!). If you want a polygon with edges use polygon outline.")
@Examples({"set {_polygon::*} to polygon with 3 points and radius 3",
"show happy villager at player offset by {_polygon::*}",
"#shows particles in the shape of a triangle at the player"})
public class ExprVectorPolygon extends SimpleExpression<Vector>{
private Expression<Integer> vertices;
private Expression<Number> radius;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
vertices = (Expression<Integer>) expr[0];
radius = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "vector polygon with " + vertices.toString() + " vertices and radius " + radius.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
int p = vertices.getSingle(e).intValue();
double r = radius.getSingle(e).doubleValue();
return VectorLib.getPolygon(p, r);
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Polygon Outline")
@Description("Creates a list of vectors in the shape of a polygon including corners and edges. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_polyoutline::*} to polygon outline with 6 points, radius 3 and density 5",
"show happy villager at player offset by {_polygonoutline::*}",
"#shows particles in the shape of a hexagon (6 points) at the player"})
public class ExprVectorPolygonOutline extends SimpleExpression<Vector> {
private Expression<Integer> vertices;
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
vertices = (Expression<Integer>) expr[0];
radius = (Expression<Number>) expr[1];
density = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "polygon outline with " + vertices.toString(arg0, arg1) + " vertices, radius " + radius.toString(arg0, arg1) + " and density " + density.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
int v = vertices.getSingle(e).intValue();
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getPolygonOutline(v, r, d);
}
}

View File

@ -0,0 +1,60 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Reflection")
@Description("Mirrors vectors in another vector. The direction parameter applies an additional scaling for each axis.")
@Examples({"set {_point} to vector 1, 2, 3 mirrored at vector 0, 0, 0",
"#{_point} is now equal to the vector -1, -2, -3"})
public class ExprVectorReflection extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Vector> center;
private Expression<Vector> direction;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expr[0];
center = (Expression<Vector>) expr[1];
direction = (Expression<Vector>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return vectors.toString() + " mirrored at " + center.toString() + " in direction " + direction.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
if (direction == null) {
return VectorLib.pointReflection(vectors.getArray(e).clone(), center.getSingle(e));
}
else {
return VectorLib.reflection(vectors.getArray(e).clone(), center.getSingle(e), direction.getSingle(e));
}
}
}

View File

@ -0,0 +1,62 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Rotate")
@Description("Rotates vectors around a rotation center and a rotation axis by an angle.")
@Examples({"set {_point} to vector 1, 2, 3",
"set {_point} to {_point} rotated around vector 0, 1, 0 at player with angle 180",
"#{_point} is now equal to the vector -1, 2, -3",
"#vector 0, 1, 0 creates a vector along the y-axis, which is used as the rotation axis"})
public class ExprVectorRotate extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Vector> axis;
private Expression<Number> angle;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expr[0];
axis = (Expression<Vector>) expr[1];
angle = (Expression<Number>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return vectors.toString(arg0, arg1) + " rotated around " + axis.toString(arg0, arg1) + " with angle " + angle.toString(arg0, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation
Vector ax = axis.getSingle(e).clone().normalize();
return VectorLib.rotate(vectors.getArray(e).clone(), ax, a);
}
}

View File

@ -0,0 +1,68 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Rotate XYZ")
@Description("Rotates vectors around a rotation center and rotation axis by an angle.")
@Examples({"set {_point} to vector 1, 2, 3",
"set {_point} to {_point} rotated around y-axis at player with angle 180",
"#{_point} is now equal to the vector -1, 2, -3"})
public class ExprVectorRotateXYZ extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Number> angle;
private int axis;
private static final String[] axisStr = new String[] {"x", "y", "z"};
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expr[0];
angle = (Expression<Number>) expr[1];
axis = parseResult.mark;
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return vectors.toString(e, arg1) + " rotated around " + axisStr[axis] + "-axis with angle " + angle.toString(e, arg1);
}
@Override
@Nullable
protected Vector[] get(Event e) {
float a = angle.getSingle(e).floatValue();
a = -a; //Skript uses clockwise and VectorMath anti-clockwise rotation
if (axis == 1) {
return VectorLib.rotateX(vectors.getArray(e).clone(), a);
}
else if (axis == 2) {
return VectorLib.rotateY(vectors.getArray(e).clone(), a);
}
else {
return VectorLib.rotateZ(vectors.getArray(e).clone(), a);
}
}
}

View File

@ -0,0 +1,68 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Scale")
@Description("Scales vectors by a scaling factor and an optional direction. The direction parameter adds an additional scaling along the x-, y- and z-axis.")
@Examples({"set {_circle::*} to circle with radius 1 and density 5",
"set {_bigcircle::*} to {_circle::*} scaled by 2",
"#Makes the circle 2 times bigger.",
"set {_ellipse::*} to {_circle::*} scaled by 1 in direction vector 1, 1, 2",
"#Makes the circle 2 times bigger in the z-direction but does not change the x- and y-coordinates. This creates an ellipse.",
"show happy villager at player offset by {_circle::*}",
"show happy villager at player offset by {_bigcircle::*}",
"show happy villager at player offset by {_ellipse::*}"})
public class ExprVectorScale extends SimpleExpression<Vector> {
private Expression<Vector> vectors;
private Expression<Number> factor;
private Expression<Vector> direction;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return vectors.isSingle();
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult parseResult) {
vectors = (Expression<Vector>) expr[0];
factor = (Expression<Number>) expr[1];
direction = (Expression<Vector>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return vectors.toString() + " scaled by " + factor.toString() + " in direction " + direction.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
double f = factor.getSingle(e).doubleValue();
if (direction == null) {
return VectorLib.scale(vectors.getArray(e).clone(), f);
}
else {
return VectorLib.scaleDirectional(vectors.getArray(e).clone(), direction.getSingle(e), f);
}
}
}

View File

@ -0,0 +1,55 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Sphere")
@Description("Creates a list of vectors in the shape of a sphere. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block.")
@Examples({"set {_sphere::*} to sphere with radius 1 and density 5",
"show happy villager at player offset by {_sphere::*}"})
public class ExprVectorSphere extends SimpleExpression<Vector> {
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "sphere with radius " + radius.toString() + " and density " + density.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getSphere(r, d);
}
}

View File

@ -0,0 +1,55 @@
package io.github.bi0qaw.biosphere.expression;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import io.github.bi0qaw.biosphere.util.VectorLib;
import javax.annotation.Nullable;
@Name("Vector Random Sphere")
@Description("Creates a list of vectors in the shape of a sphere. The locations are randomly distributed on the sphere surface.")
@Examples({"set {_sphere::*} to random sphere with radius 1 and density 5",
"show happy villager at player offset by {_sphere::*}"})
public class ExprVectorSphereRand extends SimpleExpression<Vector> {
private Expression<Number> radius;
private Expression<Number> density;
@Override
public Class<? extends Vector> getReturnType() {
return Vector.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) {
radius = (Expression<Number>) expr[0];
density = (Expression<Number>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event arg0, boolean arg1) {
return "random sphere with radius " + radius.toString() + " and density " + density.toString();
}
@Override
@Nullable
protected Vector[] get(Event e) {
double r = radius.getSingle(e).doubleValue();
double d = density.getSingle(e).doubleValue();
return VectorLib.getRandomSphere(r, d);
}
}

View File

@ -0,0 +1,114 @@
package io.github.bi0qaw.biosphere.type;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import ch.njol.yggdrasil.Fields;
import io.github.bi0qaw.biosphere.util.Frame;
import io.github.bi0qaw.biosphere.util.VectorMath;
import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FrameType {
public FrameType(){}
static {
Classes.registerClass(new ClassInfo<Frame>(Frame.class, "frame")
.user("frames?")
.name("Frame")
.description("Reference frame that can be used to get vectors relative to some direction.")
.usage(new String[]{"frame of %entity%", "frame with yaw %number% and pitch %number%"})
.examples(new String[]{"set {_frame} to frame of player", "set {_circle::*} to circle with radius 1 and density 5",
"show happy villager at player's head offset by {_circle::*} in frame of player",
"#shows a particle circle around the player's head with the yaw and pitch of the player"})
.defaultExpression(new EventValueExpression<Frame>(Frame.class))
.parser(new Parser<Frame>() {
private final Pattern parsePattern = Pattern.compile("frame:(-?\\d+(\\.\\d+)?),(-?\\d+(\\.\\d+)?)"
, Pattern.CASE_INSENSITIVE);
@Override
public Frame parse(String s, ParseContext parseContext) {
final Matcher m = parsePattern.matcher(s);
if (m.matches()) {
float yaw = VectorMath.fromSkriptYaw(Float.parseFloat(m.group(1)));
float pitch = VectorMath.fromSkriptPitch(Float.parseFloat(m.group(3)));
return new Frame().setFromYawPitch(yaw, pitch);
}
return null;
}
@Override
public boolean canParse(ParseContext context) {
return (context == ParseContext.COMMAND || context == ParseContext.EVENT || context == ParseContext.SCRIPT);
}
@Override
public String toString(Frame f, int i) {
float yaw = VectorMath.skriptYaw(f.getYaw());
float pitch = VectorMath.skriptPitch(f.getPitch());
return "frame:yaw: " + Skript.toString(yaw) + ", pitch: " + Skript.toString(pitch);
}
@Override
public String toVariableNameString(Frame f) {
float yaw = VectorMath.skriptYaw(f.getYaw());
float pitch = VectorMath.skriptPitch(f.getPitch());
return "frame:" + Skript.toString(yaw) + "," + Skript.toString(pitch);
}
@Override
public String getVariableNamePattern() {
return "frame:(-?\\d+(\\.\\d+)?),(-?\\d+(\\.\\d+)?)";
}
@Override
public String getDebugMessage(Frame f) {
float yaw = VectorMath.skriptYaw(f.getYaw());
float pitch = VectorMath.skriptPitch(f.getPitch());
return "frame:yaw=" + Skript.toString(yaw) + ",pitch=" + Skript.toString(pitch);
}
})
.serializer(new Serializer<Frame>() {
@Override
public Fields serialize(Frame f) throws NotSerializableException {
final Fields fields = new Fields();
float yaw = VectorMath.skriptYaw(f.getYaw());
float pitch = VectorMath.skriptPitch(f.getPitch());
fields.putPrimitive("yaw", yaw);
fields.putPrimitive("pitch", pitch);
return fields;
}
@Override
public void deserialize(Frame f, Fields fields) throws StreamCorruptedException, NotSerializableException {
assert false;
}
@Override
protected Frame deserialize(Fields f) throws StreamCorruptedException, NotSerializableException {
float yaw = VectorMath.fromSkriptYaw(f.getPrimitive("yaw", float.class));
float pitch = VectorMath.fromSkriptPitch(f.getPrimitive("pitch", float.class));
return new Frame().setFromYawPitch(yaw, pitch);
}
@Override
public boolean mustSyncDeserialization() {
return false;
}
@Override
protected boolean canBeInstantiated() {
return false;
}
})
);
}
}

View File

@ -0,0 +1,75 @@
package io.github.bi0qaw.biosphere.util;
import org.bukkit.util.Vector;
public class Frame implements Cloneable {
private static Vector tempv1 = new Vector();
private Vector u;
private Vector v;
private Vector w;
public Frame() {
this.u = new Vector(1, 0, 0);
this.v = new Vector(0, 1, 0);
this.w = new Vector(0, 0, 1);
}
public Frame setFromFrame(Frame f) {
this.u = f.getU().clone();
this.v = f.getV().clone();
this.w = f.getW().clone();
return this;
}
public Frame setFromYawPitch(float yaw, float pitch ) {
this.u = VectorMath.fromYawPitch(yaw, pitch);
this.w = VectorMath.fromYawPitch(yaw + 90, 0);
this.v = w.clone().crossProduct(u);
return this;
}
public Vector getU() {
return u;
}
public Vector getV() {
return v;
}
public Vector getW() {
return w;
}
public float getYaw() {
return VectorMath.wrapAngleDeg(VectorMath.getYaw(this.getW()) - 90);
}
public Frame setYaw(float yaw) {
this.setFromYawPitch(yaw, this.getPitch());
return this;
}
public float getPitch() {
return VectorMath.getPitch(this.getU());
}
public Frame setPitch(float pitch) {
this.setFromYawPitch(this.getYaw(), pitch);
return this;
}
public Vector transform(Vector v) {
tempv1.setX(v.getX()).setY(v.getY()).setZ(v.getZ());
v.zero();
VectorMath.addMul(v, this.getU(), tempv1.getX());
VectorMath.addMul(v, this.getV(), tempv1.getY());
VectorMath.addMul(v, this.getW(), tempv1.getZ());
return v;
}
public Frame clone() {
return new Frame().setFromFrame(this);
}
}

View File

@ -0,0 +1,227 @@
package io.github.bi0qaw.biosphere.util;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
public class LocationLib {
public static Location[] getCircle(Location[] locations, double radius, double density) {
Vector[] circle = VectorLib.getCircle(radius, density);
return offset(locations, circle);
}
public static Location[] getCube(Location[] locations, double radius) {
Vector[] cube = VectorLib.getCube(radius);
return offset(locations, cube);
}
public static Location[] getCubeOutline(Location[] locations, double radius, double density) {
Vector[] cubeoutline = VectorLib.getCubeOutline(radius, density);
return offset(locations, cubeoutline);
}
public static Location[] getCylindricalCoordinate(Location[] locations, double radius, double yaw, double height) {
return offset(locations, VectorMath.fromCylindricalCoordinates(radius, yaw, height));
}
public static Location[] getHelix(Location[] locations, double radius, double height, double step, double density) {
Vector[] helix = VectorLib.getHelix(radius, height, step, density);
return offset(locations, helix);
}
public static Location[] getLine(Location[] locations, Location end, double density) {
Vector origin = new Vector(0, 0, 0);
Vector vector;
ArrayList<Location> line = new ArrayList<Location>();
for (Location l: locations) {
vector = end.toVector().subtract(l.toVector());
line.addAll(Arrays.asList(LocationLib.offset(new Location[] {l}, VectorLib.getLine(origin, vector, density))));
}
return line.toArray(new Location[line.size()]);
}
public static Location[] getLineCoordinate(Location[] locations, Location end, double position) {
Location[] coordinates = new Location[locations.length];
Vector delta;
int i = 0;
for (Location l: locations) {
delta = end.toVector().subtract(l.toVector()).multiply(position);
locations[i] = l.clone().add(delta);
i++;
}
return locations;
}
public static Location[] getPolygon(Location[] locations, int points, double radius) {
Vector[] polygon = VectorLib.getPolygon(points, radius);
return offset(locations, polygon);
}
public static Location[] getPolygonOutline(Location[] locations, int points, double radius, double density) {
Vector[] polygonoutline = VectorLib.getPolygonOutline(points, radius, density);
return offset(locations, polygonoutline);
}
public static Location[] getRandomSphere(Location[] locations, double radius, double density) {
Vector[] sphere = VectorLib.getRandomSphere(radius, density);
return offset(locations, sphere);
}
public static Location[] getSphere(Location[] locations, double radius, double density) {
Vector[] sphere = VectorLib.getSphere(radius, density);
return offset(locations, sphere);
}
public static Location[] getSphericalCoordinates(Location[] locations, double radius, double yaw, double pitch) {
Vector spherical = VectorMath.fromSphericalCoordinates(radius, yaw, pitch);
return offset(locations, spherical);
}
public static Location[] linkAll(Location[] locations, double density) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(locations);
Vector[] linked = VectorLib.linkAll(vectors, density);
Location[] linkedLocations = new Location[linked.length];
World world = locations[0].getWorld();
int i = 0;
for (Vector v: linked) {
linkedLocations[i] = v.toLocation(world);
i++;
}
return linkedLocations;
}
else {
return new Location[] {};
}
}
public static Location midpoint(Location[] locations) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(locations);
Vector midpoint = VectorLib.midpoint(vectors);
return midpoint.toLocation(locations[0].getWorld());
}
else {
return null;
}
}
public static Location[] offset(Location[] locations, Vector vector) {
return offset(locations, new Vector[]{vector});
}
public static Location[] offset(Location[] locations, Vector[] vectors) {
Location[] offset = new Location[locations.length * vectors.length];
int i = 0;
for (Location l: locations) {
for (Vector v: vectors) {
offset[i] = l.clone().add(v);
i++;
}
}
return offset;
}
public static Location[] pointReflection(Location[] locations, Location point) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(locations);
Vector[] reflection = VectorLib.pointReflection(vectors, point.toVector());
return toLocation(reflection, locations[0].getWorld());
}
else {
return new Location[]{};
}
}
public static Location[] reflection(Location[] locations, Location center, Vector direction) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(locations);
Vector[] reflection = VectorLib.reflection(vectors, center.toVector(), direction);
return toLocation(reflection, locations[0].getWorld());
}
else {
return new Location[]{};
}
}
public static Location[] rotate(Location[] locations, Location center, Vector axis, double angle) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1))); //move locations to origin & convert to vectors
vectors = VectorLib.rotate(vectors, axis, angle);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[] {};
}
}
public static Location[] rotateX(Location[] locations, Location center, double angle) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1)));
VectorLib.rotateX(vectors, angle);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[]{};
}
}
public static Location[] rotateY(Location[] locations, Location center, double angle) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1)));
VectorLib.rotateY(vectors, angle);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[]{};
}
}
public static Location[] rotateZ(Location[] locations, Location center, double angle) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1)));
VectorLib.rotateZ(vectors, angle);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[]{};
}
}
public static Location[] scale(Location[] locations, Location center, double factor) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1)));
VectorLib.scale(vectors, factor);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[]{};
}
}
public static Location[] scaleDirectional(Location[] locations, Location center, Vector direction, double factor) {
if (locations.length > 0) {
Vector[] vectors = VectorLib.toVector(offset(locations, center.toVector().multiply(-1)));
VectorLib.scaleDirectional(vectors, direction, factor);
return offset(toLocation(vectors, locations[0].getWorld()), center.toVector());
}
else {
return new Location[]{};
}
}
public static Location[] toLocation(Vector[] vectors, World world) {
Location[] locations = new Location[vectors.length];
int i = 0;
for (Vector v: vectors) {
locations[i] = v.toLocation(world);
i++;
}
return locations;
}
}

View File

@ -0,0 +1,476 @@
package io.github.bi0qaw.biosphere.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class TrigLib {
public static Number[] llen(Location[] l){
Number[] nums = new Number[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
nums[i] = tempLoc.clone().toVector().length();
i++;
}
return nums;
}
public static Location[] lneg(Location[] l){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().multiply(-1);
i++;
}
return locs;
}
public static Location[] offset(Location[] l, Location l2){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = l2.clone().toVector();
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().add(vect);
i++;
}
return locs;
}
public static Location[] coffset(Location[] l, double x, double y, double z){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().add(x, y, z);
i++;
}
return locs;
}
public static Location[] vectorOffset(Location[] locations, Vector[] vectors) {
Location[] offset = new Location[locations.length * vectors.length];
int i = 0;
for (Location l: locations) {
for (Vector v: vectors) {
offset[i] = l.clone().add(v);
i++;
}
}
return offset;
}
public static Location[] mult(Location[] l, double p){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().multiply(p);
i++;
}
return locs;
}
public static Location[] lmult(Location[] l, Location l2){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = l2.clone().toVector();
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().toVector().multiply(vect).toLocation(tempLoc.getWorld());
i++;
}
return locs;
}
public static Location[] lnorm(Location[] l){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().toVector().normalize().toLocation(tempLoc.getWorld());
i++;
}
return locs;
}
public static Location[] relloc(Location[] l, Location l2){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = l2.clone().toVector();
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(vect);
i++;
}
return locs;
}
public static Number[] dotp(Location[] l, Location l2){
Number[] nums = new Number[Array.getLength(l)];
Vector vect = l2.clone().toVector();
int i = 0;
for(Location tempLoc : l){
nums[i] = tempLoc.clone().toVector().dot(vect);
i++;
}
return nums;
}
public static Number[] cdotp(Location[] l, double x, double y, double z){
Number[] nums = new Number[Array.getLength(l)];
Vector vect = new Vector(x, y, z);
int i = 0;
for(Location tempLoc : l){
nums[i] = tempLoc.clone().toVector().dot(vect);
i++;
}
return nums;
}
public static Location[] crossp(Location[] l, Location l2){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = l2.clone().toVector();
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().toVector().crossProduct(vect).toLocation(tempLoc.getWorld());
i++;
}
return locs;
}
public static Location[] ccrossp(Location[] l, double x, double y, double z){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = new Vector(x, y, z);
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().toVector().crossProduct(vect).toLocation(tempLoc.getWorld());
i++;
}
return locs;
}
public static Location[] rot(Location[] l, Location center, Vector axis, double phi){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
double n1 = axis.getX();
double n2 = axis.getY();
double n3 = axis.getZ();
double x;
double y;
double z;
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect);
x = locs[i].getX();
y = locs[i].getY();
z = locs[i].getZ();
locs[i].setX(x * (Math.pow(n1, 2) * ( 1 - Math.cos(phi)) + Math.cos(phi)) + y * (n2 * n1 * ( 1 - Math.cos(phi)) - n3 * Math.sin(phi)) + z * (n1 * n3 * ( 1-Math.cos(phi)) + n2 * (Math.sin(phi))) );
locs[i].setY(x * (n1 * n2 * ( 1 - Math.cos(phi)) + n3 * Math.sin(phi)) + y * (Math.pow(n2, 2) * (1-Math.cos(phi))+Math.cos(phi)+z*(n2*n3*(1-Math.cos(phi))-n1*Math.sin(phi))));
locs[i].setZ(x * (n3*n1* (1-Math.cos(phi))-n2*Math.sin(phi))+y*(n3*n2* ( 1 - Math.cos(phi))+n1*Math.sin(phi))+ z* (Math.pow(n3,2) * (1-Math.cos(phi)) + Math.cos(phi)));
i++;
}
return offset(locs,center);
}
public static Location[] xrot(Location[] l, Location center, double phi){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
double y;
double z;
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect);
y = locs[i].getY();
z = locs[i].getZ();
locs[i].setY(y * Math.cos(phi) + z * Math.sin(phi));
locs[i].setZ(-y * Math.sin(phi) + z * Math.cos(phi));
i++;
}
return offset(locs,center);
}
public static Location[] yrot(Location[] l, Location center, double phi){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
double x;
double z;
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect);
x = locs[i].getX();
z = locs[i].getZ();
locs[i].setX(x * Math.cos(phi) - z * Math.sin(phi));
locs[i].setZ(x * Math.sin(phi) + z * Math.cos(phi));
locs[i].add(center);
i++;
}
return locs;
}
public static Location[] zrot(Location[] l, Location center, double phi){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
double x;
double y;
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect);
x = locs[i].getX();
y = locs[i].getY();
locs[i].setX(x * Math.cos(phi) + y * Math.sin(phi));
locs[i].setY(-x * Math.sin(phi) + y * Math.cos(phi));
i++;
}
return offset(locs,center);
}
public static Location[] ptrefl(Location[] l, Location l2){
Vector vect = l2.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(vect).multiply(-1).add(vect);
i++;
}
return locs;
}
public static Location[] refl(Location[] l, Location point, Vector dir){
Location[] locs = new Location[Array.getLength(l)];
Vector vect = point.clone().toVector();
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.toVector().subtract(vect).multiply(-1).multiply(dir).add(vect).toLocation(tempLoc.getWorld());
i++;
}
return locs;
}
public static Location[] scale(Location[] l, Location center, double d){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect).multiply(d).add(centerVect);
i++;
}
return locs;
}
public static Location[] dirscale(Location[] l, Location center, Vector dir, double d){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(center).toVector().multiply(d).multiply(dir).toLocation(tempLoc.getWorld()).add(center);
i++;
}
return locs;
}
public static Location[] cdirscale(Location[] l, Location center, double x, double y, double z){
Vector centerVect = center.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
Vector vect = new Vector(x, y ,z);
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().subtract(centerVect).toVector().multiply(vect).toLocation(tempLoc.getWorld()).add(centerVect);
i++;
}
return locs;
}
public static Location[] midpt(Location[] l){
Location loc = new Location(l[0].getWorld(), 0, 0, 0);
for(Location tempLoc : l){
loc.add(tempLoc);
}
return new Location[]{loc.multiply(1D / Array.getLength(l))};
}
public static Location[] sphloc(Location[] l, double phi, double the, double r){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone();
locs[i].setX(tempLoc.getX() + r * Math.sin(the) * Math.cos(phi));
locs[i].setY(tempLoc.getY() + r * Math.cos(the));
locs[i].setZ(tempLoc.getZ() + r * Math.sin(the) * Math.sin(phi));
i++;
}
return locs;
}
public static Location[] cylloc(Location[] l, double phi, double r, double h){
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone();
locs[i].setX(tempLoc.getX() + r * Math.cos(phi));
locs[i].setY(tempLoc.getY() + h);
locs[i].setZ(tempLoc.getZ() + r * Math.sin(phi));
i++;
}
return locs;
}
public static Location[] cubeloc(Location[] l, Location l2, double r){
Location[] locs = new Location[Array.getLength(l)];
double d = r / Math.pow(2, 0.5);
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone();
locs[i].setX(tempLoc.getX() + d * (2 * l2.getX() - 1));
locs[i].setY(tempLoc.getY() + d * (2 * l2.getY() - 1));
locs[i].setZ(tempLoc.getZ() + d * (2 * l2.getZ() - 1));
i++;
}
return locs;
}
public static Location[] ccubeloc(Location[] l, double x, double y, double z, double r){
Location[] locs = new Location[Array.getLength(l)];
double d = r / Math.pow(2, 0.5);
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone();
locs[i].setX(tempLoc.getX() + d * (2 * x - 1));
locs[i].setY(tempLoc.getY() + d * (2 * y - 1));
locs[i].setZ(tempLoc.getZ() + d * (2 * z - 1));
i++;
}
return locs;
}
public static Location[] lineloc(Location[] l, Location l2, double p){
Vector vect = l2.clone().toVector();
Location[] locs = new Location[Array.getLength(l)];
int i = 0;
for(Location tempLoc : l){
locs[i] = tempLoc.clone().add(vect.clone().subtract(tempLoc.clone().toVector()).multiply(p));
i++;
}
return locs;
}
public static Location[] getLine(Location[] l, Location l2, double d){
Vector vect = l2.clone().toVector();
List<Location> locs = new ArrayList<Location>();
Vector v;
Vector tempVect;
int k;
int i;
for(Location tempLoc : l){
tempVect = tempLoc.toVector();
k = (int) (tempVect.distance(vect) * d);
v = vect.clone().subtract(tempVect).multiply(1D/k);
for(i = 0; i < k ; i++){
locs.add(tempLoc.clone().add(v.clone().multiply(i)));
}
}
return (Location[]) locs.toArray(new Location[locs.size()]);
}
public static Location[] linkAll(Location[] loc, double d){
List<Location> locs = new ArrayList<Location>();
for(Location l1 : loc){
for(Location l2 : loc){
if(!l1.equals(l2)){
locs.addAll(Arrays.asList(getLine(new Location[]{l1}, l2, d)));
}
}
}
return locs.toArray(new Location[locs.size()]);
}
public static Location[] getPoly(Location[] l, int n, double r){
double phi = Math.PI * 2 / (double) n;
Location[] locs = new Location[n*Array.getLength(l)];
Location loc;
int i = 0;
int j = 0;
for(Location tempLoc : l){
loc = tempLoc.clone().add(r, 0D, 0D);
for(i = 0; i < n; i++){
locs[j] = yrot(new Location[]{loc}, tempLoc, i * phi)[0];
j++;
}
}
return locs;
}
public static Location[] getPolyOutline(Location[] l, Integer n, double r, double d){
Location[] loc = new Location[n];
List<Location> locs = new ArrayList<Location>();
int i = 0;
for(Location tempLoc : l){
loc = getPoly(new Location[]{tempLoc}, n , r);
for(i = 0; i < n - 1; i++){
locs.addAll(Arrays.asList(getLine(new Location[]{loc[i]},loc[i+1],d)));
}
locs.addAll(Arrays.asList(getLine(new Location[]{loc[i]},loc[0],d)));
}
return (Location[]) locs.toArray(new Location[locs.size()]);
}
public static Location[] getHelix(Location[] l, double r, double h, double k, double d){
int n = (int) ( h * 2 * Math.PI * r * d);
double dphi = 1D / (k * r * d);
Location[] locs = new Location[n * Array.getLength(l)];
int i = 0;
int j = 0;
for(Location tempLoc : l){
for(j = 0; j < n; j++){
locs[i] = cylloc(new Location[]{ tempLoc }, j * dphi, r, j * h / n)[0];
i++;
}
}
return locs;
}
public static Location[] getCube(Location[] l, double r){
return vectorOffset(l, VectorLib.getCube(r));
}
public static Location[] getCubeOutline(Location[] l, double r, double d){
return vectorOffset(l, VectorLib.getCubeOutline(r, d));
}
public static Location[] getSphereRand(Location[] l, double r, double d){
List<Location> locs = new ArrayList<Location>();
int n = (int) (4 * Math.PI * r * r * d);
double phi = 0D;
double the = 0D;
Random randGen = new Random();
for(Location tempLoc : l){
for(int i = 0; i < n; i++){
phi = randGen.nextDouble() * 2 * Math.PI;
the = randGen.nextDouble() * Math.PI;
locs.add(sphloc(new Location[]{tempLoc}, phi, the, r)[0]);
}
}
return (Location[]) locs.toArray(new Location[locs.size()]);
}
public static Location[] getSphere(Location[] l, double r, double d){
List<Location> locs = new ArrayList<Location>();
double the = 0D;
double phi = 0D;
int n = (int) (Math.PI * r * d);
for(Location tempLoc : l){
the = 0;
for(int i = 0; i < n; i++){
phi = 0;
for(int j = 0; j < n * 2; j++){
locs.add(sphloc(new Location[]{tempLoc}, phi, the, r)[0]);
phi += Math.PI / n;
}
the += Math.PI / n;
}
}
return (Location[]) locs.toArray(new Location[locs.size()]);
}
}

View File

@ -0,0 +1,244 @@
package io.github.bi0qaw.biosphere.util;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class VectorLib {
public static final double SQRT2 = Math.sqrt(2);
public static Vector[] getLine(double length, double density) {
int points = (int) (length * density) + 1;
double delta = length / (double) points;
Vector[] vectors = new Vector[points];
for (int i = 0; i < points; i++) {
vectors[i] = new Vector(i*delta, 0, 0);
}
return vectors;
}
public static Vector[] getLine(Vector vector1, Vector vector2, double density) {
double length = vector1.distance(vector2);
int points = (int) (length * density) + 1;
Vector delta = vector2.clone().subtract(vector1).multiply(1.0 / (double) points);
Vector[] vectors = new Vector[points];
for (int i=0; i < points; i++) {
vectors[i] = delta.clone().multiply(i).add(vector1);
}
return vectors;
}
public static Vector[] linkLine(Vector v1, Vector v2, double density) {
int points = (int) (v1.distance(v2) * density) + 1;
Vector delta = v2.clone().subtract(v1).multiply(1D / (double) points);
Vector[] vectors = new Vector[points];
vectors[0] = v1.clone();
for (int i=1; i<points; i++) {
vectors[i] = delta.clone().multiply(i).add(v1);
}
return vectors;
}
public static Vector[] getCircle(double radius, double density) {
int n = (int) (radius * 2 * Math.PI * density);
return getPolygon(n, radius);
}
public static Vector[] getPolygon(int points, double radius) {
float deltaAngle = 360 / (float) points;
Vector[] vectors = new Vector[points];
for (int i = 0; i < points; i++) {
vectors[i] = VectorMath.fromCylindricalCoordinates(radius, i * deltaAngle, 0);
}
return vectors;
}
public static Vector[] getPolygonOutline(int points, double radius, double density) {
Vector[] polygon = getPolygon(points, radius);
List<Vector> vectors = new ArrayList<Vector>();
for (int i=0; i < points - 1; i++) {
vectors.addAll(Arrays.asList(linkLine(polygon[i], polygon[i+1], density)));
}
vectors.addAll(Arrays.asList(linkLine(polygon[polygon.length - 1], polygon[0], density)));
return vectors.toArray(new Vector[vectors.size()]);
}
public static Vector[] getCube(double radius) {
Vector[] vectors = new Vector[8];
double d = radius / SQRT2;
vectors[0] = new Vector(-d, -d, -d);
vectors[1] = new Vector(-d, -d, d);
vectors[2] = new Vector(-d, d, -d);
vectors[3] = new Vector(-d, d, d);
vectors[4] = new Vector(d, -d, -d);
vectors[5] = new Vector(d, -d, d);
vectors[6] = new Vector(d, d, -d);
vectors[7] = new Vector(d, d, d);
return vectors;
}
public static Vector[] getCubeOutline(double radius, double density) {
double off = radius/SQRT2;
int points = (int) (radius * density) + 1;
double d = 2*off/points;
Vector[] vectors = new Vector[points * 12];
for (int i=0; i < points; i++) {
vectors[i + 0*points] = new Vector(i*d-off, -off, -off);
vectors[i + 1*points] = new Vector(i*d-off, off, -off);
vectors[i + 2*points] = new Vector(i*d-off, -off, off);
vectors[i + 3*points] = new Vector(i*d-off, off, off);
vectors[i + 4*points] = new Vector(-off, i*d-off, -off);
vectors[i + 5*points] = new Vector(off, i*d-off, -off);
vectors[i + 6*points] = new Vector(-off, i*d-off, off);
vectors[i + 7*points] = new Vector(off, i*d-off, off);
vectors[i + 8*points] = new Vector(-off, -off, i*d-off);
vectors[i + 9*points] = new Vector(off, -off, i*d-off);
vectors[i + 10*points] = new Vector(-off, off, i*d-off);
vectors[i + 11*points] = new Vector(off, off, i*d-off);
}
return vectors;
}
public static Vector[] getHelix(double radius, double height, double step, double density) {
int points = (int) ( height * 2 * Math.PI * radius * density);
double deltaAngle = 360 * height / (step * points);
double deltaHeight = height / points;
Vector[] vectors = new Vector[points];
for(int i=0; i < points; i++){
vectors[i] = VectorMath.fromCylindricalCoordinates(radius, deltaAngle * i, deltaHeight * i);
}
return vectors;
}
public static Vector[] linkAll(Vector[] vectors, double density) {
List<Vector> vecs = new ArrayList<Vector>();
for (Vector v1 : vectors) {
for (Vector v2 : vectors) {
if (!v1.equals(v2)) {
vecs.addAll(Arrays.asList(linkLine(v1, v2, density)));
}
}
}
return vecs.toArray(new Vector[vecs.size()]);
}
public static Vector midpoint(Vector[] vectors) {
Vector midpoint = new Vector();
double factor = 1D/vectors.length;
for (Vector vec: vectors) {
VectorMath.addMul(midpoint, vec, factor);
}
return midpoint;
}
public static Vector[] offset(Vector[] vectors, Vector offset) {
for (Vector v: vectors) {
v.add(offset);
}
return vectors;
}
public static Vector[] pointReflection(Vector[] vectors, Vector center) {
for (Vector v: vectors) {
v.subtract(center).multiply(-1).add(center);
}
return vectors;
}
public static Vector[] reflection(Vector[] vectors, Vector center, Vector direction) {
for(Vector v: vectors){
v.subtract(center).multiply(-1).multiply(direction).add(center);
}
return vectors;
}
public static Vector[] rotate(Vector[] vectors, Vector axis, double angle) {
for (Vector v: vectors) {
v = VectorMath.rot(v, axis, angle);
}
return vectors;
}
public static Vector[] rotateX(Vector[] vectors, double angle) {
for (Vector v: vectors) {
v = VectorMath.rotX(v, angle);
}
return vectors;
}
public static Vector[] rotateY(Vector[] vectors, double angle) {
for (Vector v: vectors) {
v = VectorMath.rotY(v, angle);
}
return vectors;
}
public static Vector[] rotateZ(Vector[] vectors, double angle) {
for (Vector v: vectors) {
v = VectorMath.rotZ(v, angle);
}
return vectors;
}
public static Vector[] scale(Vector[] vectors, double factor) {
for (Vector v: vectors) {
v.multiply(factor);
}
return vectors;
}
public static Vector[] scaleDirectional(Vector[] vectors, Vector direction, double factor) {
for (Vector v: vectors) {
v.multiply(direction);
v.multiply(factor);
}
return vectors;
}
public static Vector[] getSphere(double radius, double density){
int points = (int) (Math.PI * radius * density);
Vector[] vectors = new Vector[points * points];
double deltaYaw = 360D / points;
double deltaPitch = 180D / points;
double yaw = 0;
double pitch = 0;
for (int i=0; i<points; i++) {
for (int j=0; j<points; j++) {
vectors[j+i*points] = VectorMath.fromSphericalCoordinates(radius, yaw, pitch);
pitch += deltaPitch;
}
yaw += deltaYaw;
pitch = 0;
}
return vectors;
}
public static Vector[] getRandomSphere(double radius, double density) {
int points = (int) (Math.PI * radius * density);
Vector[] vectors = new Vector[points * points];
Random rand = new Random();
double yaw, pitch;
for (int i=0; i < points * points; i++) {
yaw = rand.nextDouble() * 360;
pitch = rand.nextDouble() * 180;
vectors[i] = VectorMath.fromSphericalCoordinates(radius, yaw, pitch);
}
return vectors;
}
public static Vector[] toVector(Location[] locations) {
Vector[] vectors = new Vector[locations.length];
int i = 0;
for (Location l: locations) {
vectors[i] = l.toVector();
i++;
}
return vectors;
}
}

View File

@ -0,0 +1,203 @@
package io.github.bi0qaw.biosphere.util;
import org.bukkit.util.Vector;
public class VectorMath {
public static final double PI = Math.PI;
public static final double DEG_TO_RAD = PI / 180.0;
public static final double RAD_TO_DEG = 180.0 / PI;
public static Vector fromSphericalCoordinates(double radius, double yaw, double pitch) {
double r = Math.abs(radius);
double p = pitch * DEG_TO_RAD;
double sinp = Math.sin(p);
double x = r * sinp * Math.cos(yaw * DEG_TO_RAD);
double y = r * Math.cos(p);
double z = r * sinp * Math.sin(yaw * DEG_TO_RAD);
return new Vector(x, y, z);
}
public static Vector fromCylindricalCoordinates(double radius, double yaw, double height) {
double r = Math.abs(radius);
double x = r * Math.cos(yaw * DEG_TO_RAD);
double z = r * Math.sin(yaw * DEG_TO_RAD);
return new Vector(x, height, z);
}
public static Vector fromYawPitch(float yaw, float pitch) {
double y = Math.sin(pitch * DEG_TO_RAD);
double div = Math.cos(pitch * DEG_TO_RAD);
double x = Math.cos(yaw * DEG_TO_RAD);
double z = Math.sin(yaw * DEG_TO_RAD);
return new Vector(x,0, z).multiply(div).setY(y);
}
public static float getYaw(Vector vector) {
if (((Double) vector.getX()).equals((double) 0) && ((Double) vector.getZ()).equals((double) 0)){
return 0;
}
return (float) (Math.atan2(vector.getZ(), vector.getX()) * RAD_TO_DEG);
}
public static float getPitch(Vector vector) {
double xy = Math.sqrt(vector.getX() * vector.getX() + vector.getZ() * vector.getZ());
return (float) (Math.atan(vector.getY() / xy) * RAD_TO_DEG);
}
public static Vector setYaw(Vector vector, float yaw) {
vector = fromYawPitch(yaw, getPitch(vector));
return vector;
}
public static Vector setPitch(Vector vector, float pitch) {
vector = fromYawPitch(getYaw(vector), pitch);
return vector;
}
public static Vector addMul(Vector v1, Vector v2, double factor) {
v1.setX(v1.getX() + v2.getX() * factor);
v1.setY(v1.getY() + v2.getY() * factor);
v1.setZ(v1.getZ() + v2.getZ() * factor);
return v1;
}
public static Vector rotX(Vector vector, double angle) {
double sin = Math.sin(angle * DEG_TO_RAD);
double cos = Math.cos(angle * DEG_TO_RAD);
Vector vy = new Vector(0, cos, -sin);
Vector vz = new Vector(0, sin, cos);
Vector clone = vector.clone();
vector.setY(clone.dot(vy));
vector.setZ(clone.dot(vz));
return vector;
}
public static Vector rotY(Vector vector, double angle) {
double sin = Math.sin(angle * DEG_TO_RAD);
double cos = Math.cos(angle * DEG_TO_RAD);
Vector vx = new Vector(cos, 0, sin);
Vector vz = new Vector(-sin, 0, cos);
Vector clone = vector.clone();
vector.setX(clone.dot(vx));
vector.setZ(clone.dot(vz));
return vector;
}
public static Vector rotZ(Vector vector, double angle) {
double sin = Math.sin(angle * DEG_TO_RAD);
double cos = Math.cos(angle * DEG_TO_RAD);
Vector vx = new Vector(cos, -sin, 0);
Vector vy = new Vector(sin, cos, 0);
Vector clone = vector.clone();
vector.setX(clone.dot(vx));
vector.setY(clone.dot(vy));
return vector;
}
public static Vector rot(Vector vector, Vector axis, double angle) {
double sin = Math.sin(angle * DEG_TO_RAD);
double cos = Math.cos(angle * DEG_TO_RAD);
Vector a = axis.clone().normalize();
double ax = a.getX();
double ay = a.getY();
double az = a.getZ();
Vector rotx = new Vector(cos+ax*ax*(1-cos), ax*ay*(1-cos)-az*sin, ax*az*(1-cos)+ay*sin);
Vector roty = new Vector(ay*ax*(1-cos)+az*sin, cos+ay*ay*(1-cos), ay*az*(1-cos)-ax*sin);
Vector rotz = new Vector(az*ax*(1-cos)-ay*sin, az*ay*(1-cos)+ax*sin, cos+az*az*(1-cos));
double x = rotx.dot(vector);
double y = roty.dot(vector);
double z = rotz.dot(vector);
vector.setX(x).setY(y).setZ(z);
return vector;
}
public static float notchYaw(float yaw){
float y = yaw - 90;
if (y < -180){
y += 360;
}
return y;
}
public static float notchPitch(float pitch){
return -pitch;
}
public static float fromNotchYaw(float notchYaw){
float y = notchYaw + 90;
if (y > 180){
y -= 360;
}
return y;
}
public static float fromNotchPitch(float notchPitch){
return -notchPitch;
}
public static float skriptYaw(float yaw){
float y = yaw - 90;
if (y < 0){
y += 360;
}
return y;
}
public static float skriptPitch(float pitch){
return -pitch;
}
public static float fromSkriptYaw(float yaw){
float y = yaw + 90;
if (y > 360){
y -= 360;
}
return y;
}
public static float fromSkriptPitch(float pitch){
return -pitch;
}
public static float wrapAngleDeg(float angle) {
angle %= 360f;
if (angle <= -180) {
return angle + 360;
} else if (angle > 180) {
return angle - 360;
} else {
return angle;
}
}
public static float wrap(float a, float min, float max) {
if (a < min || a > max) {
return (a - min) - (float) Math.floor((a-min)/(max-min));
}
else {
return a;
}
}
public static float clamp(float a, float min, float max) {
if (a < min) {
return min;
}
else if (a > max) {
return max;
}
else {
return a;
}
}
public static float wrapYaw(float yaw) {
return wrap(yaw, 0, 360);
}
public static float wrapPitch(float pitch) {
return clamp(pitch, -90, 90);
}
}

View File

@ -0,0 +1,4 @@
name: Biosphere2
main: io.github.bi0qaw.biosphere.Biosphere
author: bi0qaw
version: 1.0.0