#Performance conern with Mod events

66 messages · Page 1 of 1 (latest)

high hemlock
#

I got this code running with some help, and now I got a question. The console.log spamms a LOT of times per second, so that code is executd a lot. Does that mean it has a big performance impact or is there some magic behind this that makes in barely noticable?

ForgeModEvents.onEvent('net.minecraftforge.client.event.RegisterColorHandlersEvent$Item', event => {
    event.register((stack, tintIndex) => {
        if (stack) {
            if(stack.nbt) {
                if(stack.nbt.color) {
                    console.log(tintIndex)
                    return '0x'+stack.nbt.color
                } else {
                    return -1
                }
            } else {
                return -1
            }
        } else {
            return -1
        }
    }, Item.of('kubejs:gem'))
})```
analog heartBOT
#

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

valid atlas
#

How often are we talking about here

high hemlock
#

Like 100 times? I had minecraft open for a few seconds and the editor lagged when opening the startup log

#

But that might be because I have 9 of those items in my hotbar

#

I think its for each item of that type in the inventory, for each layer, every tick

torn anvil
#

remove the console.logs and check the FPS graph while you have some of those kind of items, if not much is changing your code is fine

high hemlock
#

Thats really clever tbh

#

Lemme do that real quick

torn anvil
#

compare with, and without items, keep adding those to your inventory

#

to see if anything changes significantly

high hemlock
#

👍

torn anvil
#

actually is it possible to have F3 screen + inv screen open? 🤔

high hemlock
#

Yes I think so

torn anvil
#

check if same happens with minecraft potions

high hemlock
#

Yes, but not as much

#

I mean, my items have 3 layers being tinted and not just one

#

And I also use CustomModelData

torn anvil
#

how did you save color inside nbt? let me see your code? maybe this string manipulation is heavy

high hemlock
#

Client:

ClientEvents.highPriorityAssets(e => {
  let toRegister = [{id:['kubejs:item/white_blank_chip','kubejs:item/white_shard','kubejs:item/white_screw'],name:'kubejs:models/item/test'},{id:['kubejs:item/white_shard','kubejs:item/white_screw'],name:'kubejs:models/item/test1'},{id:['kubejs:item/white_screw'],name:'kubejs:models/item/test2'}]
  toRegister.forEach(register => {
    let index = 0
    let textures = {}
    register.id.forEach(id => {
      textures['layer'+index] = id
      index += 1
    })
    e.add(register.name,{
      "parent": "item/generated",
      "textures": textures
    })
  })
  })```
#

Startup: js StartupEvents.registry('item', event => { //CustomModelData for model and color[layer] for color on that texture layer(Starting with 0) event.create("gem").displayName('Gem').maxStackSize(1).modelJson( ` { "parent": "item/generated", "textures": { "layer0": "kubejs:item/debug" }, "overrides": [ { "predicate": { "custom_model_data": 1 }, "model": "kubejs:item/test" },{ "predicate": { "custom_model_data": 2 }, "model": "kubejs:item/test1" },{ "predicate": { "custom_model_data": 3 }, "model": "kubejs:item/test2" } ] } ` ) }) ForgeModEvents.onEvent('net.minecraftforge.client.event.RegisterColorHandlersEvent$Item', event => { event.register((stack, tintIndex) => { if (stack) { if(stack.nbt) { if(stack.nbt['color'+tintIndex]) { return '0x'+stack.nbt['color'+tintIndex] } } } return -1 }, Item.of('kubejs:gem')) })

torn anvil
#

still not seeing you writing color to nbt

high hemlock
#

I mean I just give myself an item with that nbt

#

This is just for testing right now

torn anvil
#

can you show command

#

is color an integer? string? what?

high hemlock
#

/give @s kubejs:gem{CustomModelData:1,color0:FF0000,color1:00FF00,color2:0000FF}

torn anvil
#

your code is not good on the nbt, you should have saved that in a var, you are accessing same code twice

#

same var*

#

also you may try to use NBT methods, not rely on Rhino abstraction

high hemlock
#

How do you mean nbt methodes?

torn anvil
#

like stack.nbt.getInt("color"+tintIndex) if your nbt were an int

high hemlock
#

Ok, might look at that

#

Thanks

torn anvil
#

as I said, store that in a var if you need to reuse

high hemlock
#

Yes, I just did that

analog heartBOT
#

Ticket closed!

torn anvil
#

you may convert your nbt colors to int instead of string too

#

string manipulation is bery costly

#

very

high hemlock
#

But aren't they ints?

torn anvil
#

you are using "0x"+something

#

this creates string

high hemlock
#

Ah you mean that

#

Ok, any idea how I could do that diffrently?

torn anvil
#

what do you need to return for real on that event? a color integer? i need to check what is that event about

#

this register color handler

high hemlock
#

I think I have to return an int representation of a color

torn anvil
#

checked here, it is int, so you better don't use string concatenation

#

just return as it is

high hemlock
#

You mean just the 00FF00

#

Nope, that crashes

torn anvil
#

you probably need to write it properly when you do it, like NBT.i(0x00FF00)
if you do manually don't know if it supports 0xFF0000 in chat

#

because you are prob not storing as an int

high hemlock
#

Ah ok, so I'll just do that once I make my real implementation for the color

#

Thanks

torn anvil
#

this is 0xFF0000 is 16711680

#

if you want to create item using comands, convert the hexas

high hemlock
#

No, later I will set the color with kubejs anyways

torn anvil
#

just use the nbt methods like stack.nbt.putInt("color0", 0xFF0000)

high hemlock
#

I normally do stack.nbt.color0 = 0xFF0000

#

Is that wrong?

torn anvil
#

Rhino prob writes that as a Double

high hemlock
#

Ah ok, then Ill use the putInt

#

Thanks