Search in sources :

Example 1 with IMutableTinkerStationContainer

use of slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer in project TinkersConstruct by SlimeKnights.

the class TinkerStationRepairRecipe method updateInputs.

@Override
public void updateInputs(ItemStack result, IMutableTinkerStationContainer inv, boolean isServer) {
    ToolStack inputTool = ToolStack.from(inv.getTinkerableStack());
    ToolStack resultTool = ToolStack.from(result);
    // iterate stacks, removing items as we repair
    int repairRemaining = inputTool.getDamage() - resultTool.getDamage();
    MaterialId primaryMaterial = getPrimaryMaterial(inputTool);
    for (int i = 0; i < inv.getInputCount() && repairRemaining > 0; i++) {
        final int slot = i;
        repairRemaining -= repairFromSlot(inputTool, primaryMaterial, inv, repairRemaining, i, count -> inv.shrinkInput(slot, count));
    }
    if (repairRemaining > 0) {
        TConstruct.LOG.error("Recipe repair on {} consumed too few items. {} durability unaccounted for", result, repairRemaining);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialStatsId(slimeknights.tconstruct.library.materials.stats.MaterialStatsId) IntStream(java.util.stream.IntStream) Getter(lombok.Getter) IToolPart(slimeknights.tconstruct.library.tools.part.IToolPart) RequiredArgsConstructor(lombok.RequiredArgsConstructor) IntConsumer(java.util.function.IntConsumer) ToolDamageUtil(slimeknights.tconstruct.library.tools.helper.ToolDamageUtil) ToolDefinitionData(slimeknights.tconstruct.library.tools.definition.ToolDefinitionData) TinkerToolParts(slimeknights.tconstruct.tools.TinkerToolParts) ToolDefinition(slimeknights.tconstruct.library.tools.definition.ToolDefinition) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) Nullable(javax.annotation.Nullable) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) TinkerTables(slimeknights.tconstruct.tables.TinkerTables) IToolStackView(slimeknights.tconstruct.library.tools.nbt.IToolStackView) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) TinkerTags(slimeknights.tconstruct.common.TinkerTags) ValidatedResult(slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult) ITinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationContainer) ITinkerStationRecipe(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationRecipe) TConstruct(slimeknights.tconstruct.TConstruct) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) IMaterialItem(slimeknights.tconstruct.library.tools.part.IMaterialItem) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) IMutableTinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack)

Example 2 with IMutableTinkerStationContainer

use of slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer in project TinkersConstruct by SlimeKnights.

the class ModifierRemovalRecipe method updateInputs.

