Search in sources :

Example 1 with IPartBuilderRecipe

use of slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe in project TinkersConstruct by SlimeKnights.

the class PartBuilderScreen method setDisplayForMaterial.

/**
 * Updates the data in the material display
 * @param materialRecipe  New material recipe
 */
private void setDisplayForMaterial(MaterialRecipe materialRecipe) {
    MaterialVariant materialVariant = materialRecipe.getMaterial();
    this.infoPanelScreen.setCaption(MaterialTooltipCache.getColoredDisplayName(materialVariant.getVariant()));
    // determine how much material we have
    // get exact number of material, rather than rounded
    float value = materialRecipe.getMaterialValue(this.tile.getInventoryWrapper());
    MutableComponent formatted = new TextComponent(Util.COMMA_FORMAT.format(value));
    // if we have a part recipe, mark material red when not enough
    IPartBuilderRecipe partRecipe = this.tile.getPartRecipe();
    if (partRecipe != null && value < partRecipe.getCost()) {
        formatted = formatted.withStyle(ChatFormatting.DARK_RED);
    }
    this.infoPanelScreen.setMaterialValue(formatted);
    // update stats and traits
    List<Component> stats = Lists.newLinkedList();
    List<Component> tips = Lists.newArrayList();
    // add warning that the material is uncraftable
    if (!materialVariant.get().isCraftable()) {
        stats.add(UNCRAFTABLE_MATERIAL);
        stats.add(TextComponent.EMPTY);
        tips.add(UNCRAFTABLE_MATERIAL_TOOLTIP);
        tips.add(TextComponent.EMPTY);
    }
    MaterialId id = materialVariant.getId();
    for (IMaterialStats stat : MaterialRegistry.getInstance().getAllStats(id)) {
        List<Component> info = stat.getLocalizedInfo();
        if (!info.isEmpty()) {
            stats.add(stat.getLocalizedName().withStyle(ChatFormatting.UNDERLINE));
            tips.add(TextComponent.EMPTY);
            stats.addAll(info);
            tips.addAll(stat.getLocalizedDescriptions());
            List<ModifierEntry> traits = MaterialRegistry.getInstance().getTraits(id, stat.getIdentifier());
            if (!traits.isEmpty()) {
                for (ModifierEntry trait : traits) {
                    Modifier mod = trait.getModifier();
                    stats.add(mod.getDisplayName(trait.getLevel()));
                    tips.add(mod.getDescription(trait.getLevel()));
                }
            }
            stats.add(TextComponent.EMPTY);
            tips.add(TextComponent.EMPTY);
        }
    }
    // remove last line if empty
    if (!stats.isEmpty() && stats.get(stats.size() - 1).getString().isEmpty()) {
        stats.remove(stats.size() - 1);
        tips.remove(tips.size() - 1);
    }
    this.infoPanelScreen.setText(stats, tips);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) IPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) MutableComponent(net.minecraft.network.chat.MutableComponent) MaterialVariant(slimeknights.tconstruct.library.materials.definition.MaterialVariant) IMaterialStats(slimeknights.tconstruct.library.materials.stats.IMaterialStats) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) MutableComponent(net.minecraft.network.chat.MutableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) Modifier(slimeknights.tconstruct.library.modifiers.Modifier)

Example 2 with IPartBuilderRecipe

use of slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe in project TinkersConstruct by SlimeKnights.

the class PartBuilderBlockEntity method onCraft.

@Override
public void onCraft(Player player, ItemStack result, int amount) {
    if (amount == 0 || this.level == null) {
        return;
    }
    // the recipe should match if we got this far, but being null is a problem
    IPartBuilderRecipe recipe = getPartRecipe();
    if (recipe == null) {
        return;
    }
    // we are definitely crafting at this point
    result.onCraftedBy(this.level, player, amount);
    ForgeEventFactory.firePlayerCraftingEvent(player, result, this.inventoryWrapper);
    this.playCraftSound(player);
    // give the player any leftovers
    ItemStack leftover = recipe.getLeftover(inventoryWrapper);
    if (!leftover.isEmpty()) {
        ItemHandlerHelper.giveItemToPlayer(player, leftover);
    }
    // shrink the inputs
    shrinkSlot(MATERIAL_SLOT, recipe.getItemsUsed(inventoryWrapper), player);
    if (!getItem(PATTERN_SLOT).is(TinkerTags.Items.REUSABLE_PATTERNS)) {
        shrinkSlot(PATTERN_SLOT, 1, player);
    }
    // sync display, mainly for the material value
    if (level != null && !level.isClientSide) {
        syncToRelevantPlayers(this::syncScreen);
    }
}
Also used : IPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with IPartBuilderRecipe

use of slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe in project TinkersConstruct by SlimeKnights.

the class PartBuilderScreen method updateDisplay.

@Override
public void updateDisplay() {
    // fixes the case where we added an item and lost recipes
    if (!canScroll()) {
        this.sliderProgress = 0.0F;
        this.recipeIndexOffset = 0;
    }
    // update part recipe cost
    IPartBuilderRecipe partRecipe = this.tile.getPartRecipe();
    if (partRecipe != null) {
        this.infoPanelScreen.setPatternCost(partRecipe.getCost());
    } else {
        this.infoPanelScreen.clearPatternCost();
    }
    // update material
    MaterialRecipe materialRecipe = this.tile.getMaterialRecipe();
    if (materialRecipe != null) {
        this.setDisplayForMaterial(materialRecipe);
    } else {
        // default text
        this.infoPanelScreen.setCaption(this.getTitle());
        this.infoPanelScreen.setText(INFO_TEXT);
        this.infoPanelScreen.clearMaterialValue();
    }
}
Also used : IPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe)

Aggregations

IPartBuilderRecipe (slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe)3 Component (net.minecraft.network.chat.Component)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ItemStack (net.minecraft.world.item.ItemStack)1 MaterialId (slimeknights.tconstruct.library.materials.definition.MaterialId)1 MaterialVariant (slimeknights.tconstruct.library.materials.definition.MaterialVariant)1 IMaterialStats (slimeknights.tconstruct.library.materials.stats.IMaterialStats)1 Modifier (slimeknights.tconstruct.library.modifiers.Modifier)1 ModifierEntry (slimeknights.tconstruct.library.modifiers.ModifierEntry)1 MaterialRecipe (slimeknights.tconstruct.library.recipe.material.MaterialRecipe)1