#Is there a way to only damage one of the ingredients in smithing recipe?

6 messages · Page 1 of 1 (latest)

hexed isle
#

I really wanna know if it's even possible to do.

ornate deltaBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

jaunty chasm
#

But there's a hacky way for this

const playersClosedSmithingMenu = new Set()
const playerTempStoredSmithingMenu = {}
/**
 * 
 * @param {Internal.Player} player 
 * @param {Internal.SmithingMenu} menu 
 */
const customSmithing = (player, menu) => {
    const hashCode = player.uuid.hashCode()
    const {TEMPLATE_SLOT, BASE_SLOT, ADDITIONAL_SLOT, RESULT_SLOT} = menu
    const slots = [TEMPLATE_SLOT, BASE_SLOT, ADDITIONAL_SLOT, RESULT_SLOT]
    const smithingItems = [TEMPLATE_SLOT, BASE_SLOT, ADDITIONAL_SLOT, RESULT_SLOT].map(slotIndex => menu.getSlot(slotIndex).item) 
    const ready = smithingItems.every(item => !item.empty)
    let ptsm = playerTempStoredSmithingMenu
    if(!ptsm[hashCode]) ptsm[hashCode] = {resultsStored: []}
    let resultsStored = ptsm[hashCode].resultsStored
    if(ready && resultsStored.length == 0){
        resultsStored = smithingItems.map(item => item.copy());
        ptsm[hashCode].resultsStored = resultsStored
    } 
    if(
        resultsStored.length
        && resultsStored.every((itemStored, index) => itemStored.withCount(itemStored.count - 1) == (smithingItems[index]))
    ){
        let additionalItem = resultsStored[slots.indexOf(ADDITIONAL_SLOT)]
        if(additionalItem.damageableItem){
            additionalItem.setDamageValue(additionalItem.damageValue + 1)
            if(additionalItem.damageValue < additionalItem.maxDamage){
                menu.setItem(ADDITIONAL_SLOT, 1, additionalItem)
            }
        }
    }
    if(!ready){
        ptsm[hashCode].resultsStored = []
    } 

}
#
PlayerEvents.inventoryOpened("minecraft:smithing", event => {
    /*** @type {Internal.SmithingMenu} */
    const smithingMenu = event.inventoryContainer
    const {player, server} = event
    /**@type {Internal.ItemStack[]} */ let resultsStored = []
    const checkingSmithing = server.scheduleRepeatingInTicks(1, callback => {
        if(playersClosedSmithingMenu.has(player.uuid.hashCode())){
            playersClosedSmithingMenu.delete(player.uuid.hashCode())
            delete playerTempStoredSmithingMenu[player.uuid.hashCode()]
            checkingSmithing.clear()
            delete checkingSmithing
            return;
        }
        customSmithing(player, smithingMenu)
    })

})
PlayerEvents.inventoryClosed("minecraft:smithing", event => {
    playersClosedSmithingMenu.add(event.player.uuid.hashCode())
})
#

This directly listen to changes in smithing table menu, and put the consumed additional item back with decreased durability.