#how to edit vanilla armor protection values?

27 messages · Page 1 of 1 (latest)

sand raven
#

hello am new to KubeJS and coding in JavaScript. is there a way to edit vanilla armor protection values with this mod?

lavish kettleBOT
#

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

plain bear
#

For visibility, (took me a lot of searching and pain) this snippet in startup_scripts (using overrideComponent) modifies the armor value of the leather cap to 2 instead of 1. Modify the "amount" to whatever value you want. The "id" must be either "minecraft:armor.boots", "minecraft:armor.leggings", "minecraft:armor.helmet", "minecraft:armor.chestplate" so that the bonuses do not overwrite each other. Be sure to change "feet" into "chest", "legs" or "head" depending on the corresponding bodypart (at the end) so that the bonuses apply at those corresponding locations only:

ItemEvents.modification(event => {
  event.modify('minecraft:leather_helmet', item => {
  let itemAttributeModifier = $ItemAttributeModifiers.builder().add("generic.armor", { amount: 2, id: "minecraft:armor.boots", operation: "add_value" }, "feet").build()
    item.overrideComponent("attribute_modifiers", itemAttributeModifier)
  })
})

However, this process currently completely overwrites the whole "minecraft:attribute_modifiers" list, so if you want to keep armor toughness and netherite's knockback resistance, you'll have to add ".add()"s before the ".build()" containing the corresponding information. As to how those are handled, you can search the "netherite_boots" entry in the following json and look at "minecraft:attribute_modifiers": https://github.com/misode/mcmeta/blob/summary/item_components/data.json

plain bear
#

Update: you don't need to manually copy all other modifiers if you just want to modify any number of them! This code modifies the attack damage of a hoe, but it could be used for the armor as above

event.modify("minecraft:wooden_hoe", item => {
    let modifiedAttributeModifiers = Item.of(item.item().id).attributeModifiers.withModifierAdded("generic.attack_damage", { amount: 9, id: "minecraft:base_attack_damage", operation: "add_value" }, "mainhand")
    item.overrideComponent("attribute_modifiers", modifiedAttributeModifiers)
  })
rose fossil
#

Hi, I'm trying to modify the Knockback resistance value of an armor set. I think I could use Radeau's script above for that and tried it, but I get an error...

next epochBOT
#

Paste version of startup.log, main.js from @rose fossil

plain bear
daring stag
#

same issue here. maybe the method got deprecated after 2101 release. 119 runs on 2100
i have yet to find a solution, and honestly i don't think i care enough to search for one. the documentation is pretty lackluster or maybe i'm not looking in the right spots. methods available for item are:
setBurnTime; setMaxDamage; setCraftingRemainder; setDamage; patch; setFireResistant; setFireworkExplosion; setBaseColor; item; resetComponents; setProfile; setNoteBlockSound; setTier; setPotionContents; setLore; setGlintOverride; getCustomData; setMaxStackSize; setPotionId; setTool; setUnit; get; setLockCode; set; getCustomName; setAdditionalTooltipHidden; setAttributeModifiersWithTooltip; equals; setMapItemColor; toString; setInstrument; setUnbreakableWithTooltip; setItemName; setCustomName; setCustomModelData; setRepairCost; setBlockEntityData; setBucketEntityData; getComponentMap; setBlockStateProperties; setFood; setUnbreakable; setCustomData; setBundleContents; setDyedColorWithTooltip; setContainerLootTable; setDyedColor; disableRepair; setFireworks; setRarity; remove; hashCode; getComponentString; setEntityData; setAttributeModifiers; setTooltipHidden; setNameKey; setChargedProjectiles
no idea about the parameters. i'm "guessing" with error messages atm

rose fossil
#

Right, unfortunately version 119 correspond to minecraft 1.21 and I'm working on a 1.21.1 modpack. The earliest KubeJS version avalaible for 1.21.1 is 131 and I still get the same error...
I guess I'll have to find another solution

rose fossil
daring stag
#

tried before, but honestly javascript/ java is not my expertise

#

getting incorrect assignments / parameters

rose fossil
#

Yeah, I'm pretty new to this as well

daring stag
#

this was the error btw:

Cannot convert dev.latvian.mods.rhino.NativeJavaObject@390f166c to net.minecraft.world.item.component.ItemAttributeModifiers$Entry
daring stag
#

that's intentional because of internal issues. so be it. i couldn't find another way using kubejs and will stop looking now. like i said i don't care enough atm
i know it's just a free minecraft mod, but holy shit this is actually getting to me

plain bear
rose fossil
#

Alright, I installed version 119 manually in my modpack and your code works perfectly 🙂
I tried it on an armor piece and it sorta works? It didn't remove the previous modifier for some reason... (see the screen shot)

next epochBOT
#

