Add new APIs to the vector system
This commit is contained in:
parent
8bfa308ba5
commit
f911d4e9d2
7 changed files with 138 additions and 2 deletions
|
@ -5,5 +5,5 @@ org.gradle.daemon=false
|
|||
|
||||
mc_version=1.19.2
|
||||
forge_version=43.2.3
|
||||
myversion=1.0.3.7
|
||||
myversion=1.0.4.0
|
||||
parchment_version=2022.11.27
|
24
src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java
Normal file
24
src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package dev.zontreck.libzontreck.vectors;
|
||||
|
||||
public class ChunkPos {
|
||||
public boolean isSubArea;
|
||||
public Points subclaim;
|
||||
|
||||
public ChunkPos(Vector2 chunkPos)
|
||||
{
|
||||
isSubArea=false;
|
||||
Vector3 min = new Vector3(chunkPos.x, -70, chunkPos.y);
|
||||
subclaim = new Points(min, min.add(new Vector3(15, 300, 15)));
|
||||
}
|
||||
|
||||
public ChunkPos(Vector3 point1, Vector3 point2)
|
||||
{
|
||||
isSubArea=true;
|
||||
subclaim = new Points(point1, point2);
|
||||
}
|
||||
|
||||
public boolean isWithin(Vector3 point)
|
||||
{
|
||||
return point.inside(subclaim.Point1, subclaim.Point2);
|
||||
}
|
||||
}
|
|
@ -45,4 +45,19 @@ public class NonAbsVector3
|
|||
if(x == other.x && y==other.y && z==other.z)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean inside(NonAbsVector3 point1, NonAbsVector3 point2)
|
||||
{
|
||||
if(point1.x <= x && point2.x >= x){
|
||||
if(point1.y <= y && point2.y >= y)
|
||||
{
|
||||
if(point1.z <= z && point2.z >= z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
38
src/main/java/dev/zontreck/libzontreck/vectors/Points.java
Normal file
38
src/main/java/dev/zontreck/libzontreck/vectors/Points.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package dev.zontreck.libzontreck.vectors;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Points {
|
||||
public Vector3 Point1 = Vector3.ZERO;
|
||||
public Vector3 Point2 = Vector3.ZERO;
|
||||
|
||||
|
||||
public Points(Vector3 min, Vector3 max)
|
||||
{
|
||||
if(min.less(max))
|
||||
{
|
||||
Point1=min;
|
||||
Point2=max;
|
||||
}else{
|
||||
Point1=max;
|
||||
Point2=min;
|
||||
}
|
||||
}
|
||||
|
||||
public Points(CompoundTag tag){
|
||||
deserialize(tag);
|
||||
}
|
||||
|
||||
public CompoundTag serialize(){
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("min", Point1.serialize());
|
||||
tag.put("max", Point2.serialize());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void deserialize(CompoundTag tag)
|
||||
{
|
||||
Point1 = new Vector3(tag.getCompound("min"));
|
||||
Point2 = new Vector3(tag.getCompound("max"));
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ import net.minecraft.world.phys.Vec2;
|
|||
|
||||
public class Vector2
|
||||
{
|
||||
public static final Vector2 ZERO = new Vector2(0, 0);
|
||||
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
|
@ -90,4 +92,29 @@ public class Vector2
|
|||
if(x == other.x && y==other.y)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean inside(Vector2 point1, Vector2 point2)
|
||||
{
|
||||
if(point1.x <= x && point2.x >= x){
|
||||
if(point1.y <= y && point2.y >= y)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean greater(Vector2 other)
|
||||
{
|
||||
return ((x>other.x) && (y>other.y));
|
||||
}
|
||||
public boolean less(Vector2 other)
|
||||
{
|
||||
return ((x>other.x) && (y>other.y));
|
||||
}
|
||||
public boolean equal(Vector2 other)
|
||||
{
|
||||
return same(other);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import net.minecraft.world.phys.Vec3;
|
|||
|
||||
public class Vector3
|
||||
{
|
||||
public static final Vector3 ZERO = new Vector3(0, 0, 0);
|
||||
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
@ -244,4 +247,33 @@ public class Vector3
|
|||
if(x == other.x && y==other.y && z==other.z)return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean inside(Vector3 point1, Vector3 point2)
|
||||
{
|
||||
if(point1.x <= x && point2.x >= x){
|
||||
if(point1.y <= y && point2.y >= y)
|
||||
{
|
||||
if(point1.z <= z && point2.z >= z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean greater(Vector3 other)
|
||||
{
|
||||
return ((x>other.x) && (y>other.y) && (z>other.z));
|
||||
}
|
||||
public boolean less(Vector3 other)
|
||||
{
|
||||
return ((x<other.x) && (y<other.y) && (z<other.z));
|
||||
}
|
||||
public boolean equal(Vector3 other)
|
||||
{
|
||||
return same(other);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ modId="libzontreck" #mandatory
|
|||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
||||
# see the associated build.gradle script for how to populate this completely automatically during a build
|
||||
version="1.0.3.7" #mandatory
|
||||
version="1.0.4.0" #mandatory
|
||||
# A display name for the mod
|
||||
displayName="LibZontreck" #mandatory
|
||||
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
||||
|
|
Reference in a new issue