Search in sources :

Example 6 with IReward

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();
    }
}
Also used : IReward(betterquesting.api.questing.rewards.IReward)

Example 7 with IReward

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;
}
Also used : IReward(betterquesting.api.questing.rewards.IReward) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 8 with IReward

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());
    }
}
Also used : IReward(betterquesting.api.questing.rewards.IReward) NBTBase(net.minecraft.nbt.NBTBase) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) RewardPlaceholder(betterquesting.api.placeholders.rewards.RewardPlaceholder)

Aggregations

IReward (betterquesting.api.questing.rewards.IReward)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 RewardPlaceholder (betterquesting.api.placeholders.rewards.RewardPlaceholder)2 ArrayList (java.util.ArrayList)2 EnumPartyStatus (betterquesting.api.enums.EnumPartyStatus)1 TaskPlaceholder (betterquesting.api.placeholders.tasks.TaskPlaceholder)1 IPropertyContainer (betterquesting.api.properties.IPropertyContainer)1 IQuest (betterquesting.api.questing.IQuest)1 IParty (betterquesting.api.questing.party.IParty)1 ITask (betterquesting.api.questing.tasks.ITask)1 GuiJsonEditor (betterquesting.client.gui.editors.json.scrolling.GuiJsonEditor)1 UserEntry (betterquesting.misc.UserEntry)1 QuestInstance (betterquesting.questing.QuestInstance)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 UUID (java.util.UUID)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 NBTBase (net.minecraft.nbt.NBTBase)1