Search in sources :

Example 1 with Task

use of de.teamlapen.vampirism.api.entity.player.task.Task in project Vampirism by TeamLapen.

the class TaskItem method generateTaskToolTip.

private void generateTaskToolTip(ITaskInstance taskInfo, List<ITextComponent> toolTips) {
    Task task = taskInfo.getTask();
    toolTips.clear();
    toolTips.add(task.getTranslation().plainCopy().withStyle(this.screen.getTaskContainer().getFactionColor()));
    if (task.useDescription()) {
        toolTips.add(task.getDescription());
        toolTips.add(new StringTextComponent(" "));
    }
    if (this.screen.getTaskContainer().isTaskNotAccepted(taskInfo)) {
        toolTips.add(new TranslationTextComponent("gui.vampirism.taskmaster.not_accepted"));
    } else {
        for (List<TaskRequirement.Requirement<?>> requirements : task.getRequirement().requirements().values()) {
            if (requirements == null)
                continue;
            TaskRequirement.Type type = requirements.get(0).getType();
            boolean completed = this.screen.getTaskContainer().areRequirementsCompleted(taskInfo, type);
            IFormattableTextComponent title = new TranslationTextComponent(type.getTranslationKey()).append(":");
            if (completed) {
                title.withStyle(TextFormatting.STRIKETHROUGH);
            }
            toolTips.add(title);
            for (TaskRequirement.Requirement<?> requirement : requirements) {
                IFormattableTextComponent desc;
                int completedAmount = this.screen.getTaskContainer().getRequirementStatus(taskInfo, requirement);
                switch(type) {
                    case ITEMS:
                        desc = ((Item) requirement.getStat(this.factionPlayer)).getDescription().plainCopy().append(" " + completedAmount + "/" + requirement.getAmount(this.factionPlayer));
                        break;
                    case STATS:
                        desc = new TranslationTextComponent("stat." + requirement.getStat(this.factionPlayer).toString().replace(':', '.')).append(" " + completedAmount + "/" + requirement.getAmount(this.factionPlayer));
                        break;
                    case ENTITY:
                        desc = (((EntityType<?>) requirement.getStat(this.factionPlayer)).getDescription().plainCopy().append(" " + completedAmount + "/" + requirement.getAmount(this.factionPlayer)));
                        break;
                    case ENTITY_TAG:
                        // noinspection unchecked
                        desc = new TranslationTextComponent("tasks.vampirism." + ((ITag.INamedTag<EntityType<?>>) requirement.getStat(this.factionPlayer)).getName()).append(" " + completedAmount + "/" + requirement.getAmount(this.factionPlayer));
                        break;
                    default:
                        desc = new TranslationTextComponent(task.getTranslationKey() + ".req." + requirement.getId().toString().replace(':', '.'));
                        break;
                }
                if (completed || this.screen.getTaskContainer().isRequirementCompleted(taskInfo, requirement)) {
                    desc.withStyle(TextFormatting.STRIKETHROUGH);
                }
                toolTips.add(new StringTextComponent("  ").append(desc));
            }
        }
    }
    this.toolTips.put(taskInfo, toolTips);
}
Also used : Task(de.teamlapen.vampirism.api.entity.player.task.Task) TaskRequirement(de.teamlapen.vampirism.api.entity.player.task.TaskRequirement) EntityType(net.minecraft.entity.EntityType) TaskRequirement(de.teamlapen.vampirism.api.entity.player.task.TaskRequirement) ItemRequirement(de.teamlapen.vampirism.player.tasks.req.ItemRequirement)

Example 2 with Task

use of de.teamlapen.vampirism.api.entity.player.task.Task in project Vampirism by TeamLapen.

the class TaskInstance method readNBT.

/**
 * @return {@code null} if the task does not exist
 */
