From 5a8fc75fbcdba8c3988191e1a57ecffcc6ef27d6 Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Wed, 18 May 2022 20:13:46 +0800 Subject: get item enchant level util function --- utils/utils.js | 67 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/utils/utils.js b/utils/utils.js index 48bb569..504b3bf 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,27 +1,27 @@ const NBTTagString = Java.type('net.minecraft.nbt.NBTTagString'); let utils = { - addLore: function(item, prefix, value){ - + addLore: function (item, prefix, value) { + const list = item .getNBT() .getCompoundTag("tag") .getCompoundTag("display") .getTagMap() .get("Lore") - + let done = false // Gets the current lore lines for (let i = 0; i < list.func_74745_c(); i++) { - if (String(list.func_150307_f(i)).startsWith(prefix)){ - list.func_150304_a(i, new NBTTagString(prefix+value)); + if (String(list.func_150307_f(i)).startsWith(prefix)) { + list.func_150304_a(i, new NBTTagString(prefix + value)); done = true } } - if(!done){ - list.func_74742_a( new NBTTagString(prefix+value)) + if (!done) { + list.func_74742_a(new NBTTagString(prefix + value)) } - + item .getNBT() .getCompoundTag("tag") @@ -29,29 +29,32 @@ let utils = { .getRawNBT() .func_74782_a("Lore", list); }, - getSBID: function(item){ + getSBID: function (item) { return item?.getNBT()?.getCompoundTag("tag")?.getCompoundTag("ExtraAttributes")?.getString("id") || null }, - calculateDistance: function(p1, p2) { + getSBEnchant: function (item, enchant) { + return item?.getNBT()?.getCompoundTag("tag")?.getCompoundTag("ExtraAttributes")?.getCompoundTag("enchantments")?.getInteger(enchant) || null + }, + calculateDistance: function (p1, p2) { var a = p2[0] - p1[0]; var b = p2[1] - p1[1]; var c = p2[2] - p1[2]; - - let ret = Math.hypot(a,b,c) - - if(ret<0){ + + let ret = Math.hypot(a, b, c) + + if (ret < 0) { ret *= -1 } return ret; }, - calculateDistanceQuick: function(p1, p2) { + calculateDistanceQuick: function (p1, p2) { var a = p2[0] - p1[0]; var b = p2[1] - p1[1]; var c = p2[2] - p1[2]; - + let ret = a * a + b * b + c * c - - if(ret<0){ + + if (ret < 0) { ret *= -1 } return ret; @@ -65,38 +68,38 @@ let utils = { * @param {*} points * @returns */ - fastestPathThrough:function(startPoint, points){ + fastestPathThrough: function (startPoint, points) { let ret = [] - while(ret.length{ + let positions = order.map((a) => { return points[a] }) let len = 0 - for(let i = 0;i