#Code edits all instances of item

2 messages · Page 1 of 1 (latest)

eager turtle
#

I want this code to only change 1 item

function calculateNewColor(cname, pos) {
  let newcolor = 0;
  for(let k = 0; k < 3; k++){
      newcolor += (Math.pow(256, 2 - k) * (
          cname.nodes[Math.floor(pos / cname.length) % cname.nodes.length][k] +
          Math.floor(
              ((cname.nodes[(Math.floor(pos / cname.length) + 1) % cname.nodes.length][k] -
              cname.nodes[Math.floor(pos / cname.length) % cname.nodes.length][k]) / cname.length)
              * (pos % cname.length)
          )
      ));
  }
  return newcolor;
}

function createColoredName(cname, offset, namearray) {
  let coloredname = [];
  for(let j = 0; j < namearray.length; j++){
      let pos = (j + offset) % (cname.nodes.length * cname.length);
      let newcolor = calculateNewColor(cname, pos);
      coloredname.push(Text.of(namearray[j]).color(newcolor));
  }
  return coloredname;
}

ItemEvents.tooltip(event => {
  let colorfulnames = [
      {
          id: 'moonsweaponry:netherite_greatsword',
          name: "Rainbow Sword Yay",
          nodes: [[255, 255, 0], [0, 255, 255], [255, 0, 255]],
          length: 5,
          time: 1
      },
      {
          id: "moonsweaponry:diamond_greatsword",
          name: "Diamond Greatsword of Light",
          nodes: [[255, 255, 255], [255, 255, 0], [0, 255, 255]],
          length: 5,
          time: 1
      }
      // Add more items here...
  ];

  for(let i = 0; i < colorfulnames.length; i++){
      let cname = colorfulnames[i];
      event.addAdvanced(cname.id, (item, advanced, text) => {
          let offset = Math.floor(Client.player.age / cname.time) % (cname.nodes.length * cname.length);
          let namearray = cname.name.split("");
          let coloredname = createColoredName(cname, offset, namearray);
          text.set(0, coloredname);
      });
  }
});
misty nightBOT
#

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