@Override
public void updateInputs(ItemStack result, IMutableTinkerStationContainer inv, boolean isServer) {
    // return salvage items for modifier, using the original tool as that still has the modifier
    if (isServer) {
        ItemStack toolStack = inv.getTinkerableStack();
        ToolStack tool = ToolStack.from(toolStack);
        ModifierEntry toRemove = getModifierToRemove(inv, tool.getUpgrades().getModifiers());
        if (toRemove != null) {
            AbstractModifierSalvage salvage = ModifierRecipeLookup.getSalvage(toolStack, tool, toRemove.getModifier(), toRemove.getLevel());
            if (salvage != null) {
                int salvageMax = Math.min(toolStack.getMaxStackSize(), salvage.getMaxToolSize());
                int currentSize = result.getCount();
                Consumer<ItemStack> consumer;
                // if the size is smaller than 16, shrink all salvage stack sizes to prevent a salvage dupe
                if (currentSize < salvageMax) {
                    consumer = stack -> {
                        int newSize = stack.getCount() * currentSize / salvageMax;
                        if (newSize > 0) {
                            stack.setCount(newSize);
                            inv.giveItem(stack);
                        }
                    };
                // if larger, grow salvage
                } else if (currentSize > salvageMax) {
                    consumer = stack -> {
                        int newSize = stack.getCount() * currentSize / salvageMax;
                        int maxStackSize = stack.getMaxStackSize();
                        while (newSize > maxStackSize) {
                            inv.giveItem(ItemHandlerHelper.copyStackWithSize(stack, maxStackSize));
                            newSize -= maxStackSize;
                        }
                        if (newSize > 0) {
                            stack.setCount(newSize);
                            inv.giveItem(stack);
                        }
                    };
                } else {
                    consumer = inv::giveItem;
                }
                salvage.acceptItems(tool, consumer, TConstruct.RANDOM);
            }
        }
    }
    // remove the input item, done second as we need its location for salvage
    for (int i = 0; i < inv.getInputCount(); i++) {
        ItemStack stack = inv.getInput(i);
        if (!stack.isEmpty() && ingredient.test(stack)) {
            inv.shrinkInput(i, 1, container.copy());
            break;
        }
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) LoggingRecipeSerializer(slimeknights.mantle.recipe.helper.LoggingRecipeSerializer) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ModifierRecipeLookup(slimeknights.tconstruct.library.recipe.modifiers.ModifierRecipeLookup) TinkerModifiers(slimeknights.tconstruct.tools.TinkerModifiers) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) Ingredient(net.minecraft.world.item.crafting.Ingredient) AbstractRecipeBuilder(slimeknights.mantle.recipe.data.AbstractRecipeBuilder) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) AbstractModifierSalvage(slimeknights.tconstruct.library.recipe.modifiers.salvage.AbstractModifierSalvage) Nullable(javax.annotation.Nullable) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) TinkerTags(slimeknights.tconstruct.common.TinkerTags) IncrementalModifierRecipeBuilder(slimeknights.tconstruct.library.recipe.modifiers.adding.IncrementalModifierRecipeBuilder) ValidatedResult(slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult) FinishedRecipe(net.minecraft.data.recipes.FinishedRecipe) ITinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationContainer) IncrementalModifierRecipe(slimeknights.tconstruct.library.recipe.modifiers.adding.IncrementalModifierRecipe) ITinkerStationRecipe(slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationRecipe) TConstruct(slimeknights.tconstruct.TConstruct) Objects(java.util.Objects) Consumer(java.util.function.Consumer) JsonHelper(slimeknights.mantle.util.JsonHelper) List(java.util.List) Modifier(slimeknights.tconstruct.library.modifiers.Modifier) IMutableTinkerStationContainer(slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) ItemStack(net.minecraft.world.item.ItemStack) ToolStack(slimeknights.tconstruct.library.tools.nbt.ToolStack) AbstractModifierSalvage(slimeknights.tconstruct.library.recipe.modifiers.salvage.AbstractModifierSalvage)

Aggregations

Nullable (javax.annotation.Nullable)2 Getter (lombok.Getter)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 ItemStack (net.minecraft.world.item.ItemStack)2 RecipeSerializer (net.minecraft.world.item.crafting.RecipeSerializer)2 Level (net.minecraft.world.level.Level)2 TConstruct (slimeknights.tconstruct.TConstruct)2 TinkerTags (slimeknights.tconstruct.common.TinkerTags)2 ModifierEntry (slimeknights.tconstruct.library.modifiers.ModifierEntry)2 IMutableTinkerStationContainer (slimeknights.tconstruct.library.recipe.tinkerstation.IMutableTinkerStationContainer)2 ITinkerStationContainer (slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationContainer)2 ITinkerStationRecipe (slimeknights.tconstruct.library.recipe.tinkerstation.ITinkerStationRecipe)2 ValidatedResult (slimeknights.tconstruct.library.recipe.tinkerstation.ValidatedResult)2 ToolStack (slimeknights.tconstruct.library.tools.nbt.ToolStack)2 JsonObject (com.google.gson.JsonObject)1 List (java.util.List)1 Objects (java.util.Objects)1 Consumer (java.util.function.Consumer)1 IntConsumer (java.util.function.IntConsumer)1