Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import crafttweaker.data.IData;
- import crafttweaker.player.IPlayer;
- // Helper functions to manage custom per-player data.
- function SetSoLData(pl as IPlayer, solData as IData) {
- if (pl.world.isRemote()) {
- print("Attempting to call SetSoLData from client side!");
- //return;
- }
- val solDataContainer as IData = {PlayerPersisted: {solData: solData}};
- pl.setNBT(solDataContainer);
- }
- function GetSoLData(pl as IPlayer) as IData {
- // Try to read solData from player data
- var plData = pl.nbt.ForgeData.PlayerPersisted as IData;
- var solData = plData.solData;
- if (!isNull(solData)) {
- // Per-player data found, check version
- val ver = solData.dataVersion;
- // TODO: move into value at the top
- if (ver.asInt() == 0) {
- return solData;
- } else {
- print("Spice Of Life: CT Edition: invalid data version found, resetting data");
- }
- }
- print("Spice Of Life: CT Edition: generating new data");
- val tastedFoods = {} as IData;
- val recentFoods = {} as IData;
- solData = {
- tastedFoods: tastedFoods,
- recentFoods: recentFoods,
- dataVersion: 0
- } as IData;
- SetSoLData(pl, solData);
- return solData;
- }
- // Calculate modified food value
- // TESTING ONLY - WILL CHANGE LATER!!!
- mods.hungertweaker.events.HungerEvents.onGetFoodValues(function(event as mods.hungertweaker.events.GetFoodValuesEvent) {
- val dat = GetSoLData(event.player);
- //print("Read data!");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement