#Adding onto attribute values

107 messages · Page 1 of 1 (latest)

dry sleet
#

Right now I'm trying to make a script that when you click a block it increases your block break speed attribute, but right now it only adds 1 block break speed and doesn't add anymore so it's stuck at 1 block break speed
https://paste.denizenscript.com/View/136738

devout fjordBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

dry sleet
#

I'm honestly confused because the "Operation: ADD_NUMBER" thing should add 1 to the base number no?

dry sleet
#

Please help 🙏

#

Huh, weird I wonder why the bot isn't changing the thread title

plain stirrupBOT
# lethal spire !debug
Info: debug

If you need help with a script issue, one of the most powerful tools Denizen has to offer is full debug output. This is displaying in your console whenever scripts are running until you turn debug off. To share a debug log quickly and easily with helpers, simply run the command /denizen debug -r in-game to begin recording, then run through the part of the script you need help with, then run the command /denizen submit. This will give you a link to a paste of the debug log, which you can then copy/paste back to us!

dry sleet
lethal spire
#

But it's not working

#

So there is a bug either in the script or Denizen

dry sleet
lethal spire
#

And the debug would help identify where that is

dry sleet
#

I'm still confused about what the "operation: add_number" thing does

lethal spire
#

!l attribute modifiers

plain stirrupBOT
# lethal spire !l attribute modifiers

In minecraft, the "attributes" system defined certain core numerical values on entities, such as max health or attack damage.
The value of an "attribute" is determined by its "base value" modified mathematically by each of its "attribute modififers".
"Attribute modifiers" can be added either directly to the entity, or onto items - when on an item, an entity can equip it into the correct slot to automatically apply the modifier.

These can be read via such tags as !tag EntityTag.attribute_modifiers, !tag ItemTag.attribute_modifiers,
!tag EntityTag.has_attribute, !tag EntityTag.attribute_value, !tag EntityTag.attribute_base_value, !tag EntityTag.attribute_default_value, ...

These can be modified by such mechanisms as <@link mechanism EntityTag.attri...

Group

Properties

dry sleet
# plain stirrup

Yeah I'm using itemtag.add_attribute_modifiers but it still just sets the value to the value I'm giving it

#

Lemme type the definemap thingy

#
  • definemap attributes:
    block_break_speed:
    key: blacksmith:add_bbs
    operation: ADD_NUMBER
    amount: 1
    slot: hand
dry sleet
#

But it only sets the attribute to 1 and doesn't add 1 to the value

lethal spire
#

Right... and a debug would display an error message and why it didn't do what it should

dry sleet
#

Not on the PC

lethal spire
#

It's a command typed in-game

dry sleet
#

So I can't do it in game

lethal spire
#

Ah ok

hardy flint
dry sleet
#

I also tried getting the current value of the attribute but I didn't find any way how

hardy flint
#

!m attribute_modifiers

plain stirrupBOT
# hardy flint !m attribute_modifiers
Cannot Specify Searched Mechanism

Multiple possible mechanisms: ItemTag.attribute_modifiers, EntityTag.attribute_modifiers, ItemTag.add_attribute_modifiers, EntityTag.add_attribute_modifiers, ItemTag.remove_attribute_modifiers, EntityTag.remove_attribute_modifiers.

hardy flint
#

!m ItemTag.attribute_modifiers

plain stirrupBOT
# hardy flint !m ItemTag.attribute_modifiers

(Property) Sets the attribute modifiers of an item, with key as the attribute name and value as a list of modifiers,
where each modifier is a MapTag containing keys 'name', 'amount', 'slot', 'operation', and 'id'.
For use as a mechanism, this is a SET operation, meaning pre-existing modifiers are removed.
For format details, refer to !language attribute modifiers.

Group

Properties

Object

ItemTag

Input

MapTag

Tags

<ItemTag.attribute_modifiers> (Property) Returns the attribute modifiers of an item, with key as t...

dry sleet
hardy flint
#

It's an identifier for the modifier, iirc it makes sure that attribute values stack correctly or something

hardy flint
#

Becomes very apparent when working with custom attributes on armor

dry sleet
#

So how do I like make it so I can add to the attribute

#

Or get the attribute amount

hardy flint
dry sleet
#

I've tried <player.item_in_hand.attribute_modifiers>

dry sleet
#

BUT not the amount

hardy flint
#

It's a bit confusing, but it's returned as a MapTag of a ListTag of a MapTag containing the modifier stuff

dry sleet
#

Is there any function where to get a specific part of an attribute)

#

I've tried <player.item_in_hand.attribute_modifiers.get[block_break_speed]>

dry sleet
dry sleet
hardy flint
#

Hold on, I'm booting up the game

dry sleet
#

It's called "amount" btw

dry sleet
hardy flint
dry sleet
#

Just need the value of "amount"

hardy flint
#

Ok so, since it's a list of modifiers you'll have to grab the right list. If you plan on having other sources of block_break_speed you'll need to get the right modifier based on its key being "blacksmith:add_bbs", but if you don't then you can just do .get[1].get[amount]

#

actually, .first.get[amount] should work too

dry sleet
#

Sweet

dry sleet
hardy flint
#

it's a list, so you're just grabbing the first element

#

since even if it has one modifier, it's still stored as a list

#

(that element being the modifier info like the key name, value, slot, etc which is all stored in a map)

dry sleet
#

Alrighty, I'll try this out later and tell ya what happened

compact snowBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@dry sleet

dry sleet
#

.

#

Ae forgor about this

dry sleet
#

Well this is interesting

#

Oh great

#

This isn't goid

#

The .first.get[amount] did get me the value I want

#

But add_attribute_modifiers didn't change at all

#

But if I changed it to attribute_modifiers it added it fine

#

But it removed the other attributes

#

E

#

Yeah it doesn't change if it already is the attribute there

dry sleet
#

Now the problem is that add_attribute_modifier doesn't have the function of changing the amount

#

E

#

I've got an idea

#

What if I just remove it block break speed

#

And add it again

#

Problem is I don't know how to remove attributes with remove_attribute_modifiers

#

Gahdamn this is giving me a headache

dry sleet
#

E

#

Are there really no functions to just add to an Attributes value

#

Pls help🙏

upbeat acorn
#

ok so

#

mc changed attributes in 1.21

#

and you're trying to add a modifier with the same key

#

which is.. not allowed? i guess

#

with that being said if you go with different ids all the modifiers will show individually

#

eg

- +1 Block Break Speed
- +1 Block Break Sp...
- ..```
#

i suggest checking if the item already has a modifier with your key, saving that value, removing the modifier if it exists and re-setting it with the new value & same key

#

eg

- if player isnt holding anything:
  - narrate hold something
  - stop

- if previous modifier exists:
  - define current_value your_attribute_value
  - remove current attribute from held item
- define current_value:++ ##adds onto existing value/also acts as fallback
- adjust held item again```
#

i dont love spoon feeding but the syntax is kinda ugly so:

  • to get the value: <player.item_in_hand.attribute_modifiers.get[block_break_speed].first.get[amount]||0> ##||0 is a fallback (ie if no value is returned from the tag it returns 0)
  • to remove your previous modifier: - inventory adjust slot:hand remove_attribute_modifiers:blacksmith:add_bbs
dry sleet
#

ah yup that did it

#

Thanks. With that I should be able to finish my script

upbeat acorn
compact snowBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@dry sleet

dry sleet
#

Alright

dry sleet
#

seemed like everything alright

#

time to resolve th is