Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. private static BlockPos getBlockPosFromCompound(NBTTagCompound pos) {
  2. return new BlockPos(pos.getInt("x"), pos.getInt("y"), pos.getInt("z"));
  3. }
  4. /**
  5. * Translates BlockPos to a String form
  6. * @param coords
  7. * @return
  8. */
  9. static NBTTagCompound serializePos(BlockPos coords) {
  10. if (coords == null) {
  11. return null;
  12. }
  13. NBTTagCompound cmp = new NBTTagCompound();
  14. cmp.setInt("x", coords.x);
  15. cmp.setInt("y", coords.y);
  16. cmp.setInt("z", coords.z);
  17. return cmp;
  18. }
  19.  
  20. private static final Pattern COLON_SPLIT = Pattern.compile(":");
  21. /**
  22. * Parses a string into BlockPos
  23. *
  24. * @deprecated Only used for reading old data
  25. * @param loc
  26. * @return
  27. */
  28. static BlockPos deserializeOldLoc(String loc) {
  29. if (loc != null) {
  30. String[] args = COLON_SPLIT.split(loc, 3);
  31. if (args.length == 3) {
  32. try {
  33. int x = (int) Math.floor(Float.parseFloat(args[0]));
  34. int y = (int) Math.floor(Float.parseFloat(args[1]));
  35. int z = (int) Math.floor(Float.parseFloat(args[2]));
  36. return new BlockPos(x, y, z);
  37. } catch (NumberFormatException inored) {}
  38. }
  39. }
  40. return null;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement