Skip to content
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

Added TooltipLines operator #1450

Merged
merged 4 commits into from
Dec 31, 2024

Conversation

pippinsmith
Copy link
Contributor

Implements #1449

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2024

CLA assistant check
All committers have signed the CLA.

.function(input -> {
ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
itemStack.getRawValue().getTooltipLines(Minecraft.getInstance().player, TooltipFlag.Default.NORMAL).stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minecraft is a client-side-only class, so this will unfortunately crash when used on servers.
But I believe the first param of getTooltipLines is Nullable, so we can just pass null here.

@pippinsmith
Copy link
Contributor Author

pippinsmith commented Dec 30, 2024 via email

@rubensworks
Copy link
Member

but might
create scenarios where testing in a terminal query would produce different
results, though that might not be important.

Indeed, there may be cases where it will be different.
Terminals will run the tooltip query client-side, while ID operators run server-side without a player context.
In theory, ID networks could also run based on a specific player, but this would require some extensive internal changes.

@pippinsmith
Copy link
Contributor Author

pippinsmith commented Dec 30, 2024 via email

* Get the tooltip lines of an itemstack.
*/
public static final IOperator OBJECT_ITEMSTACK_TOOLTIP_LINES = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
.output(ValueTypes.LIST).symbol("tooltip_lines").operatorName("tooltiplines").interactName("tooltipLines")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if tooltip instead of tooltip_lines would not be sufficient. (no strong opinion) (same would apply to the other names)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, I was basing it on the ItemStack method name, but makes sense for it to be short right now, since there's no version that returns it as a single object (maybe at some point after #1402 ?)

@pippinsmith
Copy link
Contributor Author

Currently having some discussion about this and my original intended use case on the discord, the option of adding an extra Entity.ItemTooltip(Item) operator has been coined for dealing with the player context, won't be finalizing this PR until all discussion is resolved but will continue testing things.

@rubensworks
Copy link
Member

Both the entity-based and entity-less variants could be valuable.

@pippinsmith
Copy link
Contributor Author

I didn't add tests yet for the entity variant, I noticed that many of the more complex entity operators are missing tests and might have used that as a basis for not trying yet (it works in game, I promise)

feel free to nitpick about naming, I'm working in jetbrains so it's just a refactor button away

@rubensworks rubensworks merged commit 02f4af4 into CyclopsMC:master-1.19-lts Dec 31, 2024
2 checks passed
@rubensworks
Copy link
Member

Thanks @pippinsmith!

@pippinsmith
Copy link
Contributor Author

You're welcome, gonna throw the 1.20 build in the modpack I'm playing when I get the chance.
Not sure how that import stayed there, spotless for sure complained the first time when I moved to null, I guess building for a client run skips spotless 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants