Skip to content

Commit

Permalink
Add More Helpers for Vec3i, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Dec 11, 2024
1 parent ee569f6 commit e8cde2e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/nbt/NbtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public static <T> NbtList asListTag(Collection<T> values, Function<T, NbtElement
return putVec3i(new NbtCompound(), pos);
}

public static @NotNull NbtCompound createVec3iTag(@Nonnull Vec3i pos)
{
return putVec3i(new NbtCompound(), pos);
}

public static @NotNull NbtCompound createVec3iToArray(@Nonnull Vec3i pos, String tagName)
{
return writeBlockPosToArrayTag(pos, new NbtCompound(), tagName);
Expand Down Expand Up @@ -187,6 +192,26 @@ public static BlockPos readBlockPos(@Nullable NbtCompound tag)
return null;
}

@Nullable
public static Vec3i readVec3i(@Nullable NbtCompound tag)
{
return readVec3iFromTag(tag);
}

@Nullable
public static Vec3i readVec3iFromTag(@Nullable NbtCompound tag)
{
if (tag != null &&
NbtWrap.containsInt(tag, "x") &&
NbtWrap.containsInt(tag, "y") &&
NbtWrap.containsInt(tag, "z"))
{
return new Vec3i(NbtWrap.getInt(tag, "x"), NbtWrap.getInt(tag, "y"), NbtWrap.getInt(tag, "z"));
}

return null;
}

@Nullable
public static BlockPos readBlockPosFromListTag(@Nonnull NbtCompound tag, String tagName)
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/position/Vec2d.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.dy.masa.malilib.util.position;

import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector2d;

/**
* Post-ReWrite code
Expand Down Expand Up @@ -53,6 +54,11 @@ public boolean equals(Object o)
Double.compare(vec2d.y, this.y) == 0;
}

public Vector2d toVector()
{
return new Vector2d(this.getX(), this.getY());
}

@Override
public int hashCode()
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/position/Vec2i.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.dy.masa.malilib.util.position;

import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector2i;

/**
* Post-ReWrite code
Expand Down Expand Up @@ -54,6 +55,11 @@ public boolean equals(Object o)
return this.y == vec2i.y;
}

public Vector2i toVector()
{
return new Vector2i(this.getX(), this.getY());
}

@Override
public int hashCode()
{
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/fi/dy/masa/malilib/util/position/Vec3d.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.dy.masa.malilib.util.position;

import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector3d;

/**
* Post-ReWrite code
Expand Down Expand Up @@ -91,11 +92,6 @@ public Vec3d normalize()
return normalized(this.x, this.y, this.z);
}

public net.minecraft.util.math.Vec3d toVanilla()
{
return new net.minecraft.util.math.Vec3d(this.x, this.y, this.z);
}

public static Vec3d of(double x, double y, double z)
{
return new Vec3d(x, y, z);
Expand All @@ -117,6 +113,16 @@ public static Vec3d normalized(double x, double y, double z)
return d < 1.0E-4 ? ZERO : new Vec3d(x / d, y / d, z / d);
}

public net.minecraft.util.math.Vec3d toVanilla()
{
return new net.minecraft.util.math.Vec3d(this.x, this.y, this.z);
}

public Vector3d toVector()
{
return new Vector3d(this.getX(), this.getY(), this.getZ());
}

@Override
public String toString()
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/position/Vec3f.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.dy.masa.malilib.util.position;

import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector3f;

/**
* Post-ReWrite code
Expand Down Expand Up @@ -52,6 +53,11 @@ public static Vec3f normalized(float x, float y, float z)
return d < 1.0E-4 ? ZERO : new Vec3f(x / d, y / d, z / d);
}

public Vector3f toVector()
{
return new Vector3f(this.getX(), this.getY(), this.getZ());
}

@Override
public String toString()
{
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/position/Vec3i.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fi.dy.masa.malilib.util.position;

import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector3i;

import net.minecraft.util.math.BlockPos;

/**
* Post-ReWrite code
Expand All @@ -26,6 +29,16 @@ public Vec3i(int x, int y, int z)
*/
}

public Vec3i of(BlockPos blockPos)
{
return new Vec3i(blockPos.getX(), blockPos.getY(), blockPos.getZ());
}

public Vec3i of(net.minecraft.util.math.Vec3i vanilla)
{
return new Vec3i(vanilla.getX(), vanilla.getY(), vanilla.getZ());
}

/*
public int getX()
{
Expand Down Expand Up @@ -58,6 +71,21 @@ public double squareDistanceOfCenterTo(Vec3d pos)
return (this.getX() + 0.5) * pos.x + (this.getY() + 0.5) * pos.y + (this.getZ() + 0.5) * pos.z;
}

public net.minecraft.util.math.Vec3i toVanilla()
{
return new net.minecraft.util.math.Vec3i(this.getX(), this.getY(), this.getZ());
}

public net.minecraft.util.math.BlockPos toBlockPos()
{
return new BlockPos(this.getX(), this.getY(), this.getZ());
}

public Vector3i toVector()
{
return new Vector3i(this.getX(), this.getY(), this.getZ());
}

@Override
public String toString()
{
Expand Down

0 comments on commit e8cde2e

Please sign in to comment.