Paste version of warden_armor_knockback.js from @rose fossil

rose fossil
#

Also, can I modify two modifiers on the same item?

plain bear
# rose fossil Also, can I modify two modifiers on the same item?

Yeah, you can chain multiple .withModifierAdded like in the following script:

event.modify("minecraft:trident", item => {
    let modifiedAttributeModifiers = Item.of(item.item().id).attributeModifiers.withModifierAdded("generic.attack_damage", { amount: 11, id: "minecraft:base_attack_damage", operation: "add_value" }, "mainhand").withModifierAdded("generic.attack_speed", { amount: -2.8, id: "minecraft:base_attack_speed", operation: "add_value" }, "mainhand").withModifierAdded("player.entity_interaction_range", { amount: 1.5, id: "minecraft:base_entity_interaction_range", operation: "add_value" }, "mainhand").withModifierAdded("generic.attack_damage", { amount: 4, id: "combat-plus:offhand_damage", operation: "add_value" }, "offhand")
    item.overrideComponent("attribute_modifiers", modifiedAttributeModifiers)
  })
plain bear
# rose fossil Alright, I installed version 119 manually in my modpack and your code works perf...

Idk what's going on there. I never touched knockback resistance, but my guess is that it's something to do with the attribute name or the id being different. Either that or knockback resistance is handled differently for black magic reasons. What I would do is to either:

  1. Somehow log the attributes of the item you want to modify so you can maybe inspect the correct attribute name and id to confirm whether or not it's an id mismatch or black magic
  2. Tear down all attributes and apply them manually yourself like I did with my armors here:
//Helper function to modify the armor value of an armor item
function modifyArmorValue(event, value, armorId, slot){
  let itemAttributeModifier = $ItemAttributeModifiers.builder().add("generic.armor", { amount: value, id: armorId, operation: "add_value" }, slot).add("generic.armor_toughness", { amount: 0, id: armorId, operation: "add_value" }, slot)
  event.overrideComponent("attribute_modifiers", itemAttributeModifier.build())
}

(Basically my first script)

rose fossil
#

You were right! It was an id mismatch! Thanks

#

For reference this is my corrected code :

ItemEvents.modification(event => {
  let kr = 0.2; // Knockback Resistance value
  let armorSet = [
    "deeperdarker:warden_helmet",
    "deeperdarker:warden_chestplate",
    "deeperdarker:warden_leggings",
    "deeperdarker:warden_boots"
  ];
  let armorIDs = [
    "minecraft:armor.helmet",
    "minecraft:armor.chestplate",
    "minecraft:armor.leggings",
    "minecraft:armor.boots"
  ];
  let armorSlots = [
    "head",
    "chest",
    "legs",
    "feet"
  ];

  // Loop through each armor piece and modify its attributes
  for (let i = 0; i < armorSet.length; i++) {
    event.modify(armorSet[i], item => {
      let modifiedAttributeModifiers = Item.of(item.item().id).attributeModifiers.withModifierAdded(
        "generic.knockback_resistance", { amount: kr, id: armorIDs[i], operation: "add_value" }, armorSlots[i]
      )
      item.overrideComponent("attribute_modifiers", modifiedAttributeModifiers)
  })}
});
rose fossil
#

Thank you for the help @plain bear !

twin agate
#

I found this thread looking at how to modify a helmet added by a mod, and with some digging, I found out a way to do this on the latest KubeJS for 1.21.1 where overrideComponent() has been removed. Instead you have setAttributeModifiers() and setAttributeModifiersWithTooltip() which take an array of ItemAttributeModifiers.Entry. So you can take the approach done earlier, but call modifiers() on the modified attributes to get the Entry array to pass back. In my case, I wanted to make an item actually have armor and integrate with another mod because of how I modified the recipe to be more expensive.

Here I use setAttributesWithTooltip() so that they show up in the tooltip UI. If you use setAttributes() by itself, the affect is still applied when equipped, but the tooltip will not include the attributes.

Hopefully this helps save time for the next person trying to do something like this.

  event.modify('mizs_broom:witch_hat_helmet', item => {
    // Create the updated set of modifiers 
    let modifiedAttributeModifiers = Item.of(item.item().id).attributeModifiers
      .withModifierAdded(
        "generic.armor", 
        { amount: 1, id: "minecraft:armor.helmet", operation: "add_value" }, 
        "head"
      )
      .withModifierAdded(
        "irons_spellbooks:max_mana", 
        { amount: 25, id: "irons_spellbooks:head_max_mana_modifier", operation: "add_value" },
        "head"
      )
    // Apply them to the item. 
    item.setAttributeModifiersWithTooltip(modifiedAttributeModifiers.modifiers())
  })
rancid wing
#

sending a message here so i can come back thank you !