#how to edit vanilla armor protection values?
27 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
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)
})
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...
Paste version of startup.log, main.js from @rose fossil
Huh, funny. I ran only the code for the hoe and it worked as expected, but then I noticed that our kjs versions are different. I upped my version to 181 and it gave me the same error as you. Idk what's going on there, but the safest bet would be to lower your kubejs version. Mine is 119 for reference
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
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
I think setAttributeModifiers is the method we're looking for?
tried before, but honestly javascript/ java is not my expertise
getting incorrect assignments / parameters
Yeah, I'm pretty new to this as well
this was the error btw:
Cannot convert dev.latvian.mods.rhino.NativeJavaObject@390f166c to net.minecraft.world.item.component.ItemAttributeModifiers$Entry
@Override
@HideFromJS
public <T> ComponentFunctions kjs$override(DataComponentType<T> type, @Nullable T value) {
item.kjs$overrideComponent(type, value);
return this;
}
does not look like they want us to keep using this
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
I am using 119 for 1.21.1 for the record. I'm trying stuff with sinytra connector, and it's been the only recent version that doesn't catapult a lot of fabric mods for me (aka cause a crash) 
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)
Paste version of warden_armor_knockback.js from @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)
})
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:
- 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
- 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)
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)
})}
});
Thank you for the help @plain bear !
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())
})
sending a message here so i can come back thank you !