[SPIGOT-5485] Support for spawn eggs with different spawned mob type Created: 27/Dec/19 Updated: 29/Jul/24 Resolved: 29/Jul/24 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | blablubbabc | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 2 |
Labels: | deserialization, serialization, spawnegg |
Issue Links: |
|
||||||||||||||||
Version: | This server is running CraftBukkit version git-Spigot-05bb8bc-7d677e7 (MC: 1.15.1) (Implementing API version 1.15.1-R0.1-SNAPSHOT) | ||||||||||||||||
Guidelines Read: | Yes |
Description |
Since the update to MC 1.13 Spigot performs a legacy conversion of spawn egg items during ItemStack deserialization. This takes and then removes the stored spawned mob type from the item's nbt data, gets its numerical type id, maps it to a corresponding new spawn egg material via the SPAWN_EGGS map in CraftLegacy and changes the ItemStack's type via the updateMaterial call during ItemStack deserialization / when applying the deserialized ItemMeta to the deserialized ItemStack. There are currently 3 (minor) issues with this:
The usecase of this could be to disguise a spawn egg and surprise the user when the spawn egg is used. Another use case is to create spawn eggs for mobs which currently don't have a corresponding spawn egg in vanilla minecraft, eg. create a vindicator spawn egg that actually spawns an illusioner (for which no own spawn egg item exists currently). From my basic testing so far these spawn eggs seem to work and behave fine in vanilla minecraft. However, once these spawn egg items go through Spigot's item deserialization they run through the legacy conversion which replaces their ItemStack material to the actual corresponding mob type. This either breaks the disguise in the first usecase, and completely destroys the item in the second usecase (since illusioners don't have a corresponding spawn egg material, resulting in the item type being cleared).
I have only very briefly looked into this, after a user of one of my plugins ran into this issue of his custom spawn eggs getting converted to turtle eggs. The 'fix' is to not specify any mob id when creating the spawn egg via minecraft's give command. But the above mentioned use cases for these custom spawn eggs seem valid to me. Would it be possible to support these custom spawn egg items, or is there a fundamental / vanilla minecraft issue with them? Maybe, if this is possible, a solution would be to only run the legacy conversion if the current item material is actually the legacy spawn egg material. And otherwise skip the legacy conversion. And then also don't remove the internal mob id from the item's data. Minecraft then handles the spawning of the explicitly specified mob type just fine as far as I can tell.
I have tested this with the plugin Shopkeepers, which stores items via Bukkit's item serialization. If you want a minimal reproduction plugin, which simply serializes and deserializes a held item, let me know. The minecraft give command for creating such an item could look like this: /give blablubbabc minecraft:pig_spawn_egg{EntityTag:{id:"minecraft:creeper"}}
Bukkit's serialized output looks like this: ==: org.bukkit.inventory.ItemStack v: 2227 type: PIG_SPAWN_EGG meta: ==: ItemMeta meta-type: SPAWN_EGG internal: H4sIAAAAAAAAAONiYOBi4HTNK8ksqQxJTOdgYMpMYRDMzcxLTS5KTCuxSi5KTS1ILWJgAAB18udrKQAAAA== When deserialized this returns a spawn egg of type 'creeper_spawn_egg'. |
Comments |
Comment by blablubbabc [ 29/Jul/24 ] |
Comment by blablubbabc [ 29/Jul/24 ] |
With the removal of the legacy spawn egg conversion during item deserialization (https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/c6b4d5a87fa1293e40ca0f3c56a687d7025839a5) during 1.20.6, this issue seems to be resolved. Briefly tested this with this command: /give blablubbabc minecraft:pig_spawn_egg[minecraft:entity_data=\{id:"minecraft:creeper"}] |
Comment by Proto Type [ 14/May/24 ] |
Why is this still not fixed? One use case I was trying to use in my server is to have a Vex spawn egg which spawns a lightning bolt. Turns into a Turtle spawn egg because this isn't supported yet ;_; |
Comment by blablubbabc [ 28/Dec/19 ] |
The ItemMonsterEgg takes into account the optionally existing "id" field in the "EntityTag". I just tested these spawn eggs again on 1.15.1 and they seem to work fine so far (they spawn the expected internally stored mob type and don't get converted by minecraft across server restarts, chunk loads, etc.). Can't comment on whether or not its supposed to work. |
Comment by md_5 [ 28/Dec/19 ] |
>The usecase of this could be to disguise a spawn egg and surprise the user when the spawn egg is used. Another use case is to create spawn eggs for mobs which currently don't have a corresponding spawn egg in vanilla minecraft, eg. create a vindicator spawn egg that actually spawns an illusioner (for which no own spawn egg item exists currently). Fairly certain this is no longer possible or meant to be possible in vanilla. |