Moving this from #1067869136606220288 since I was told it would be better suited here
I'm trying to patch durability for my custom items, but I need unbreaking to actually work. I've tried several different formats and setups but I cannot figure out how to make it recognize it.
Currently on 1.13.0 scripting version, as I am unsure how high I can push the version before one of my other scripts breaks.
import { system, world } from "@minecraft/server";
import * as mc from "@minecraft/server";
import { EquipmentSlot, GameMode, Player } from "@minecraft/server";
/** @type {import("@minecraft/server").ItemCustomComponent} */
/*
const ItemUnbreakableComponent = {
onBeforeDurabilityDamage(event) {
event.durabilityDamage = 0;
},
};
system.beforeEvents.startup.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("wiki:unbreakable", ItemUnbreakableComponent);
});
*/
const percentageCheck = Math.random();
const DurabilityPatchComponent = {
onBeforeDurabilityDamage(event) {
//const player = e.source;
//const item = e.itemStack;
let item = entity?.getComponent("equippable")?.getEquipment("Mainhand")
const unbreakingLevel = item.getComponent(mc.ItemComponentTypes?.Enchantable)?.getEnchantment("unbreaking")?.level || 0
if ((1/(unbreakingLevel+1))>=percentageCheck) {
event.durabilityDamage = 1;
} else { return; }
},
};
world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("htc:durability_patch", DurabilityPatchComponent);
});
