Advertisement
v1993

Untitled

Nov 9th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import crafttweaker.data.IData;
  2. import crafttweaker.player.IPlayer;
  3.  
  4. // Helper functions to manage custom per-player data.
  5.  
  6. function SetSoLData(pl as IPlayer, solData as IData) {
  7. if (pl.world.isRemote()) {
  8. print("Attempting to call SetSoLData from client side!");
  9. //return;
  10. }
  11.  
  12. val solDataContainer as IData = {PlayerPersisted: {solData: solData}};
  13. pl.setNBT(solDataContainer);
  14. }
  15.  
  16. function GetSoLData(pl as IPlayer) as IData {
  17. // Try to read solData from player data
  18. var plData = pl.nbt.ForgeData.PlayerPersisted as IData;
  19. var solData = plData.solData;
  20.  
  21. if (!isNull(solData)) {
  22. // Per-player data found, check version
  23. val ver = solData.dataVersion;
  24. // TODO: move into value at the top
  25. if (ver.asInt() == 0) {
  26. return solData;
  27. } else {
  28. print("Spice Of Life: CT Edition: invalid data version found, resetting data");
  29. }
  30. }
  31.  
  32. print("Spice Of Life: CT Edition: generating new data");
  33. val tastedFoods = {} as IData;
  34. val recentFoods = {} as IData;
  35. solData = {
  36. tastedFoods: tastedFoods,
  37. recentFoods: recentFoods,
  38.  
  39. dataVersion: 0
  40. } as IData;
  41. SetSoLData(pl, solData);
  42. return solData;
  43. }
  44.  
  45. // Calculate modified food value
  46. // TESTING ONLY - WILL CHANGE LATER!!!
  47.  
  48. mods.hungertweaker.events.HungerEvents.onGetFoodValues(function(event as mods.hungertweaker.events.GetFoodValuesEvent) {
  49. val dat = GetSoLData(event.player);
  50. //print("Read data!");
  51. });
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement