New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update for nullable spawner types, editMeta
util
#2514
Update for nullable spawner types, editMeta
util
#2514
Conversation
mechanism.echoError("Mechanism 'LocationTag.spawner_type' is only valid for spawners."); | ||
return; | ||
} | ||
if (mechanism.value == null && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!mechanism.hasValue()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -33,4 +35,10 @@ public void setItemStack(ItemStack item) { | |||
public void setItemMeta(ItemMeta meta) { | |||
object.setItemMeta(meta); | |||
} | |||
|
|||
public <T extends ItemMeta> void editMeta(Class<T> metaType, Consumer<T> editor) { | |||
T meta = metaType.cast(getItemMeta()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to use this over just (T)
? I ask specifically because I generally worry about reflection calls having unexpected performance issues, so it's preferable to avoid if not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to a direct cast
Changes
ItemSpawnerType
to modern property format, and changed it to account for the spawner type being nullable internally on 1.20+ (previously just threw an NPE), including support for setting it to null in the mechanism.LocationTag.spawner_type
for the type being nullable, including updating the mech to modern registration.This also includes a workaround (this has since been fixed.makeBlockStateRaw
) for setting it to null in the mechanism due to a Spigot bug - I have already opened an issue @ Spigot for thisItemInstrument
:allows custom instruments
from the meta, as Spigot uses hard-coded ones :/ponder
when unset (which is effectively random because it's based on the internal order of stuff - it grabs the first entry from the horn instruments tag/the instrument registry).getMusicInstrument
in favor of just getting it directly.setMusicInstrument
in favor of the newItemProperty#editMeta
.setPropertyValue
's param name to match the usual one (param
->value
).ElementTag#asString
call insetPropertyValue
's error message, and slightly cleaned it up.describes
into ainstanceof
check instead of a material check.Additions
ItemProperty#editMeta(Class metaType, Consumer editor)
- a util method to avoid boilerplateget/setItemMeta
calls & casts.