Subtle Effects

Subtle Effects

1M Downloads

[Feature request] Item particles compatibility with custom KubeJS injected rarities

moninformateur opened this issue ยท 2 comments

commented

Current behavior: When using custom rarities injected with a KubeJS script, item particles will display as black.

Requested behavior: Color of the item particles uses the item's custom rarity (displayed in its name).

Example KubeJS script that will inject rarity to an object (startup_script/custom_rarities.js) :

// This function creates a rarity. Parameters are the name of the rarity and its colorCode
function createRarity (/** @type {string} */ name, /** @type {number} */ colorCode) {
  let color = $UtilsJS.makeFunctionProxy("startup", $UnaryOperator, (style) => {
    return withColorMethod.invoke(style, Color.of(colorCode).createTextColorJS())
  })
  return $Rarity["create(java.lang.String,java.util.function.UnaryOperator)"](name, color)
}

// Create a custom rarity
createRarity("CUSTOM_RARE", 0x007FF0)

// Which items will be applied the "CUSTOM_RARE" rarity.
const rareItems = [
  'minecraft:oak_log'
]

// Assign custom rarity to items in the rareItems array.
  rareItems.forEach(item => {
    event.modify(`${item}`, (item) => {
      item.rarity = "CUSTOM_RARE"
    })
  })

Results :

image
image

commented

I think this might be more of a bug, but I will try to fix it.

commented

After looking in to this for a while I have discovered that this is in fact a bug. And a Forge / Neo only issue since fabric doesn't provide a custom constructor for Rarity.

For future bug reporting please provide a fully working KubeJS examples and please specifically the version and loader you used. And that your js only works for a specific loader.
While I have worked with KubeJS before it was not fun hunting down how exactly to load java class with it. Or the fact that you did not include withColorMethod which is crucial for making the game boot. Please next time link the source where you got the original code.
In case some one needs the source for this here is a link: https://discord.com/channels/303440391124942858/1237440577809944576