Migrate vectors to a dedicated API interface
This commit is contained in:
parent
0f01475ec3
commit
81286767f4
18 changed files with 1124 additions and 469 deletions
|
@ -1,6 +1,6 @@
|
|||
package dev.zontreck.libzontreck.util;
|
||||
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3d;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -18,9 +18,9 @@ public class BlocksUtil
|
|||
* @param limit The applicable limit for vein detection
|
||||
* @return List of positions for the vein
|
||||
*/
|
||||
public static List<Vector3> VeinOf(ServerLevel level, Vector3 start, int limit)
|
||||
public static List<Vector3d> VeinOf(ServerLevel level, Vector3d start, int limit)
|
||||
{
|
||||
List<Vector3> ret = new ArrayList<>();
|
||||
List<Vector3d> ret = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
|
115
src/main/java/dev/zontreck/libzontreck/util/PositionUtil.java
Normal file
115
src/main/java/dev/zontreck/libzontreck/util/PositionUtil.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
package dev.zontreck.libzontreck.util;
|
||||
|
||||
import dev.zontreck.libzontreck.api.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides helper functions for position related things
|
||||
*/
|
||||
public class PositionUtil
|
||||
{
|
||||
|
||||
public List<Vector3> makeCube(Vector3 p1, Vector3 p2)
|
||||
{
|
||||
List<Vector3> vecs = new ArrayList<>();
|
||||
Vector3 work = new Vector3d();
|
||||
Vector3d v1 = p1.asVector3d();
|
||||
Vector3d v2 = p2.asVector3d();
|
||||
|
||||
double xx = v1.x;
|
||||
double yy = v1.y;
|
||||
double zz = v1.z;
|
||||
|
||||
int yState = 0;
|
||||
int zState = 0;
|
||||
int xState = 0;
|
||||
|
||||
for(xx = Math.round(v1.x); (xx != Math.round(v2.x) && xState != 2);)
|
||||
{
|
||||
for(zz = Math.round(v1.z); (zz != Math.round(v2.z) && zState != 2);)
|
||||
{
|
||||
for(yy = Math.round(v1.y); (yy != Math.round(v2.y) && yState != 2);)
|
||||
{
|
||||
work = new Vector3d(xx, yy, zz);
|
||||
|
||||
if(!vecs.contains(work)) vecs.add(work);
|
||||
|
||||
if(yy > v2.y)
|
||||
{
|
||||
yy -= 1.0;
|
||||
if(yy == Math.round(v2.y) && yState == 0)
|
||||
{
|
||||
yState++;
|
||||
}else{
|
||||
if(yState == 1)
|
||||
{
|
||||
yState ++;
|
||||
}
|
||||
}
|
||||
} else if(yy < v2.y)
|
||||
{
|
||||
yy += 1.0;
|
||||
if(yy == Math.round(v2.y) && yState == 0){
|
||||
yState ++;
|
||||
}else {
|
||||
if(yState == 1)yState++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yState=0;
|
||||
work = new Vector3d(xx,yy,zz);
|
||||
|
||||
if(!vecs.contains(work)) vecs.add(work);
|
||||
|
||||
if(zz > v2.z)
|
||||
{
|
||||
zz -= 1.0;
|
||||
|
||||
if(zz == Math.round(v2.z) && zState == 0)zState++;
|
||||
else{
|
||||
if(zState == 1)zState++;
|
||||
}
|
||||
}else if(zz < v2.z)
|
||||
{
|
||||
zz += 1.0;
|
||||
|
||||
if(zz == Math.round(v2.z) && zState == 0)zState++;
|
||||
else {
|
||||
if(zState==1)zState++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zState=0;
|
||||
work = new Vector3d(xx,yy,zz);
|
||||
|
||||
if(!vecs.contains(work)) vecs.add(work);
|
||||
|
||||
if(xx > v2.x)
|
||||
{
|
||||
xx -= 1.0;
|
||||
|
||||
if(xx == Math.round(v2.x) && xState == 0) xState++;
|
||||
else{
|
||||
if(xState == 1)xState++;
|
||||
}
|
||||
}else if(xx < v2.x)
|
||||
{
|
||||
xx += 1.0;
|
||||
|
||||
if(xx == Math.round(v2.x) && xState==0)xState++;
|
||||
else{
|
||||
if(xState==1)xState++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vecs;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.libzontreck.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -13,6 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
|
|||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
public class ServerUtilities
|
||||
{
|
||||
|
@ -23,7 +25,7 @@ public class ServerUtilities
|
|||
*/
|
||||
public static ServerPlayer getPlayerByID(String id)
|
||||
{
|
||||
return LibZontreck.THE_SERVER.getPlayerList().getPlayer(UUID.fromString(id));
|
||||
return ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(UUID.fromString(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +81,7 @@ public class ServerUtilities
|
|||
public static boolean playerIsOffline(UUID ID) throws InvalidSideException {
|
||||
if(isClient())throw new InvalidSideException("This can only be called on the server");
|
||||
|
||||
if(LibZontreck.THE_SERVER.getPlayerList().getPlayer(ID) == null) return true;
|
||||
if(ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(ID) == null) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue