start moving to int vector impls where possible

This commit is contained in:
dfsek
2021-11-24 13:54:43 -07:00
parent ba7722ce45
commit b04f7cfc55
15 changed files with 196 additions and 31 deletions

View File

@@ -7,7 +7,7 @@
package com.dfsek.terra.api.block.state.properties.enums;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.generic.Construct;

View File

@@ -10,7 +10,7 @@ package com.dfsek.terra.api.structure;
import java.util.Random;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.StringIdentifiable;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;

View File

@@ -15,7 +15,6 @@ import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.util.vector.Vector2;

View File

@@ -5,7 +5,7 @@
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.structure.rotation;
package com.dfsek.terra.api.util;
import net.jafama.FastMath;

View File

@@ -0,0 +1,86 @@
package com.dfsek.terra.api.util.vector.integer;
import com.dfsek.terra.api.util.Rotation;
/**
* oh yeah
*/
public class Vector2Int {
private final int x;
private final int z;
private static final Vector2Int ZERO = new Vector2Int(0, 0);
private static final Vector2Int UNIT = new Vector2Int(0, 1);
protected Vector2Int(int x, int z) {
this.x = x;
this.z = z;
}
public static Vector2Int zero() {
return ZERO;
}
public static Vector2Int unit() {
return UNIT;
}
public static Vector2Int of(int x, int z) {
return new Vector2Int(x, z);
}
public int getX() {
return x;
}
public int getZ() {
return z;
}
public Vector3Int toVector3(int y) {
return new Vector3Int(x, y, z);
}
public Mutable mutable() {
return new Mutable(x, z);
}
public Vector2Int rotate(Rotation rotation) {
return switch(rotation) {
case CW_90 -> of(z, -x);
case CCW_90 -> of(-z, x);
case CW_180 -> of(-x, -z);
default -> this;
};
}
public static class Mutable {
private int x, z;
protected Mutable(int x, int z) {
this.x = x;
this.z = z;
}
public int getZ() {
return z;
}
public int getX() {
return x;
}
public void setZ(int z) {
this.z = z;
}
public void setX(int x) {
this.x = x;
}
public Vector2Int immutable() {
return new Vector2Int(x, z);
}
}
}

View File

@@ -0,0 +1,80 @@
package com.dfsek.terra.api.util.vector.integer;
public class Vector3Int {
private final int x, y, z;
private static final Vector3Int ZERO = new Vector3Int(0, 0, 0);
private static final Vector3Int UNIT = new Vector3Int(0, 1, 0);
protected Vector3Int(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public Mutable mutable() {
return new Mutable(x, y, z);
}
public static Vector3Int unit() {
return UNIT;
}
public static Vector3Int zero() {
return ZERO;
}
public static Vector3Int of(int x, int y, int z) {
return new Vector3Int(x, y, z);
}
public static class Mutable {
private int x, y, z;
protected Mutable(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setZ(int z) {
this.z = z;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public Vector3Int immutable() {
return Vector3Int.of(x, y, z);
}
}
}