#Color/Formatting new attributes help
5 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
swordtest.js
//Sabers
global.easyAttribute({
'spartanweaponry:iron_saber': {
uuid: ['c1a8d755-8b35-4e79-bcb3-1b5e43c4f7a1'],
attr: ['minecraft:generic.attack_damage'],
base: [1],
val: [2],
slot: 'mainhand'
}
});
globalFunctions.js
global.easyAttribute = function (items) {
let $AttributeModifier = Java.loadClass('net.minecraft.world.entity.ai.attributes.AttributeModifier');
const $MinecraftForge = Java.loadClass('net.minecraftforge.common.MinecraftForge');
const $EventPriority = Java.loadClass('net.minecraftforge.eventbus.api.EventPriority');
const $KubeJS = Java.loadClass('dev.latvian.mods.kubejs.KubeJS');
if ($KubeJS.startupScriptManager.firstLoad) {
$MinecraftForge.EVENT_BUS.addListener($EventPriority.LOW, false, Java.loadClass('net.minecraftforge.event.entity.player.ItemTooltipEvent'), event => global.modifyTooltips(event));
}
//Modify Attribute
ForgeEvents.onEvent('net.minecraftforge.event.ItemAttributeModifierEvent', event => {
let itemId = event.itemStack.id;
Object.entries(items).forEach(([item, stats]) => {
if (itemId === item && event.slotType === stats.slot) {
for (let i = 0; i < stats.attr.length; i++) {
let uuid = UUID.fromString(stats.uuid[i]); // Change the string uuid to an actual one
let modifier = new $AttributeModifier(uuid, stats.attr[i], stats.val[i], "addition");
event.removeAttribute(stats.attr[i]); // Remove default attribute
event.addModifier(stats.attr[i], modifier); // Apply new attribute
}
}
});
});
//---------------------------------------------//
//---------------------------------------------//
//Modify Tooltip
global.modifyTooltips = (event) => {
let itemId = event.itemStack.id;
Object.entries(items).forEach(([item, stats]) => {
if (itemId === item) {
for (let i = 0; i < stats.attr.length; i++) {
let attrKey = stats.attr[i].replace(/.*:/, '');
attrKey = Text.translate(`attribute.name.${attrKey}`).string; // Formats the attribute name
for (let j = 0; j < event.toolTip.size(); j++) {
let text = event.toolTip.get(j).string; // Loops through all tooltip lines
if (text.includes(attrKey)) { // Checks if this line matches the attribute
event.toolTip.set(j, Text.of(` ${stats.base[i] + stats.val[i]} ${attrKey}`).darkGreen().italic(false)); // Replace with colored text
}
}
}
}
});
};
};