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);
}
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);
}
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);
}
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;
}
Aggregations