Upstream Paper

This commit is contained in:
Sotr
2018-07-28 22:38:20 +08:00
parent 2def9e628a
commit af7444df09
3 changed files with 19 additions and 11 deletions

View File

@@ -54,11 +54,11 @@ public class Chunk {
TileEntity replaced = super.put(key, value); TileEntity replaced = super.put(key, value);
if (replaced != null) { if (replaced != null) {
replaced.setCurrentChunk(null); replaced.setCurrentChunk(null);
tileEntityCounts.decrement(replaced.tileEntityKeyString); tileEntityCounts.decrement(replaced.getMinecraftKeyString());
} }
if (value != null) { if (value != null) {
value.setCurrentChunk(Chunk.this); value.setCurrentChunk(Chunk.this);
tileEntityCounts.increment(value.tileEntityKeyString); tileEntityCounts.increment(value.getMinecraftKeyString());
} }
return replaced; return replaced;
} }
@@ -68,7 +68,7 @@ public class Chunk {
TileEntity removed = super.remove(key); TileEntity removed = super.remove(key);
if (removed != null) { if (removed != null) {
removed.setCurrentChunk(null); removed.setCurrentChunk(null);
tileEntityCounts.decrement(removed.tileEntityKeyString); tileEntityCounts.decrement(removed.getMinecraftKeyString());
} }
return removed; return removed;
} }
@@ -712,7 +712,7 @@ public class Chunk {
this.markDirty(); this.markDirty();
entity.setCurrentChunk(this); entity.setCurrentChunk(this);
entityCounts.increment(entity.entityKeyString); entityCounts.increment(entity.getMinecraftKeyString());
if (entity instanceof EntityItem) { if (entity instanceof EntityItem) {
itemCounts[k]++; itemCounts[k]++;
} else if (entity instanceof IInventory) { } else if (entity instanceof IInventory) {
@@ -761,7 +761,7 @@ public class Chunk {
} }
this.markDirty(); this.markDirty();
entity.setCurrentChunk(null); entity.setCurrentChunk(null);
entityCounts.decrement(entity.entityKeyString); entityCounts.decrement(entity.getMinecraftKeyString());
if (entity instanceof EntityItem) { if (entity instanceof EntityItem) {
itemCounts[i]--; itemCounts[i]--;
} else if (entity instanceof IInventory) { } else if (entity instanceof IInventory) {
@@ -895,13 +895,13 @@ public class Chunk {
List entityslice = aentityslice[j]; // Spigot List entityslice = aentityslice[j]; // Spigot
// Paper start // Paper start
DuplicateUUIDMode mode = world.paperConfig.duplicateUUIDMode; DuplicateUUIDMode mode = world.paperConfig.duplicateUUIDMode;
if (mode == DuplicateUUIDMode.DELETE || mode == DuplicateUUIDMode.REGEN) { if (mode == DuplicateUUIDMode.WARN | mode == DuplicateUUIDMode.DELETE || mode == DuplicateUUIDMode.REGEN) {
Map<UUID, Entity> thisChunk = new HashMap<>(); Map<UUID, Entity> thisChunk = new HashMap<>();
for (Iterator<Entity> iterator = ((List<Entity>) entityslice).iterator(); iterator.hasNext(); ) { for (Iterator<Entity> iterator = ((List<Entity>) entityslice).iterator(); iterator.hasNext(); ) {
Entity entity = iterator.next(); Entity entity = iterator.next();
if (entity.dead) continue; if (entity.dead) continue;
Entity other = ((WorldServer) world).entitiesByUUID.get(entity.uniqueID); Entity other = ((WorldServer) world).entitiesByUUID.get(entity.uniqueID);
if (other == null) { if (other == null || other.dead || world.getEntityUnloadQueue().contains(other)) {
other = thisChunk.get(entity.uniqueID); other = thisChunk.get(entity.uniqueID);
} }
if (other != null && !other.dead) { if (other != null && !other.dead) {
@@ -917,6 +917,9 @@ public class Chunk {
iterator.remove(); iterator.remove();
break; break;
} }
default:
logger.warn("[DUPE-UUID] Duplicate UUID found used by " + other + ", doing nothing to " + entity + ". See https://github.com/PaperMC/Paper/issues/1223 for discussion on what this is about.");
break;
} }
} }
thisChunk.put(entity.uniqueID, entity); thisChunk.put(entity.uniqueID, entity);

View File

@@ -1813,21 +1813,26 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
public Chunk getChunkAtLocation() { public Chunk getChunkAtLocation() {
return getCurrentChunkAt((int)Math.floor(locX) >> 4, (int)Math.floor(locZ) >> 4); return getCurrentChunkAt((int)Math.floor(locX) >> 4, (int)Math.floor(locZ) >> 4);
} }
public final MinecraftKey entityKey = EntityTypes.getKey(this); private String entityKeyString = null;
public final String entityKeyString = entityKey != null ? entityKey.toString() : null; private MinecraftKey entityKey = getMinecraftKey();
@Override @Override
public MinecraftKey getMinecraftKey() { public MinecraftKey getMinecraftKey() {
if (entityKey == null) {
entityKey = EntityTypes.getKey(this);
entityKeyString = entityKey != null ? entityKey.toString() : null;
}
return entityKey; return entityKey;
} }
@Override @Override
public String getMinecraftKeyString() { public String getMinecraftKeyString() {
getMinecraftKey(); // Try to load if it doesn't exists. see: https://github.com/PaperMC/Paper/issues/1280
return entityKeyString; return entityKeyString;
} }
@Nullable @Nullable
public final String getSaveID() { public final String getSaveID() {
return entityKeyString; return getMinecraftKeyString();
// Paper end // Paper end
} }