Upstream Paper

This commit is contained in:
Sotr
2019-03-24 18:17:28 +08:00
parent 6498e68a50
commit 8c772dd85f
7 changed files with 38 additions and 7 deletions

View File

@@ -63,6 +63,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
};
List<Entity> entitySlice = null;
public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason;
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
@@ -1671,6 +1672,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
if (origin != null) {
nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
}
if (spawnReason != null) {
nbttagcompound.setString("Paper.SpawnReason", spawnReason.name());
}
// Save entity's from mob spawner status
if (spawnedViaMobSpawner) {
nbttagcompound.setBoolean("Paper.FromMobSpawner", true);
@@ -1824,6 +1828,26 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
spawnedViaMobSpawner = nbttagcompound.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
if (nbttagcompound.hasKey("Paper.SpawnReason")) {
String spawnReasonName = nbttagcompound.getString("Paper.SpawnReason");
try {
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
} catch (Exception ignored) {
LogManager.getLogger().error("Unknown SpawnReason " + spawnReasonName + " for " + this);
}
}
if (spawnReason == null) {
if (spawnedViaMobSpawner) {
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER;
} else if (this instanceof EntityInsentient && this instanceof IAnimal && !((EntityInsentient) this).isTypeNotPersistent()) {
if (!nbttagcompound.getBoolean("PersistenceRequired")) {
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL;
}
}
}
if (spawnReason == null) {
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
}
// Paper end
} catch (Throwable throwable) {

View File

@@ -3,7 +3,7 @@ package net.minecraft.server;
import java.io.IOException;
public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
private static final int MAX_LENGTH = Short.MAX_VALUE * 8 + 8; // Paper
private IChatBaseComponent a;
public net.md_5.bungee.api.chat.BaseComponent[] components; // Spigot
private ChatMessageType b;
@@ -30,9 +30,9 @@ public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
//packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(components)); // Paper - comment, replaced with below
// Paper start - don't nest if we don't need to so that we can preserve formatting
if (this.components.length == 1) {
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(this.components[0]));
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(this.components[0]), MAX_LENGTH); // Paper - use proper max length
} else {
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(this.components));
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(this.components), MAX_LENGTH); // Paper - use proper max length
}
// Paper end
} else {

View File

@@ -158,7 +158,7 @@ public final class SpawnerCreature {
float f1 = (float) l3 + 0.5F;
EntityHuman entityhuman1 = worldserver.a((double) f, (double) f1, -1.0D);
if (entityhuman1 != null) {
if (entityhuman1 != null && worldserver.isLoadedAndInBounds(blockposition_mutableblockposition)) { // Paper - don't load chunks for mob spawn
double d0 = entityhuman1.d((double) f, (double) k3, (double) f1);
if (d0 > 576.0D && blockposition.distanceSquared((double) f, (double) k3, (double) f1) >= 576.0D) {
@@ -171,7 +171,7 @@ public final class SpawnerCreature {
i4 = biomebase_biomemeta.c + worldserver.random.nextInt(1 + biomebase_biomemeta.d - biomebase_biomemeta.c);
}
if (worldserver.isLoadedAndInBounds(blockposition_mutableblockposition) && worldserver.a(enumcreaturetype, biomebase_biomemeta, (BlockPosition) blockposition_mutableblockposition)) { // Paper - don't load chunks for mob spawn
if (worldserver.a(enumcreaturetype, biomebase_biomemeta, (BlockPosition) blockposition_mutableblockposition)) {
EntityPositionTypes.Surface entitypositiontypes_surface = EntityPositionTypes.a(biomebase_biomemeta.b);
if (entitypositiontypes_surface != null && a(entitypositiontypes_surface, worldserver, blockposition_mutableblockposition, biomebase_biomemeta.b)) {
EntityInsentient entityinsentient;

View File

@@ -1084,6 +1084,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed signature, added SpawnReason
// Paper start
if (entity.spawnReason == null) entity.spawnReason = spawnReason;
if (regionLimited != null) {
return regionLimited.addEntity(entity, spawnReason);
}