mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
SPIGOT-7731: Spawn eggs cannot have damage
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
95f120b7ff
commit
9db084c279
6 changed files with 4 additions and 84 deletions
|
@ -459,11 +459,6 @@ public final class CraftItemFactory implements ItemFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException {
|
||||
return ((CraftMetaItem) meta).updateMaterial(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getSpawnEgg(EntityType type) {
|
||||
if (type == EntityType.UNKNOWN) {
|
||||
|
|
|
@ -626,12 +626,6 @@ public final class CraftItemStack extends ItemStack {
|
|||
itemMeta = CraftItemFactory.instance().asMetaFor(itemMeta, getType(item));
|
||||
if (itemMeta == null) return true;
|
||||
|
||||
Item oldItem = item.getItem();
|
||||
Item newItem = CraftItemType.bukkitToMinecraft(CraftItemFactory.instance().updateMaterial(itemMeta, CraftItemType.minecraftToBukkit(oldItem)));
|
||||
if (oldItem != newItem) {
|
||||
item.setItem(newItem);
|
||||
}
|
||||
|
||||
if (!((CraftMetaItem) itemMeta).isEmpty()) {
|
||||
CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
||||
|
||||
|
|
|
@ -1691,10 +1691,6 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|||
void serializeInternal(final Map<String, NBTBase> unhandledTags) {
|
||||
}
|
||||
|
||||
Material updateMaterial(Material material) {
|
||||
return material;
|
||||
}
|
||||
|
||||
static void serializeEnchantments(Map<Enchantment, Integer> enchantments, ImmutableMap.Builder<String, Object> builder, ItemMetaKey key) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
return;
|
||||
|
|
|
@ -13,12 +13,9 @@ import net.minecraft.world.item.component.CustomData;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntitySnapshot;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.util.CraftLegacy;
|
||||
import org.bukkit.entity.EntitySnapshot;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||
|
@ -110,19 +107,10 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
@ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT)
|
||||
static final ItemMetaKey ENTITY_ID = new ItemMetaKey("id");
|
||||
|
||||
private EntityType spawnedType;
|
||||
private NBTTagCompound entityTag;
|
||||
|
||||
CraftMetaSpawnEgg(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
|
||||
if (!(meta instanceof CraftMetaSpawnEgg egg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.spawnedType = egg.spawnedType;
|
||||
|
||||
updateMaterial(null); // Trigger type population
|
||||
}
|
||||
|
||||
CraftMetaSpawnEgg(DataComponentPatch tag) {
|
||||
|
@ -135,11 +123,6 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
|
||||
CraftMetaSpawnEgg(Map<String, Object> map) {
|
||||
super(map);
|
||||
|
||||
String entityType = SerializableMeta.getString(map, ENTITY_ID.BUKKIT, true);
|
||||
if (entityType != null) {
|
||||
this.spawnedType = CraftEntityType.stringToBukkit(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -149,31 +132,11 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
if (tag.contains(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
|
||||
if (context instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) context;
|
||||
|
||||
// Duplicated from constructor
|
||||
String entityType = SerializableMeta.getString(map, ENTITY_ID.BUKKIT, true);
|
||||
if (entityType != null) {
|
||||
this.spawnedType = CraftEntityType.stringToBukkit(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.spawnedType != null) {
|
||||
// We have a valid spawn type, just remove the ID now
|
||||
entityTag.remove(ENTITY_ID.NBT);
|
||||
}
|
||||
|
||||
// Tag still has some other data, lets try our luck with a conversion
|
||||
if (!entityTag.isEmpty()) {
|
||||
// SPIGOT-4128: This is hopeless until we start versioning stacks. RIP data.
|
||||
// entityTag = (NBTTagCompound) MinecraftServer.getServer().dataConverterManager.update(DataConverterTypes.ENTITY, new Dynamic(DynamicOpsNBT.a, entityTag), -1, CraftMagicNumbers.DATA_VERSION).getValue();
|
||||
}
|
||||
|
||||
// See if we can read a converted ID tag
|
||||
if (entityTag.contains(ENTITY_ID.NBT)) {
|
||||
this.spawnedType = CraftEntityType.stringToBukkit(entityTag.getString(ENTITY_ID.NBT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,11 +171,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
}
|
||||
|
||||
boolean isSpawnEggEmpty() {
|
||||
return !(hasSpawnedType() || entityTag != null);
|
||||
}
|
||||
|
||||
boolean hasSpawnedType() {
|
||||
return spawnedType != null;
|
||||
return entityTag != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -244,8 +203,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
if (meta instanceof CraftMetaSpawnEgg) {
|
||||
CraftMetaSpawnEgg that = (CraftMetaSpawnEgg) meta;
|
||||
|
||||
return hasSpawnedType() ? that.hasSpawnedType() && this.spawnedType.equals(that.spawnedType) : !that.hasSpawnedType()
|
||||
&& entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
|
||||
return entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -260,9 +218,6 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
final int original;
|
||||
int hash = original = super.applyHash();
|
||||
|
||||
if (hasSpawnedType()) {
|
||||
hash = 73 * hash + spawnedType.hashCode();
|
||||
}
|
||||
if (entityTag != null) {
|
||||
hash = 73 * hash + entityTag.hashCode();
|
||||
}
|
||||
|
@ -281,30 +236,10 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||
public CraftMetaSpawnEgg clone() {
|
||||
CraftMetaSpawnEgg clone = (CraftMetaSpawnEgg) super.clone();
|
||||
|
||||
clone.spawnedType = spawnedType;
|
||||
if (entityTag != null) {
|
||||
clone.entityTag = entityTag.copy();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
final Material updateMaterial(Material material) {
|
||||
if (spawnedType == null) {
|
||||
spawnedType = EntityType.fromId(getDamage());
|
||||
setDamage(0);
|
||||
}
|
||||
|
||||
if (spawnedType != null) {
|
||||
if (entityTag != null) {
|
||||
// Remove ID tag as it is now in the material
|
||||
entityTag.remove("id");
|
||||
}
|
||||
|
||||
return CraftLegacy.fromLegacy(new MaterialData(Material.LEGACY_MONSTER_EGG, (byte) spawnedType.getTypeId()));
|
||||
}
|
||||
|
||||
return super.updateMaterial(material);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ public final class CraftLegacy {
|
|||
new Exception().printStackTrace();
|
||||
}
|
||||
|
||||
SPAWN_EGGS.put((byte) 0, Material.PIG_SPAWN_EGG); // Will be fixed by updateMaterial if possible
|
||||
SPAWN_EGGS.put((byte) 0, Material.PIG_SPAWN_EGG);
|
||||
|
||||
SPAWN_EGGS.put((byte) EntityType.BAT.getTypeId(), Material.BAT_SPAWN_EGG);
|
||||
SPAWN_EGGS.put((byte) EntityType.BLAZE.getTypeId(), Material.BLAZE_SPAWN_EGG);
|
||||
|
|
|
@ -88,7 +88,7 @@ public class MaterialReroutingTest extends AbstractTestingBase {
|
|||
if (methodNode.desc.contains("Lorg/bukkit/Material;") || signature.contains("Lorg/bukkit/Material;")) {
|
||||
// Add method exceptions here
|
||||
switch (methodNode.name) {
|
||||
case "<init>", "updateMaterial", "setItemMeta0" -> {
|
||||
case "<init>", "setItemMeta0" -> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue