use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.
the class GuiRewardEditDefault method setValue.
@Override
public void setValue(NBTTagCompound value) {
IReward reward = quest.getRewards().getValue(rID);
if (reward != null) {
reward.readFromNBT(value, EnumSaveType.CONFIG);
this.SendChanges();
}
}
use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.
the class RewardStorage method writeToNBT.
@Override
public NBTTagList writeToNBT(NBTTagList json, EnumSaveType saveType) {
if (saveType != EnumSaveType.CONFIG) {
return json;
}
for (Entry<Integer, IReward> rew : database.entrySet()) {
ResourceLocation rewardID = rew.getValue().getFactoryID();
NBTTagCompound rJson = rew.getValue().writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG);
rJson.setString("rewardID", rewardID.toString());
rJson.setInteger("index", rew.getKey());
json.appendTag(rJson);
}
return json;
}
use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.
the class RewardStorage method readFromNBT.
@Override
public void readFromNBT(NBTTagList json, EnumSaveType saveType) {
if (saveType != EnumSaveType.CONFIG) {
return;
}
database.clear();
ArrayList<IReward> unassigned = new ArrayList<IReward>();
for (int i = 0; i < json.tagCount(); i++) {
NBTBase entry = json.get(i);
if (entry == null || entry.getId() != 10) {
continue;
}
NBTTagCompound jsonReward = (NBTTagCompound) entry;
ResourceLocation loc = new ResourceLocation(jsonReward.getString("rewardID"));
int index = jsonReward.hasKey("index", 99) ? jsonReward.getInteger("index") : -1;
IReward reward = RewardRegistry.INSTANCE.createReward(loc);
if (reward instanceof RewardPlaceholder) {
NBTTagCompound jr2 = jsonReward.getCompoundTag("orig_data");
ResourceLocation loc2 = new ResourceLocation(jr2.getString("rewardID"));
IReward r2 = RewardRegistry.INSTANCE.createReward(loc2);
if (r2 != null) {
jsonReward = jr2;
reward = r2;
}
}
if (reward != null) {
reward.readFromNBT(jsonReward, EnumSaveType.CONFIG);
if (index >= 0) {
add(reward, index);
} else {
unassigned.add(reward);
}
} else {
RewardPlaceholder rph = new RewardPlaceholder();
rph.setRewardData(jsonReward, EnumSaveType.CONFIG);
if (index >= 0) {
add(rph, index);
} else {
unassigned.add(rph);
}
}
}
for (IReward r : unassigned) {
add(r, nextKey());
}
}
Aggregations