-
-
Notifications
You must be signed in to change notification settings - Fork 820
Some fixes for potion items #5555
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
Open
BUGTeas
wants to merge
12
commits into
GeyserMC:master
Choose a base branch
from
BUGTeas:fix-potion-component
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb98765
Add some code comments, remove the incorrect prefix correctly in poti…
BUGTeas 989eb71
Fix tipped arrow always using name "Tipped Arrow" and not affected by…
BUGTeas d038c66
Fix the wrong Bedrock ID of tipped arrows in the tooltip of shulker box
BUGTeas c002361
Is necessary to check the type of Item to improve performance, like g…
BUGTeas 02666f6
Revert "Is necessary to check the type of Item to improve performance…
BUGTeas abf57ca
Able to display custom potion effects in all items; Optimize potion n…
BUGTeas f804eb1
Ensure potion displays the same name both its own tooltip and shulker…
BUGTeas 19f202a
Add `minecraft:potion_duration_scale` component support (new feature …
BUGTeas 1f53fdf
Merge branch 'master' of https://github.com/GeyserMC/Geyser into fix-…
BUGTeas 22e8f32
Merge branch 'master' of github.com:GeyserMC/Geyser into fix-potion-c…
BUGTeas 31259a2
Improve access to potion names
BUGTeas e313a7a
Improve a little of code
BUGTeas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |||||
| import org.geysermc.geyser.item.components.Rarity; | ||||||
| import org.geysermc.geyser.item.type.Item; | ||||||
| import org.geysermc.geyser.item.type.PotionItem; | ||||||
| import org.geysermc.geyser.item.type.TippedArrowItem; | ||||||
| import org.geysermc.geyser.level.block.type.Block; | ||||||
| import org.geysermc.geyser.registry.BlockRegistries; | ||||||
| import org.geysermc.geyser.registry.Registries; | ||||||
|
|
@@ -201,7 +202,9 @@ public static ItemData translateToBedrock(GeyserSession session, @NonNull Geyser | |||||
| PotionContents potionContents = components.get(DataComponentTypes.POTION_CONTENTS); | ||||||
| // Make custom effect information visible when shown in tooltip | ||||||
| if (potionContents != null && tooltip.showInTooltip(DataComponentTypes.POTION_CONTENTS)) { | ||||||
| customName += getPotionEffectInfo(potionContents, session.locale()); // TODO should this be done with lore instead? | ||||||
| // Add to the name (use '\n' to wrap lines) instead of the lore | ||||||
| // to make it show in HUD like the effect information of vanilla Bedrock potion | ||||||
| customName += getPotionEffectInfo(potionContents, components.getOrDefault(DataComponentTypes.POTION_DURATION_SCALE, 1f), session.locale()); | ||||||
| } | ||||||
|
|
||||||
| nbtBuilder.setCustomName(customName); | ||||||
|
|
@@ -372,22 +375,23 @@ private static String attributeToLore(GeyserSession session, int attribute, Item | |||||
| Effect.INFESTED | ||||||
| ); | ||||||
|
|
||||||
| public static String getPotionEffectInfo(PotionContents contents, String language) { | ||||||
| public static String getPotionEffectInfo(PotionContents contents, float durationScale, String language) { | ||||||
| StringBuilder finalText = new StringBuilder(); | ||||||
| List<MobEffectInstance> effectInstanceList = contents.getCustomEffects(); | ||||||
| for (MobEffectInstance effectInstance : effectInstanceList) { | ||||||
| Effect effect = effectInstance.getEffect(); | ||||||
| MobEffectDetails details = effectInstance.getDetails(); | ||||||
| int amplifier = details.getAmplifier(); | ||||||
| int durations = details.getDuration(); | ||||||
| TranslatableComponent appendTranslatable = Component.translatable("effect.minecraft." + effect.toString().toLowerCase(Locale.ROOT)); | ||||||
| int duration = details.getDuration(); | ||||||
| TranslatableComponent appendTranslatable = Component.translatable("effect.minecraft." + effect.name().toLowerCase(Locale.ROOT)); | ||||||
| if (amplifier != 0) { | ||||||
| appendTranslatable = Component.translatable("potion.withAmplifier", | ||||||
| appendTranslatable, | ||||||
| Component.translatable("potion.potency." + amplifier)); | ||||||
| } | ||||||
| if (durations > 20) { | ||||||
| int seconds = durations / 20; | ||||||
| if (duration > 20) { | ||||||
| int scaledDuration = (int) (duration * durationScale); | ||||||
| int seconds = scaledDuration / 20; | ||||||
| int secondsFormat = seconds % 60; | ||||||
| int minutes = seconds / 60; | ||||||
| int minutesFormat = minutes % 60; | ||||||
|
|
@@ -399,13 +403,14 @@ public static String getPotionEffectInfo(PotionContents contents, String languag | |||||
| appendTranslatable = Component.translatable("potion.withDuration", | ||||||
| appendTranslatable, | ||||||
| Component.text(text)); | ||||||
| } else if (durations == -1) { | ||||||
| } else if (duration == -1) { | ||||||
| appendTranslatable = Component.translatable("potion.withDuration", | ||||||
| appendTranslatable, | ||||||
| Component.translatable("effect.duration.infinite")); | ||||||
| } | ||||||
| Component component = Component.text() | ||||||
| .resetStyle() | ||||||
| // Use blue to distinguish the gray vanilla Bedrock effect | ||||||
| .color((negativeEffectList.contains(effect)) ? NamedTextColor.RED : NamedTextColor.BLUE) | ||||||
| .append(appendTranslatable) | ||||||
| .build(); | ||||||
|
|
@@ -415,21 +420,34 @@ public static String getPotionEffectInfo(PotionContents contents, String languag | |||||
| return finalText.toString(); | ||||||
| } | ||||||
|
|
||||||
| public static String getPotionName(PotionContents contents, ItemMapping mapping, String language) { | ||||||
| public static String getPotionName(PotionContents contents, ItemMapping mapping, boolean includeDefault, String language) { | ||||||
| String customPotionName = contents.getCustomName(); | ||||||
| Potion potion = Potion.getByJavaId(contents.getPotionId()); | ||||||
|
|
||||||
| if (customPotionName != null) { | ||||||
| // "custom_name" tag in "potion_contents" component | ||||||
| return MessageTranslator.convertMessage( | ||||||
| Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + customPotionName), | ||||||
| language); | ||||||
| return MinecraftLocale.getLocaleString(mapping.getJavaItem().translationKey() + ".effect." + customPotionName, language); | ||||||
| } | ||||||
| if (!contents.getCustomEffects().isEmpty()) { | ||||||
|
|
||||||
| if (includeDefault) { | ||||||
| // Make a name when has custom effects | ||||||
| String potionName = potion == null ? "empty" : potion.toString().toLowerCase(Locale.ROOT); | ||||||
| return MessageTranslator.convertMessage(Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + potionName), language); | ||||||
| // because the custom effect information is display from the second line of the name. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // if name is not set, the custom effect information will not be displayed. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| String potionName; | ||||||
| Potion potion = Potion.getByJavaId(contents.getPotionId()); | ||||||
| if (potion != null) { | ||||||
| potionName = potion.name().toLowerCase(Locale.ROOT); | ||||||
| // Remove the incorrect prefix | ||||||
| // for example, potion "long_leaping" should use "leaping" in translatable name | ||||||
| if (potionName.startsWith("strong_")) { | ||||||
| potionName = potionName.substring(7); | ||||||
| } else if (potionName.startsWith("long_")) { | ||||||
| potionName = potionName.substring(5); | ||||||
| } | ||||||
| } else { | ||||||
| potionName = "empty"; | ||||||
| } | ||||||
| return MinecraftLocale.getLocaleString(mapping.getJavaItem().translationKey() + ".effect." + potionName, language); | ||||||
| } | ||||||
|
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -565,17 +583,22 @@ public static String getCustomName(GeyserSession session, DataComponents compone | |||||
| } | ||||||
|
|
||||||
| if (!customNameOnly) { | ||||||
| if (mapping.getJavaItem() instanceof PotionItem) { | ||||||
| PotionContents potionContents = components.get(DataComponentTypes.POTION_CONTENTS); | ||||||
| if (potionContents != null) { | ||||||
| String potionName = getPotionName(potionContents, mapping, session.locale()); // TODO also test this | ||||||
| boolean forceName = false; | ||||||
| PotionContents potionContents = components.get(DataComponentTypes.POTION_CONTENTS); | ||||||
| if (potionContents != null) { | ||||||
| // hold the custom effect information (reason for this is mentioned in getPotionName method) | ||||||
| forceName = TooltipOptions.fromComponents(components).showInTooltip(DataComponentTypes.POTION_CONTENTS) | ||||||
| && !potionContents.getCustomEffects().isEmpty(); | ||||||
| // Get name in "potion_contents" component for vanilla potion items | ||||||
| if (mapping.getJavaItem() instanceof PotionItem || mapping.getJavaItem() instanceof TippedArrowItem) { | ||||||
| String potionName = getPotionName(potionContents, mapping, forceName, session.locale()); | ||||||
| if (potionName != null) { | ||||||
| return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (includeAll) { | ||||||
| if (includeAll || forceName) { | ||||||
| // Fix book title display in tooltips of shulker box | ||||||
| WrittenBookContent bookContent = components.get(DataComponentTypes.WRITTEN_BOOK_CONTENT); | ||||||
| if (bookContent != null) { | ||||||
|
|
@@ -589,6 +612,11 @@ public static String getCustomName(GeyserSession session, DataComponents compone | |||||
| // behavior as of 1.21 | ||||||
| return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MessageTranslator.convertMessage(customName, session.locale()); | ||||||
| } | ||||||
|
|
||||||
| if (forceName) { | ||||||
| String translationKey = mapping.getJavaItem().translationKey(); | ||||||
| return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To my knowledge, this item still doesn't exist - at least not the base tipped arrow. Can we account for that?