mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-25 09:34:44 +01:00
SPIGOT-2894: Preserve unreadable spawn egg data in memory
By: md_5 <git@md-5.net>
This commit is contained in:
parent
00609fd3df
commit
597dc19283
1 changed files with 16 additions and 8 deletions
|
@ -18,6 +18,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
static final ItemMetaKey ENTITY_ID = new ItemMetaKey("id");
|
static final ItemMetaKey ENTITY_ID = new ItemMetaKey("id");
|
||||||
|
|
||||||
private EntityType spawnedType;
|
private EntityType spawnedType;
|
||||||
|
private NBTTagCompound entityTag;
|
||||||
|
|
||||||
CraftMetaSpawnEgg(CraftMetaItem meta) {
|
CraftMetaSpawnEgg(CraftMetaItem meta) {
|
||||||
super(meta);
|
super(meta);
|
||||||
|
@ -34,7 +35,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
super(tag);
|
super(tag);
|
||||||
|
|
||||||
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||||
NBTTagCompound entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||||
|
|
||||||
if (entityTag.hasKey(ENTITY_ID.NBT)) {
|
if (entityTag.hasKey(ENTITY_ID.NBT)) {
|
||||||
this.spawnedType = EntityType.fromName(new MinecraftKey(entityTag.getString(ENTITY_ID.NBT)).a()); // PAIL: rename
|
this.spawnedType = EntityType.fromName(new MinecraftKey(entityTag.getString(ENTITY_ID.NBT)).a()); // PAIL: rename
|
||||||
|
@ -53,12 +54,15 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
|
|
||||||
if (hasSpawnedType()) {
|
if (entityTag == null) {
|
||||||
NBTTagCompound entityTag = new NBTTagCompound();
|
entityTag = new NBTTagCompound();
|
||||||
entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString());
|
|
||||||
|
|
||||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasSpawnedType()) {
|
||||||
|
entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,7 +81,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSpawnEggEmpty() {
|
boolean isSpawnEggEmpty() {
|
||||||
return !hasSpawnedType();
|
return !(hasSpawnedType() || entityTag != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasSpawnedType() {
|
boolean hasSpawnedType() {
|
||||||
|
@ -104,7 +108,8 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
if (meta instanceof CraftMetaSpawnEgg) {
|
if (meta instanceof CraftMetaSpawnEgg) {
|
||||||
CraftMetaSpawnEgg that = (CraftMetaSpawnEgg) meta;
|
CraftMetaSpawnEgg that = (CraftMetaSpawnEgg) meta;
|
||||||
|
|
||||||
return hasSpawnedType() ? that.hasSpawnedType() && this.spawnedType.equals(that.spawnedType) : !that.hasSpawnedType();
|
return hasSpawnedType() ? that.hasSpawnedType() && this.spawnedType.equals(that.spawnedType) : !that.hasSpawnedType()
|
||||||
|
&& entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +127,9 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||||
if (hasSpawnedType()) {
|
if (hasSpawnedType()) {
|
||||||
hash = 73 * hash + spawnedType.hashCode();
|
hash = 73 * hash + spawnedType.hashCode();
|
||||||
}
|
}
|
||||||
|
if (entityTag != null) {
|
||||||
|
hash = 73 * hash + entityTag.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
return original != hash ? CraftMetaSpawnEgg.class.hashCode() ^ hash : hash;
|
return original != hash ? CraftMetaSpawnEgg.class.hashCode() ^ hash : hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue