#modify item durability

24 messages · Page 1 of 1 (latest)

nocturne mulch
#

I'm trying to modify the durability from the hammers and excavators of this mod. but the script doesn't work

ItemEvents.modification(event => {
event.modify('simplest_hammers:iron_hammer', item => {
    item.maxDamage = 1500
  }),
  event.modify('simplest_hammers:golden_hammer', item => {
    item.maxDamage = 192
  }),
   event.modify('simplest_hammers:diamond_hammer', item => {
    item.maxDamage = 9364
  }),
  event.modify('simplest_hammers:netherite_hammer', item => {
    item.maxDamage = 12184
  })
})

ItemEvents.modification(event => {
event.modify('simplest_excavators:iron_excavator', item => {
    item.maxDamage = 1500
  }),
  event.modify('simplest_excavators:golden_excavator', item => {
    item.maxDamage = 192
  }),
   event.modify('simplest_excavators:diamond_excavator', item => {
    item.maxDamage = 9364
  }),
  event.modify('simplest_excavators:netherite_excavator', item => {
    item.maxDamage = 12184
  })
})```
surreal pivotBOT
#

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

clear radish
#

without logs, I can only hazard to guess that the issue is the trailing commas between lines.
Once you close off a modify function with the }) either just start a new line, or close it with ; not ,. The comma is usually used in collections to differentiate between objects. That does not apply here

You may be interested in removing so much of the repeated code. This code is an example of creating a collection of simple objects, each consisting of name & dmg values
It then goes over each object in the collection, and modifies the corresponding tool with that same name, and sets maxDamage to the damage supplied
You just need to add the other tools into that tools collection. This does use commas between objects to differentiate between them

const tools = [
    { name: 'simplest_hammers:iron_hammer', damage: 1500 },
    { name: 'simplest_hammers:golden_hammer', damage: 192 },
    { name: 'simplest_hammers:diamond_hammer', damage: 9364 }
]

ItemEvents.modification(event => {
    tools.forEach(tool => {
        event.modify(tool.name, item => {
            item.maxDamage = tool.damage
        })
    })
})
nocturne mulch
reef waveBOT
#

Paste version of startup.log from @nocturne mulch

nocturne mulch
#

in game durability still 750

lofty abyss
lofty abyss
# nocturne mulch no

ok i got it working from the example matryoshka gave:


const tools = [
    { name: 'iceandfire:copper_sword', damage: 1500 }
]

ItemEvents.modification(event => {
    tools.forEach(tool => {
        event.modify(tool.name, item => {
            item.maxDamage = tool.damage
        })
    })
})

#

ill try to also modify attack dmg, attack speed and dig speed

#

btw is digspeed and armor in general just broken ?

nocturne mulch
#

so it works for everyone but me ahujel

lofty abyss
#

// kubejs/startup_scripts/edit_items.js

// Define the tools you want to modify
const tools = [
    { name: 'iceandfire:copper_sword', damage: 200, attack: 6 },
    { name: 'iceandfire:copper_axe', damage: 200, attack: 9 },
    { name: 'iceandfire:copper_pickaxe', damage: 200, attack: 4 },
    { name: 'iceandfire:copper_shovel', damage: 200, attack: 4 },
    { name: 'iceandfire:copper_hoe', damage: 200, attack: 1 }
];

ItemEvents.modification(event => {
    tools.forEach(tool => {
        event.modify(tool.name, item => {
            item.maxDamage = tool.damage;       // durability
            item.attackDamage = tool.attack;    // base attack damage
        });
    });
});

nocturne mulch
#

mines the same

const tools = [
    { name: 'simplest_hammers:iron_hammer', damage: 1500 },
    { name: 'simplest_hammers:golden_hammer', damage: 192 },
    { name: 'simplest_hammers:diamond_hammer', damage: 9364 }
]

ItemEvents.modification(event => {
    tools.forEach(tool => {
        event.modify(tool.name, item => {
            item.maxDamage = tool.damage
        })
    })
})```
nocturne mulch
#

what?

nocturne mulch
#

??codeblock

reef waveBOT
# nocturne mulch ??codeblock

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
nocturne mulch
#

this

#

ok so

#

you know what would help this work?

Me having the code in the right curseforge profile