@Nullable
public static TaskInstance readNBT(@Nonnull CompoundNBT nbt) {
    Task task = ModRegistries.TASKS.getValue(new ResourceLocation(nbt.getString("task")));
    if (task == null)
        return null;
    UUID id = nbt.getUUID("id");
    UUID insId = nbt.getUUID("insId");
    boolean accepted = nbt.getBoolean("accepted");
    long taskTimer = nbt.getLong("taskTimer");
    CompoundNBT statsNBT = nbt.getCompound("stats");
    Map<ResourceLocation, Integer> stats = new HashMap<>();
    statsNBT.getAllKeys().forEach(name -> {
        stats.put(new ResourceLocation(name), statsNBT.getInt(name));
    });
    ResourceLocation rewardId = new ResourceLocation(nbt.getString("rewardId"));
    ITaskRewardInstance reward = TaskManager.createReward(rewardId, nbt);
    long taskDuration = nbt.getLong("taskDuration");
    return new TaskInstance(id, task, stats, accepted, taskTimer, insId, reward, taskDuration);
}
Also used : ITaskInstance(de.teamlapen.vampirism.api.entity.player.task.ITaskInstance) Task(de.teamlapen.vampirism.api.entity.player.task.Task) CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.util.ResourceLocation) ITaskRewardInstance(de.teamlapen.vampirism.api.entity.player.task.ITaskRewardInstance) UUID(java.util.UUID) Nullable(javax.annotation.Nullable)

Example 3 with Task

use of de.teamlapen.vampirism.api.entity.player.task.Task in project Vampirism by TeamLapen.

the class TaskInstance method decode.

public static TaskInstance decode(PacketBuffer buffer) {
    UUID id = buffer.readUUID();
    Task task = ModRegistries.TASKS.getValue(buffer.readResourceLocation());
    UUID insId = buffer.readUUID();
    boolean accepted = buffer.readBoolean();
    long taskTimer = buffer.readVarLong();
    int statsAmount = buffer.readVarInt();
    Map<ResourceLocation, Integer> stats = new HashMap<>();
    for (int i = 0; i < statsAmount; i++) {
        stats.put(buffer.readResourceLocation(), buffer.readVarInt());
    }
    ResourceLocation rewardId = buffer.readResourceLocation();
    ITaskRewardInstance reward = TaskManager.createReward(rewardId, buffer);
    long taskDuration = buffer.readVarLong();
    return new TaskInstance(id, task, stats, accepted, taskTimer, insId, reward, taskDuration);
}
Also used : ITaskInstance(de.teamlapen.vampirism.api.entity.player.task.ITaskInstance) Task(de.teamlapen.vampirism.api.entity.player.task.Task) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.util.ResourceLocation) ITaskRewardInstance(de.teamlapen.vampirism.api.entity.player.task.ITaskRewardInstance) UUID(java.util.UUID)

Example 4 with Task

use of de.teamlapen.vampirism.api.entity.player.task.Task in project Vampirism by TeamLapen.

the class TaskArgument method parse.

@Override
public Task parse(StringReader reader) throws CommandSyntaxException {
    ResourceLocation id = ResourceLocation.read(reader);
    Task task = ModRegistries.TASKS.getValue(id);
    if (task == null)
        throw TASK_NOT_FOUND.create(id);
    return task;
}
Also used : Task(de.teamlapen.vampirism.api.entity.player.task.Task) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

Task (de.teamlapen.vampirism.api.entity.player.task.Task)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 ITaskInstance (de.teamlapen.vampirism.api.entity.player.task.ITaskInstance)2 ITaskRewardInstance (de.teamlapen.vampirism.api.entity.player.task.ITaskRewardInstance)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 TaskRequirement (de.teamlapen.vampirism.api.entity.player.task.TaskRequirement)1 ItemRequirement (de.teamlapen.vampirism.player.tasks.req.ItemRequirement)1 Nullable (javax.annotation.Nullable)1 EntityType (net.minecraft.entity.EntityType)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1