Skip to content

Commit

Permalink
Update NbtUtils with Vec3i Int Array tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Dec 11, 2024
1 parent 72374d4 commit 0547cfb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 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,16 @@ public static <T> NbtList asListTag(Collection<T> values, Function<T, NbtElement
return putVec3i(new NbtCompound(), pos);
}

public static @NotNull NbtCompound createVec3iToArray(@Nonnull Vec3i pos, String tagName)
{
return writeBlockPosToArrayTag(pos, new NbtCompound(), tagName);
}

public static @NotNull NbtCompound createVec3iToArrayTag(@Nonnull Vec3i pos, String tagName)
{
return writeBlockPosToArrayTag(pos, new NbtCompound(), tagName);
}

public static @NotNull NbtCompound createEntityPosition(@Nonnull Vec3d pos)
{
return createEntityPositionToTag(pos);
Expand Down Expand Up @@ -144,6 +154,16 @@ public static <T> NbtList asListTag(Collection<T> values, Function<T, NbtElement
return tag;
}

public static @NotNull NbtCompound writeVec3iToArray(@Nonnull Vec3i pos, @Nonnull NbtCompound tag, String tagName)
{
return writeBlockPosToArrayTag(pos, tag, tagName);
}

public static @NotNull NbtCompound writeVec3iToArrayTag(@Nonnull Vec3i pos, @Nonnull NbtCompound tag, String tagName)
{
return writeBlockPosToArrayTag(pos, tag, tagName);
}

public static @NotNull NbtCompound writeBlockPosToArrayTag(@Nonnull Vec3i pos, @Nonnull NbtCompound tag, String tagName)
{
int[] arr = new int[] { pos.getX(), pos.getY(), pos.getZ() };
Expand Down Expand Up @@ -205,6 +225,28 @@ public static BlockPos readBlockPosFromArrayTag(@Nonnull NbtCompound tag, String
return null;
}

@Nullable
public static Vec3i readVec3iFromIntArray(@Nonnull NbtCompound nbt, String key)
{
return readVec3iFromIntArrayTag(nbt, key);
}

@Nullable
public static Vec3i readVec3iFromIntArrayTag(@Nonnull NbtCompound tag, String tagName)
{
if (NbtWrap.containsIntArray(tag, tagName))
{
int[] pos = NbtWrap.getIntArray(tag, tagName);

if (pos.length == 3)
{
return new Vec3i(pos[0], pos[1], pos[2]);
}
}

return null;
}

public static @NotNull NbtCompound removeBlockPos(@Nonnull NbtCompound tag)
{
return removeBlockPosFromTag(tag);
Expand Down

0 comments on commit 0547cfb

Please sign in to comment.