432 Commits

Author SHA1 Message Date
md_5
a7b8b0270a
Update to Minecraft 1.18-pre5 2021-11-22 09:00:00 +11:00
md_5
eb19161294
SPIGOT-6783: Items do not appear in custom anvil inventories 2021-11-04 18:17:58 +11:00
Doc
cef1fda37b
#947: Add missing spawn eggs for SpawnEggMeta 2021-10-30 18:34:04 +11:00
blablubbabc
dc764e7a2f
#877: Improve and simplify CraftBlockState 2021-09-29 18:56:16 +10:00
DerFrZocker
a0a37f416c
SPIGOT-6630: Replacing an enchantment on an item creates a conflict error 2021-08-24 18:10:30 +02:00
blablubbabc
7c8bbcbee7
SPIGOT-6716: Preserve the order of stored enchantments of enchanted books.
In some cases, differences in this order can result in item stack
comparisons to fails.
2021-08-20 19:41:17 +10:00
md_5
82f0955b3b
SPIGOT-6666: NPE when deserializing bundle 2021-07-23 16:38:51 +10:00
md_5
fb556bfa14
Update to Minecraft 1.17.1 2021-07-07 00:00:00 +10:00
Doc
07ed44a415
SPIGOT-6527: Add AxolotlBucketMeta 2021-07-04 09:32:25 +10:00
Doc
7aa02e3a31
SPIGOT-6615 Fix Glow Item Frame to use EntityTagMeta 2021-07-03 09:33:04 +10:00
md_5
470050ad1e
SPIGOT-6587: Update documentation/error of drop chance API 2021-06-20 12:15:28 +10:00
md_5
ded19075b1
SPIGOT-6570: Missing InventoryType: COMPOSTER 2021-06-17 08:29:15 +10:00
md_5
d7ef1e91fa
SPIGOT-6558: Attempt to improve SkullMeta 2021-06-16 10:28:42 +10:00
md_5
622cf61119
SPIGOT-6555: Cannot access shield BlockStateMeta 2021-06-15 13:06:23 +10:00
md_5
d9c69b44da
SPIGOT-6529: Fix BundleMeta#setItems 2021-06-13 08:48:13 +10:00
md_5
74575d4888
SPIGOT-6506: Fix crash with custom inventories 2021-06-11 19:20:20 +10:00
md_5
e2f5ea34e9
Update to Minecraft 1.17 2021-06-11 15:00:00 +10:00
blablubbabc
a0149bf165
SPIGOT-6480: Players cannot take books from lecterns that were opened by plugins 2021-05-29 18:52:52 +10:00
md_5
a8d7c94a5b
SPIGOT-6434: Smithing Table and Anvil inventories .getType() returns CRAFTING 2021-04-25 08:34:44 +10:00
Julian van den Berkmortel
115244c744
SPIGOT-6078: Add SmithItemEvent and expand SmithingInventory API 2021-04-18 18:03:23 +10:00
md_5
90d6905b15
Repackage NMS 2021-03-16 09:00:00 +11:00
md_5
0c24068ad6
Organise imports 2021-03-09 08:47:33 +11:00
blablubbabc
c631fe5579
#797: The copy constructor of CraftMetaTropicalFishBucket did not copy its entityTag field 2021-02-06 09:23:50 +11:00
Gerrygames
ed4d4cd651
SPIGOT-6342: TROPICAL_FISH_BUCKET isSimilar returns true when it should not 2021-02-06 09:23:50 +11:00
md_5
aeb95e3a30
Add more checkstyle checks 2021-01-31 10:08:41 +11:00
blablubbabc
560b65c4f8
#707, SPIGOT-5063, SPIGOT-5304, SPIGOT-5656, SPIGOT-3206, SPIGOT-5350, SPIGOT-5980, SPIGOT-4672: Persist the exact internal text representation where possible.
Issues resolved by this:
* SPIGOT-5063: Internal text representation of ItemStacks changes during ItemStack serialization. This issue was initially primarily concerned with the conversion between color text attributes to legacy color codes.
* SPIGOT-5304: Internal text representation of ItemStacks changes when opening the inventory (in creative mode). In particularly, this issue is also concerned with the conversion between plain text representations to non-plain ones.
* SPIGOT-5656: Internal text representation of ItemStacks changes during ItemStack serialization. This issue is particularly concerned with reordering of text attributes in the text's Json representation.
* SPIGOT-3206: Internal text representation of book pages changes during ItemStack serialization.
* SPIGOT-5350: Any non-plain text features are stripped from books during ItemStack serialization.
* SPIGOT-5980: Written books are marked as 'resolved' during ItemStack serialization and on various inventory interactions, even though they aren't, and thereby breaking any non-resolved page contents.
* SPIGOT-4672: Since item display names are serialized in their internal Json representation, any translatable components get properly persisted as well now.

