not finished, tried to make entity with custom skin + bug patches
This commit is contained in:
parent
559bead7d8
commit
b935c6fee6
25 changed files with 442 additions and 113 deletions
17
src/main/java/me/unurled/raxen/utils/EntityUtils.java
Normal file
17
src/main/java/me/unurled/raxen/utils/EntityUtils.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package me.unurled.raxen.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class EntityUtils {
|
||||
|
||||
public void setSkin(Entity e) {
|
||||
if (e instanceof Player) {
|
||||
|
||||
}
|
||||
// Bukkit.getWorld("aa").spawn(new Location(Bukkit.getWorld("aa"), 0, 0, 0), new CraftPlayer())
|
||||
}
|
||||
}
|
108
src/main/java/me/unurled/raxen/utils/RayTrace.java
Normal file
108
src/main/java/me/unurled/raxen/utils/RayTrace.java
Normal file
|
@ -0,0 +1,108 @@
|
|||
package me.unurled.raxen.utils;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RayTrace {
|
||||
|
||||
//origin = start position
|
||||
//direction = direction in which the raytrace will go
|
||||
Vector origin, direction;
|
||||
|
||||
public RayTrace(Vector origin, Vector direction) {
|
||||
this.origin = origin;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
//get a point on the raytrace at X blocks away
|
||||
public Vector getPostion(double blocksAway) {
|
||||
return origin.clone().add(direction.clone().multiply(blocksAway));
|
||||
}
|
||||
|
||||
//checks if a position is on contained within the position
|
||||
public boolean isOnLine(Vector position) {
|
||||
double t = (position.getX() - origin.getX()) / direction.getX();
|
||||
;
|
||||
if (position.getBlockY() == origin.getY() + (t * direction.getY()) && position.getBlockZ() == origin.getZ() + (t * direction.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//get all postions on a raytrace
|
||||
public ArrayList<Vector> traverse(double blocksAway, double accuracy) {
|
||||
ArrayList<Vector> positions = new ArrayList<>();
|
||||
for (double d = 0; d <= blocksAway; d += accuracy) {
|
||||
positions.add(getPostion(d));
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
//intersection detection for current raytrace with return
|
||||
public Vector positionOfIntersection(Vector min, Vector max, double blocksAway, double accuracy) {
|
||||
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
|
||||
for (Vector position : positions) {
|
||||
if (intersects(position, min, max)) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//intersection detection for current raytrace
|
||||
public boolean intersects(Vector min, Vector max, double blocksAway, double accuracy) {
|
||||
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
|
||||
for (Vector position : positions) {
|
||||
if (intersects(position, min, max)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//bounding box instead of vector
|
||||
public Vector positionOfIntersection(BoundingBox boundingBox, double blocksAway, double accuracy) {
|
||||
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
|
||||
for (Vector position : positions) {
|
||||
if (intersects(position, boundingBox.getMin(), boundingBox.getMax())) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//bounding box instead of vector
|
||||
public boolean intersects(BoundingBox boundingBox, double blocksAway, double accuracy) {
|
||||
ArrayList<Vector> positions = traverse(blocksAway, accuracy);
|
||||
for (Vector position : positions) {
|
||||
if (intersects(position, boundingBox.getMin(), boundingBox.getMax())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//general intersection detection
|
||||
public static boolean intersects(Vector position, Vector min, Vector max) {
|
||||
if (position.getX() < min.getX() || position.getX() > max.getX()) {
|
||||
return false;
|
||||
} else if (position.getY() < min.getY() || position.getY() > max.getY()) {
|
||||
return false;
|
||||
} else if (position.getZ() < min.getZ() || position.getZ() > max.getZ()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//debug / effects
|
||||
public void highlight(World world, double blocksAway, double accuracy){
|
||||
for(Vector position : traverse(blocksAway,accuracy)){
|
||||
world.playEffect(position.toLocation(world), Effect.BOW_FIRE,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -98,18 +98,40 @@ public class Utils {
|
|||
* @return a String
|
||||
*/
|
||||
public static String textCompToString(TextComponent comp) {
|
||||
MiniMessage minimessage = MiniMessage.builder()
|
||||
/* MiniMessage minimessage = MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolver(StandardTags.color())
|
||||
.resolver(StandardTags.decorations())
|
||||
.resolver(StandardTags.reset())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
.build(); */
|
||||
return ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacyAmpersand()
|
||||
.serialize(comp));
|
||||
}
|
||||
|
||||
/**
|
||||
* transform a text-component to a string
|
||||
* @param comp a string
|
||||
* @return a String
|
||||
*/
|
||||
public static String textCompToString(Component comp) {
|
||||
/* MiniMessage minimessage = MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolver(StandardTags.color())
|
||||
.resolver(StandardTags.decorations())
|
||||
.resolver(StandardTags.reset())
|
||||
.build()
|
||||
)
|
||||
.build(); */
|
||||
return ChatColor.translateAlternateColorCodes('§', LegacyComponentSerializer.legacyAmpersand()
|
||||
.serialize(comp));
|
||||
}
|
||||
|
||||
public static void comp(Component comp) {
|
||||
LegacyComponentSerializer.legacyAmpersand().serialize(comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips all color from a string.
|
||||
* @param string the string that wants to be decolored.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue