mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 12:41:50 +01:00
18c3716c49
This enables us a fast reference to the entities current chunk instead of having to look it up by hashmap lookups. We also store counts by type to further enable other performance optimizations in later patches.
101 lines
3.6 KiB
Diff
101 lines
3.6 KiB
Diff
From 471ff10805ee8ef1b93d19bd05a91b9f372417c9 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 4 Jul 2018 01:40:13 -0400
|
|
Subject: [PATCH] Add MinecraftKey Information to Objects
|
|
|
|
Stores the reference to the objects respective MinecraftKey
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index ed39b122e..3a8902bf1 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -41,7 +41,7 @@ import org.bukkit.event.entity.EntityPortalEvent;
|
|
import org.bukkit.plugin.PluginManager;
|
|
// CraftBukkit end
|
|
|
|
-public abstract class Entity implements ICommandListener {
|
|
+public abstract class Entity implements ICommandListener, KeyedObject { // Paper
|
|
|
|
// CraftBukkit start
|
|
private static final int CURRENT_LEVEL = 2;
|
|
@@ -1702,11 +1702,23 @@ public abstract class Entity implements ICommandListener {
|
|
return true;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public final MinecraftKey entityKey = EntityTypes.getKey(this);
|
|
+ public final String entityKeyString = entityKey != null ? entityKey.toString() : null;
|
|
+
|
|
+ @Override
|
|
+ public MinecraftKey getMinecraftKey() {
|
|
+ return entityKey;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getMinecraftKeyString() {
|
|
+ return entityKeyString;
|
|
+ }
|
|
@Nullable
|
|
public final String getSaveID() {
|
|
- MinecraftKey minecraftkey = EntityTypes.a(this);
|
|
-
|
|
- return minecraftkey == null ? null : minecraftkey.toString();
|
|
+ return entityKeyString;
|
|
+ // Paper end
|
|
}
|
|
|
|
protected abstract void a(NBTTagCompound nbttagcompound);
|
|
diff --git a/src/main/java/net/minecraft/server/KeyedObject.java b/src/main/java/net/minecraft/server/KeyedObject.java
|
|
new file mode 100644
|
|
index 000000000..61c2b993c
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
|
|
@@ -0,0 +1,8 @@
|
|
+package net.minecraft.server;
|
|
+
|
|
+public interface KeyedObject {
|
|
+ MinecraftKey getMinecraftKey();
|
|
+ default String getMinecraftKeyString() {
|
|
+ return getMinecraftKey().toString();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
|
index 5a5a588e7..672ba3134 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
|
@@ -7,7 +7,7 @@ import org.apache.logging.log4j.Logger;
|
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
|
import org.bukkit.inventory.InventoryHolder; // CraftBukkit
|
|
|
|
-public abstract class TileEntity {
|
|
+public abstract class TileEntity implements KeyedObject {
|
|
|
|
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
|
|
private static final Logger a = LogManager.getLogger();
|
|
@@ -27,8 +27,21 @@ public abstract class TileEntity {
|
|
TileEntity.f.a(new MinecraftKey(s), oclass);
|
|
}
|
|
|
|
- @Nullable
|
|
- public static MinecraftKey a(Class<? extends TileEntity> oclass) {
|
|
+ // Paper start
|
|
+ public final MinecraftKey tileEntityKey = getKey(this.getClass());
|
|
+ public final String tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
|
|
+
|
|
+ @Override
|
|
+ public MinecraftKey getMinecraftKey() {
|
|
+ return tileEntityKey;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getMinecraftKeyString() {
|
|
+ return tileEntityKeyString;
|
|
+ }
|
|
+ @Nullable public static MinecraftKey getKey(Class<? extends TileEntity> oclass) { return a(oclass); } // Paper - OBFHELPER
|
|
+ @Nullable public static MinecraftKey a(Class<? extends TileEntity> oclass) {
|
|
return (MinecraftKey) TileEntity.f.b(oclass);
|
|
}
|
|
|
|
--
|
|
2.18.0
|
|
|