---------

Minecraft uses text components to represent text. Internally Minecraft stores these components as Json formatted Strings and dynamically parses the text components from this Json representation whenever required.

In some cases Minecraft will create the text components and then convert them to Json itself for the internal storage. In other cases the Json representation is specified by users (eg. in Minecraft give commands, loot tables, mob equipment specified via Minecraft's summon commands, etc.).
There are many different ways in which the same text components can be represented in Json. When Minecraft compares objects which store this textual information, it takes the exact Json representation into account to determine whether the objects are considered equal. For example, ItemStacks will not match (and therefore not stack) if there is a difference in this internal Json representation for at least one if the item's text attributes (such as display name, lore, book pages, etc.). And when specifying nbt data in command selectors (eg. to only match entities/players which hold an item with specific name), the selector compares the raw Json representation as well.

As long as the Json representation is valid and can be parsed, Minecraft will not modify or normalize it.
However, under various circumstances Spigot converts this text information from the internal Json representation to text components (and in some cases even to plain text with legacy color codes) and then later tries to convert the text from these representations back to text components in the Json representation. Because this backwards conversion is in many cases not able to reproduce the original Json representation, the internal data of some affected Minecraft objects (ItemStacks, TileEntities, Entities, etc.) will in some cases get modified.

One especially notable situation in which this issue can come up is Bukkit's configuration serialization of ItemStacks: When a plugin serializes and later deserializes ItemStacks with display name, localized name, lore, or book pages of signed books, Spigot would convert these textual ItemStack attributes to plain text with legacy color codes and later try to convert those back to chat components in the Json representation. If the reconstructed Json representation does not match the original representation, the deserialized ItemStacks would no longer match nor stack with any original ItemStacks.

This case is particularly common if the original ItemStacks are created by users via some vanilla Minecraft mechanism (eg. Minecraft's give command, loot tables, mob equipment specified via Minecraft's summon command, etc.) and the used internal text representation for the created ItemStacks does not match the text representation produced by Spigot. This is also quite likely to be case, because the internal text representation produced by Spigot can sometimes be slightly verbose and, until recently, contained legacy color codes which cannot be used in Minecraft commands in-game.
However, this issue is not limited to items created by users, but affects items created by Minecraft itself as well.

Other cases in which Spigot itself (without any plugins involved) will convert between these text representations include dragging items around inside the inventory or opening the inventory while in creative mode. In these cases Spigot creates Bukkit representations of the affected items for use in Bukkit events and then, after the events have been handled, converts these Bukkit representations back to Minecraft items. See for example SPIGOT-5656 and SPIGOT-5304.

The idea of these changes is to avoid this back and forth conversion between the internal Json representation and the text component or plain text representations in various situations in which it is not actually required:
* CraftMetaItem stores the raw original Json representation for the display name, localized name, lore and pages of signed books now. As long as no plugin modifies these text attributes via the API, they can be reapplied in their original form to an ItemStack.
* The configuration serialization will serialize the original Json representation for these text attributes now so that it can also be restored during deserialization.
* However, in order to still be able to deserialize previously serialized items, and in order to allow users to specify text in the more simple plain representation in configuration files, we also still accept plain text during deserialization. Our approach is to check if the serialized text contains legacy color codes, in which case we convert it to chat components using our own converter and then to Json. Otherwise we try to parse it via Minecraft's Json parser. If the parsing fails due to the text not being valid Json, we interpret the text as plain text and convert it via our own converter as well.
* Various duplicated code has been removed from CraftMetaBookSigned and instead the base CraftMetaBook class allows sub classes to override the relevant aspects of how pages are parsed, serialized and deserialized.
* The BlockStates for command blocks and signs preemptively retrieved the custom name and sign line components, converted them to plain text and later converted them back to text components when applying the BlockState. We now only perform this conversion if a plugin has explicitly modified these texts.

Other changes:
* Minor: We also retrieve, convert and update a few other BlockState attributes directly from the underlying snapshot and only when requested by plugins now.
* SPIGOT-5980: Written books did not properly persist their 'resolved' attribute, resulting in unresolved book pages not getting resolved.
* There are methods to get and set the resolved value for books. However, these are not yet exposed in Bukkit.
* Minor fix: CraftMetaBook#isBookEmpty did not check some of the book attributes. This is probably a minor issue, but for consistency reasons there are checks for the missing attribute(s) now.

----
Covered cases
---
* By remembering the raw original String data, we can persist the exact text representation (eg. the ordering of elements within the Json text object (SPIGOT-5656), used style of escaping quotes (single quotes, escaped double quotes, etc.), use of plain texts (SPIGOT-5304), used boolean style, modern text component features such as translatable texts (SPIGOT-4672), etc.). All of these differences would otherwise cause the ItemStack to no longer be considered equal to its original.
* An empty String in the serialized config data results in no display name rather than an empty display name, like before. An item with explicitly empty display name (`{display: {Name: '""'}}`) is saved as `'""'` and can also be loaded from that representation again.
* Any plain texts, with or without color codes, which don't parse as Json (eg. `display-name: 'Bla'`) are still getting run through Spigot's text to components converter, like before.
* We can now also persist empty but explicitly present lore (`{display:{Lore:[]}}`). Previously this would get removed when the ItemMeta gets reapplied to the item. And ItemMeta#equals would return true for items with and without this empty lore data, even though Minecraft considers them to be different. For plugins using the API there should be no change: #hasLore still checks whether the lore is both present and not empty, and #getLore returns an empty list instead of null in this case (however, it previously already returned an empty list in this case). And setting the lore to an empty list via #setLore will still result in an item with no lore.
* Similarly, we can also persist explicitly specified but empty lists of book pages now.

----
Cases that are not covered (i.e. which may lead to changes in items), but were already not covered previously:
----
* NBT data for text that is not actually of type String.
* Empty or unexpected entries within the display compound.
* Variations in the NBT data representation in item features other than the above mentioned ones.
* Texts containing color codes. During deserialization these texts get interpreted as plain text and converted to a text component representation. This will break the serialization of any ItemStacks which actually use a text component representation with embedded color codes for some reason. Usually the likelihood for encountering such items in practice would probably be small. However, in the past (pre MC 1.16) Spigot would actually produce such items during ItemStack deserialization or when plugins created ItemStack via the Bukkit API. However, Spigot has changed the text representation it produces in MC 1.16, so any previously created and still existing items with this text representation are already problematic anyways now. See SPIGOT-5964. A fix for this linked issue (eg. the automatic conversion of these items) would probably resolve this deficit here as well.
* Spigot's String to text components converter produces quite verbose components since 1.16. See SPIGOT-5964 as well. However, this applies regardless of the changes of this PR.
* Book ItemStacks with more pages than 100 pages or oversized pages are truncated (like before) and may therefore change.
hange.
2021-01-01 08:53:14 +11:00
Parker Hawke
878b43758d
#772: Add API to set equipment silently 2020-12-21 18:30:48 +11:00
SydMontague
1dabfdc82f
#754: Fix pre-1.16 serialized SkullMeta being broken on 1.16+, losing textures
The underlying issue is a change by Mojang how UUID are stored in NBT.
This patch will have CraftBukkit convert the format during
deserialization.
2020-09-25 17:09:59 +10:00
Martoph
da9bb3ea92
#753: RecipeIterator#hasNext will now accurately represent if the current iterator has a next item. 2020-09-18 18:44:19 +10:00
Phoenix616
13fc33f732
#744: Add ability to get location from smithing inventory 2020-09-03 08:18:30 +10:00
Brokkonaut
6008e6660a
SPIGOT-6025: Do not NPE when target world of a compass no longer exists 2020-08-31 17:12:48 +10:00
Parker Hawke
e850144b07
#726: Add Inventory#isEmpty() 2020-08-16 11:21:08 +10:00
blablubbabc
69fddc725b
#705: Improve implementation of furnace related block states
CraftFurnace is the base class for all concrete types of furnaces (this
mimics Minecraft's underlying type hierarchy). It is marked as abstract
now to avoid accidental instantiation.

Also, the various furnace sub types were missing type parameters.
2020-07-09 08:49:55 +10:00
md_5
4309566390
SPIGOT-5943: Calling get BlockStateMeta#getBlockState causes NPE with shield with banner 2020-07-05 11:35:20 +10:00
md_5
068618eb5b
SPIGOT-5927: Some items NBT data disappears 2020-07-03 09:14:34 +10:00
md_5
3b9cf0f803
Improve code formatting 2020-07-01 14:17:48 +10:00
md_5
b8b65eb744
SPIGOT-5908: CompassMeta for new lodestone compass data 2020-07-01 10:48:37 +10:00
md_5
a13b8cfc71
SPIGOT-5907: Item Frame NBT data disappears 2020-07-01 10:00:24 +10:00
Martoph
cf01fd9d7d
#696: Respect the NotNull annotation of getChargedProjectiles in CraftMetaCrossbow 2020-06-29 09:09:52 +10:00
md_5
983305bb4a
SPIGOT-5856: Soul Campfire BlockState cannot be cast to Campfire 2020-06-27 17:18:34 +10:00
md_5
174a2ee539
SPIGOT-5829: RGB hex colours not supported in several places 2020-06-26 09:40:21 +10:00
md_5
3f0c333870
SPIGOT-5809: block.getState() wall signs too 2020-06-25 20:08:32 +10:00
md_5
b5db08bea5
SPIGOT-5809: block.getState() instanceof Sign for crimson_sign missed 2020-06-25 19:42:38 +10:00
md_5
9a3bd97f60
SPIGOT-5809: block.getState() instanceof Sign for warped_sign missed 2020-06-25 19:30:42 +10:00
md_5
76d2add0bb
SPIGOT-5802: Add SmithingRecipe API 2020-06-25 12:41:55 +10:00
md_5
7ea3c040bc
Update to Minecraft 1.16.1 2020-06-25 10:00:00 +10:00
blablubbabc
c9d7c16b5f SPIGOT-2623: Add EntityEquipment methods to get/set ItemStacks by slot. 2020-06-13 20:56:32 +10:00
Aikar
1b2830a3b3 SPIGOT-4441: Fix serializing Components to and from Legacy
While cfeef75cd97 might of semi helped being able to save black text
lore, it actually took a fundamental problem with the legacy serialization
code and expanded it to break even more aspects of the server when dealing
with Component to Legacy conversion.

This is causing data loss in Spigot with cases such as setting an item name
to white gets stripped resulting in it being italic.

Additionally, things such as book pages have been returning black formatting
codes for the end of the line even when the user doesn't have colors in the book.

The root issue is that the "Default Color" system is fundamentally wrong.

Components do not and should not care about what element of the game they
are being used by, and that's what the default color system did.

It results in components that if obtained from 1 source such as a Book
where the default / rendered color is black, is then copied to another
source such as an Entity name, the black is carried forward and shown
in the Entity name, when in reality it should have been white.

This commit reverts cfeef75cd97 and fixes the underlying serialization
issues when it comes to Legacy to and From conversions.

There was quite a number of issues with this code overall, in how
it handles inserting color codes, new line parsing and such.

Books was using mojangs own "getLegacyString" which doesn't match behavior.
We also do not want to use Mojangs method as there is no guarantee they don't
remove that in future.
Plus, everything about books uses the CB implementation anyways, and it should
be consistent (this was mandatory to avoid serialization format changes on old vs new)

These changes as is results in Item Stacks already serialized will not
change contents when they go to component and back, so this won't impact
any existing data.

Newly created books though for example will change behavior in that they
will no longer insert black color codes in the serialized data and will
only represent intentional color changes by the creator of the book.
This will result in cleaner data on them, and books are the only thing
I'm aware of that has a behavioral shift due to the likelyhood of the
default color system kicking in on other parts of the string.

A unit test has been added to verify integrity of serialization to
ensure that any legacy string that is converted into Components will
always re-encode back in the same way when going back to Legacy.
2020-06-01 19:19:42 +10:00
md_5
cfeef75cd9 SPIGOT-5749: ItemMeta serializing to YAML not saving black colour code 2020-05-26 19:39:03 +10:00
Parker Hawke
933e9094bf #664: Add methods to get/set ItemStacks in EquipmentSlots 2020-05-05 19:10:03 +10:00