Calling Registry.ATTRIBUTE.getKey(attribute) when Attribute is a PlayerEx attribute returns null.
briarss opened this issue ยท 12 comments
Hi there. I'm writing a mod that adds RPG-style affixes to loot, and it's fully data-driven. I assume i am running into this issue due to PlayerEx using Data Attributes, but i'm using the safe supplier method that is used in Data Attributes and it's still erroring out.
Alright, thank you. One final final question, albeit the wrong repo x) How can i change the potency of attributes rolled on relics?
Hi there,
This can be done with a datapack - the documentation for this is a bit sparse but this as well as looking at the files in the mod jar for an example explain it well enough.
I see, thank you. Would it be possible to contact you on Discord or somewhere? We are using PlayerEx, RelicEx and the mod i wrote as the core part of a modpack for ~100 streamers, and I'm wanting to look into balance options but don't want to fill up the github issues with "How would i x"
I've sent you a friend request on Discord. I'm back at work starting today so I'll only be able to reply evening.
Hi there,
This is almost certainly because Registry.ATTRIBUTE#getKey
is being called before PlayerEx's attributes are registered.
When the world is created server-side, Data Attributes loads any attributes defined in a datapack and registers them to the game. When a player joins the world, the server sends this information to the client and the attributes are then registered to the client's game too. For singleplayer this happens at the same time but for multiplayer this occurs on the server once at startup and then on the client(s) whenever a player joins the server. Additionally, when a player disconnects from a server, the attributes are unregistered from that client. This is so that different servers/worlds can have different datapack-defined attributes.
Outside of the aforementioned events, the JSON loaded attributes do not exist in the game's memory. In summary, Data Attributes implements lazy-loading attributes and PlayerEx registers its attribute using this method.
If you link me your repo I can maybe have a look and make some recommendations? I don't know exactly how (or when) you're dynamically generating datadriven rpg-style loot; is it pregame? On world load? I'm sure this is fixable.
Thanks.
Ah - please see this issue. I don't really know how to fix this!
Edit: I think it's either the size of the packet Data Attributes sends on connection or the bit of code that checks to see that the client got the packet and is running the right version. I could maybe output a release tomorrow without the latter feature for you to test to see if that fixes it?
Hey, sure. https://github.com/amoooooo/Affixated most of the impl is in the common package, but some stuff is inside fabric too. Forge hasnt been touched much yet, so can safely be ignored.
I actually got it working, mostly, but the AttributeModifiers i apply to it dont show up in the tooltip nor apply, but they do with default Trinket attribute modifiers. Specifically PlayerEx attributes.
Hi,
I took a brief look, and from what I can see you're doing something similar to an addon mod for PlayerEx that adds RPG-style trinket-compatible loot - RelicEx. Some things I'll just point out:
- This part where you get an attribute from a datapack loaded
ResourceLocation
here will sometimes (not always) give you a null attribute when reading data-driven attributes (i.e., from PlayerEx like Constitution). This is because: a) the order of the datapacks loaded from mods is not reliable (so Data Attributes could be loaded before your mod sometimes or vice-versa); b) Data Attributes does not register the attributes to the client when the datapack is loaded, so you will have a mismatch on server/client depending on how your doing things. A solution would be to just keep a register/cache of theResourceLocation
as-is, until such a time when you can be certain of the attribute object being present (see last bullet point on the event provided by Data Attributes for this specific purpose). - RelicEx also uses datapacks to load item attribute modifier data similar to how you're doing it (albeit not as nicely as your json); see here. RelicEx faces the same issue as you are having; so care needed to be taken on how and when I actually reference the attributes - check here and here.
- By using the event provided by Data Attributes, here, RelicEx gets a guarantee that referencing PlayerEx attributes will not result in nulls.
I'm sure you're doing things your own way, so I don't want to step on your toes - but you might find it helpful/insightful to take a look at some of the code in RelicEx.
Not sure about the tooltip though; I think you're storing the modifiers using a custom nbt tag/format on the ItemStack, right? Is there a reason why you're not appending to the default vanilla attribute modifiers list (I think it's nbt list with key 'Attributes')?
Hi, i've gotten something working but come back with another issue. We're running the server with proxies via velocity for some custom stuff, but PlayerEx and DataAttributes will not allow you to connect to a Velocity proxy at all. Is this something that can be fixed?
final question... you can't seem to add PlayerEx attributes via origins as the attribute doesn't exist, is there a workaround or is this something origins would have to fix? i assume it's because of Data Attributes
See this issue. Note that one of the issues that stopped me from contributing to Origins/Apoli seems to have been resolved - regardless, the incompatibility persists until I can fix it.