Search in sources :

Example 1 with ItemRequirement

use of de.teamlapen.vampirism.player.tasks.req.ItemRequirement in project Vampirism by TeamLapen.

the class TaskManager method getStat.

private int getStat(@Nonnull ITaskInstance taskInstance, @Nonnull TaskRequirement.Requirement<?> requirement) {
    Map<ResourceLocation, Integer> stats = taskInstance.getStats();
    if (!taskInstance.isAccepted())
        return 0;
    int neededStat = 0;
    int actualStat = 0;
    switch(requirement.getType()) {
        case STATS:
            actualStat = this.player.getStats().getValue(Stats.CUSTOM.get((ResourceLocation) requirement.getStat(this.factionPlayer)));
            neededStat = stats.get(requirement.getId()) + requirement.getAmount(this.factionPlayer);
            break;
        case ENTITY:
            actualStat = this.player.getStats().getValue(Stats.ENTITY_KILLED.get((EntityType<?>) requirement.getStat(this.factionPlayer)));
            neededStat = stats.get(requirement.getId()) + requirement.getAmount(this.factionPlayer);
            break;
        case ENTITY_TAG:
            // noinspection unchecked
            for (EntityType<?> type : ((ITag.INamedTag<EntityType<?>>) requirement.getStat(this.factionPlayer)).getValues()) {
                actualStat += this.player.getStats().getValue(Stats.ENTITY_KILLED.get(type));
            }
            neededStat = stats.get(requirement.getId()) + requirement.getAmount(this.factionPlayer);
            break;
        case ITEMS:
            ItemStack stack = ((ItemRequirement) requirement).getItemStack();
            neededStat = stack.getCount();
            actualStat = this.player.inventory.countItem(stack.getItem());
            break;
        case BOOLEAN:
            if (!(Boolean) requirement.getStat(this.factionPlayer))
                return 0;
            return 1;
    }
    return Math.min(requirement.getAmount(this.factionPlayer) - (neededStat - actualStat), requirement.getAmount(this.factionPlayer));
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ItemRequirement(de.teamlapen.vampirism.player.tasks.req.ItemRequirement) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemRequirement

use of de.teamlapen.vampirism.player.tasks.req.ItemRequirement in project Vampirism by TeamLapen.

the class TaskItem method renderDummy.

@Override
public void renderDummy(MatrixStack matrixStack, int x, int y, int listWidth, int listHeight, int itemHeight, int mouseX, int mouseY, float partialTicks, float zLevel) {
    // render background
    RenderSystem.enableDepthTest();
    GuiUtils.drawContinuousTexturedBox(matrixStack, TASKMASTER_GUI_TEXTURE, x, y, 17, 208, listWidth, itemHeight, 136, 21, 3, 3, 3, 3, zLevel);
    RenderSystem.disableDepthTest();
    // render content
    ITaskRewardInstance reward = this.item.getReward();
    if (reward instanceof ItemRewardInstance) {
        ItemStack stack = ((ItemRewardInstance) reward).getReward();
        this.screen.getItemRenderer().renderAndDecorateItem(stack, x + 3 + 113 - 21, y + 2);
        this.screen.getItemRenderer().renderGuiItemDecorations(this.screen.font, stack, x + 3 + 113 - 21, y + 2, "" + Math.min(stack.getCount(), stack.getMaxStackSize()));
    } else {
        this.screen.getItemRenderer().renderAndDecorateItem(PAPER, x + 3 + 113 - 21, y + 2);
    }
    List<TaskRequirement.Requirement<?>> requirements = this.item.getTask().getRequirement().getAll();
    for (int i = 0; i < requirements.size(); i++) {
        TaskRequirement.Requirement<?> requirement = requirements.get(i);
        switch(requirement.getType()) {
            case ITEMS:
                ItemStack stack = ((ItemRequirement) requirement).getItemStack();
                this.screen.getItemRenderer().renderAndDecorateItem(stack, x + 3 + 3 + i * 20, y + 2);
                this.screen.getItemRenderer().renderGuiItemDecorations(this.screen.font, stack, x + 3 + 3 + i * 20, y + 2, "" + Math.min(stack.getCount(), stack.getMaxStackSize()));
                break;
            case ENTITY:
            case ENTITY_TAG:
                this.screen.getItemRenderer().renderAndDecorateItem(SKULL_ITEM, x + 3 + 3 + i * 20, y + 2);
                this.screen.getItemRenderer().renderGuiItemDecorations(this.screen.font, SKULL_ITEM, x + 3 + 3 + i * 20, y + 2, "" + requirement.getAmount(factionPlayer));
                break;
            default:
                this.screen.getItemRenderer().renderAndDecorateItem(PAPER, x + 3 + 3 + i * 20, y + 2);
                break;
        }
    }
    // render task button
    this.taskButton.x = x + listWidth - 17;
    this.taskButton.y = y + 4;
    this.taskButton.render(matrixStack, mouseX, mouseY, partialTicks);
}
Also used : TaskRequirement(de.teamlapen.vampirism.api.entity.player.task.TaskRequirement) ItemRequirement(de.teamlapen.vampirism.player.tasks.req.ItemRequirement) ItemRewardInstance(de.teamlapen.vampirism.player.tasks.reward.ItemRewardInstance) ITaskRewardInstance(de.teamlapen.vampirism.api.entity.player.task.ITaskRewardInstance) TaskRequirement(de.teamlapen.vampirism.api.entity.player.task.TaskRequirement) ItemRequirement(de.teamlapen.vampirism.player.tasks.req.ItemRequirement) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemRequirement (de.teamlapen.vampirism.player.tasks.req.ItemRequirement)2 ItemStack (net.minecraft.item.ItemStack)2 ITaskRewardInstance (de.teamlapen.vampirism.api.entity.player.task.ITaskRewardInstance)1 TaskRequirement (de.teamlapen.vampirism.api.entity.player.task.TaskRequirement)1 ItemRewardInstance (de.teamlapen.vampirism.player.tasks.reward.ItemRewardInstance)1 ResourceLocation (net.minecraft.util.ResourceLocation)1