Advertisement
Lanzr

paste

Jun 25th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package net.lanzr.tpCast.api;
  2.  
  3. import net.lanzr.tpCast.tpCast;
  4. import net.minecraft.core.BlockPos;
  5. import net.minecraft.nbt.CompoundTag;
  6. import net.minecraft.server.level.ServerPlayer;
  7. import net.minecraft.world.phys.Vec3;
  8. import org.apache.commons.lang3.tuple.Pair;
  9.  
  10. public class tpCastTag {
  11. private CompoundTag mTag;
  12. private ServerPlayer mPlayer;
  13. public String
  14. HomePosAlias ="homePos",
  15. HomeDimAlias ="homeDim",
  16. BackPosAlias ="backPos",
  17. BackDimAlias ="backDim";
  18. public tpCastTag(ServerPlayer player) {
  19. CompoundTag pTag = player.getPersistentData();
  20. mTag = pTag.getCompound(tpCast.MODID);
  21. mPlayer = player;
  22. if(!pTag.contains(tpCast.MODID)) {
  23. pTag.put(tpCast.MODID,mTag);
  24. }
  25. }
  26.  
  27. public boolean hasKey(String str){
  28. return mTag.contains(str);
  29. }
  30.  
  31. public void rmKey(String str) {
  32. mTag.remove(str);
  33. }
  34.  
  35. public void setHome() {
  36. BlockPos playerPos = mPlayer.getOnPos();
  37. mTag.putIntArray(HomePosAlias,new int[]{playerPos.getX(), playerPos.getY(), playerPos.getZ()});
  38. mTag.putString(HomeDimAlias,mPlayer.getLevel().dimension().location().toString());
  39. }
  40. public void setHome(Vec3 pos, String dim) {
  41. mTag.putIntArray(HomePosAlias,new int[]{(int)pos.x,(int)pos.y,(int)pos.z});
  42. mTag.putString(HomeDimAlias, dim);
  43. }
  44. public Pair<Vec3, String> getHome() {
  45. int[] pos = mTag.getIntArray(HomePosAlias);
  46. Vec3 vec = new Vec3(pos[0],pos[1],pos[2]);
  47. String dim = mTag.getString(HomeDimAlias);
  48. return Pair.of(vec, dim);
  49. }
  50.  
  51. public void setBack() {
  52. BlockPos playerPos = mPlayer.getOnPos();
  53. mTag.putIntArray(BackPosAlias,new int[]{playerPos.getX(), playerPos.getY(), playerPos.getZ()});
  54. mTag.putString(BackDimAlias,mPlayer.getLevel().dimension().location().toString());
  55. }
  56.  
  57. public void setBack(Vec3 pos, String dim) {
  58. mTag.putIntArray(BackPosAlias,new int[]{(int)pos.x,(int)pos.y,(int)pos.z});
  59. mTag.putString(BackDimAlias, dim);
  60. }
  61.  
  62. public Pair<Vec3, String> getBack() {
  63. int[] pos = mTag.getIntArray(BackPosAlias);
  64. Vec3 vec = new Vec3(pos[0],pos[1],pos[2]);
  65. String dim = mTag.getString(BackDimAlias);
  66. return Pair.of(vec, dim);
  67. }
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement