Skip to content

Commit

Permalink
Update NbtUtils with BlockPos and EntityPos calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Dec 10, 2024
1 parent fb9ddba commit 11465d7
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/main/java/fi/dy/masa/malilib/util/nbt/NbtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,35 @@ public static <T> NbtList asListTag(Collection<T> values, Function<T, NbtElement
return list;
}

public static NbtCompound createBlockPosTag(Vec3i pos)
public static @NotNull NbtCompound createBlockPosTag(@Nonnull BlockPos pos)
{
return writeBlockPos(pos, new NbtCompound());
}

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

public static NbtCompound putVec3i(@Nonnull NbtCompound tag, @Nonnull Vec3i pos)
public static @NotNull NbtCompound createEntityPositionToTag(@Nonnull Vec3d pos)
{
return writeVec3dToListTag(pos, new NbtCompound(), NbtKeys.POS);
}

public static @NotNull NbtCompound putVec3i(@Nonnull NbtCompound tag, @Nonnull Vec3i pos)
{
NbtWrap.putInt(tag, "x", pos.getX());
NbtWrap.putInt(tag, "y", pos.getY());
NbtWrap.putInt(tag, "z", pos.getZ());
return tag;
}

public static @NotNull NbtCompound writeBlockPos(@Nonnull BlockPos pos, @Nonnull NbtCompound tag)
{
NbtWrap.putInt(tag, "x", pos.getX());
NbtWrap.putInt(tag, "y", pos.getY());
NbtWrap.putInt(tag, "z", pos.getZ());

return tag;
}

Expand Down Expand Up @@ -171,7 +190,7 @@ public static BlockPos readBlockPosFromArrayTag(@Nonnull NbtCompound tag, String
return null;
}

public static NbtCompound removeBlockPosFromTag(@Nonnull NbtCompound tag)
public static @NotNull NbtCompound removeBlockPosFromTag(@Nonnull NbtCompound tag)
{
NbtWrap.remove(tag, "x");
NbtWrap.remove(tag, "y");
Expand All @@ -180,12 +199,17 @@ public static NbtCompound removeBlockPosFromTag(@Nonnull NbtCompound tag)
return tag;
}

public static NbtCompound writeVec3dToListTag(@Nonnull Vec3d pos, @Nonnull NbtCompound tag)
public static @NotNull NbtCompound writeEntityPositionToTag(@Nonnull Vec3d pos, @Nonnull NbtCompound tag)
{
return writeVec3dToListTag(pos, tag, NbtKeys.POS);
}

public static @NotNull NbtCompound writeVec3dToListTag(@Nonnull Vec3d pos, @Nonnull NbtCompound tag)
{
return writeVec3dToListTag(pos, tag, NbtKeys.POS);
}

public static NbtCompound writeVec3dToListTag(@Nonnull Vec3d pos, @Nonnull NbtCompound tag, String tagName)
public static @NotNull NbtCompound writeVec3dToListTag(@Nonnull Vec3d pos, @Nonnull NbtCompound tag, String tagName)
{
NbtList posList = new NbtList();

Expand Down Expand Up @@ -265,7 +289,7 @@ public static BlockPos readAttachedPosFromTag(@Nonnull NbtCompound tag)
* @param tag ()
* @return ()
*/
public static NbtCompound writeAttachedPosToTag(@Nonnull BlockPos pos, @Nonnull NbtCompound tag)
public static @NotNull NbtCompound writeAttachedPosToTag(@Nonnull BlockPos pos, @Nonnull NbtCompound tag)
{
tag.putInt("TileX", pos.getX());
tag.putInt("TileY", pos.getY());
Expand Down

0 comments on commit 11465d7

Please sign in to comment.