2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-07-04 09:55:24 +02:00
|
|
|
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
|
|
|
|
|
2018-07-15 03:53:17 +02:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2020-08-02 07:39:36 +02:00
|
|
|
index b8868b86338ce0e89bc74eccccf714b910d7a4fe..9cb2f3b31921870ddba044840e99eb04babe26bb 100644
|
2018-07-15 03:53:17 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2019-08-15 04:47:38 +02:00
|
|
|
@@ -178,7 +178,7 @@ public class PaperCommand extends Command {
|
2020-03-18 13:38:24 +01:00
|
|
|
|
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
|
|
|
entities.forEach(e -> {
|
2018-07-15 03:53:17 +02:00
|
|
|
- MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch
|
|
|
|
+ MinecraftKey key = e.getMinecraftKey();
|
|
|
|
|
|
|
|
MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
|
2020-08-02 07:39:36 +02:00
|
|
|
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.chunkX, e.chunkZ);
|
2018-07-04 09:55:24 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2020-09-19 13:29:53 +02:00
|
|
|
index cf9b2c6675e6d875aea2eb66a3d91e86712a1b4d..8cd7c8d5d1a20239ffb3b064f8bd0b7a45cfc63f 100644
|
2018-07-04 09:55:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -51,7 +51,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
2018-07-04 09:55:24 +02:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2018-07-15 03:53:17 +02:00
|
|
|
-public abstract class Entity implements INamableTileEntity, ICommandListener {
|
|
|
|
+public abstract class Entity implements INamableTileEntity, ICommandListener, KeyedObject { // Paper
|
2018-07-04 09:55:24 +02:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
private static final int CURRENT_LEVEL = 2;
|
2020-09-19 13:29:53 +02:00
|
|
|
@@ -1677,12 +1677,31 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
2018-07-04 09:55:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
2018-07-27 06:44:53 +02:00
|
|
|
+ private MinecraftKey entityKey;
|
|
|
|
+ private String entityKeyString;
|
2018-07-04 09:55:24 +02:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MinecraftKey getMinecraftKey() {
|
2018-07-27 06:44:53 +02:00
|
|
|
+ if (entityKey == null) {
|
|
|
|
+ this.entityKey = EntityTypes.getName(this.getEntityType());
|
|
|
|
+ this.entityKeyString = this.entityKey != null ? this.entityKey.toString() : null;
|
|
|
|
+ }
|
2018-07-04 09:55:24 +02:00
|
|
|
+ return entityKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getMinecraftKeyString() {
|
2018-07-27 06:44:53 +02:00
|
|
|
+ getMinecraftKey(); // Try to load if it doesn't exists. see: https://github.com/PaperMC/Paper/issues/1280
|
2018-07-04 09:55:24 +02:00
|
|
|
+ return entityKeyString;
|
|
|
|
+ }
|
|
|
|
@Nullable
|
|
|
|
public final String getSaveID() {
|
2019-04-24 03:00:24 +02:00
|
|
|
EntityTypes<?> entitytypes = this.getEntityType();
|
|
|
|
MinecraftKey minecraftkey = EntityTypes.getName(entitytypes);
|
|
|
|
|
2018-07-15 03:53:17 +02:00
|
|
|
- return entitytypes.a() && minecraftkey != null ? minecraftkey.toString() : null;
|
2019-04-24 03:00:24 +02:00
|
|
|
+ return entitytypes != null && entitytypes.isPersistable() ? getMinecraftKeyString() : null;
|
2018-07-04 09:55:24 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2020-06-25 11:27:25 +02:00
|
|
|
protected abstract void loadData(NBTTagCompound nbttagcompound);
|
2018-07-15 03:53:17 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index e08ccba8134846ef11928183d118a6cce53b6d89..ffb8685e7c457483bcf4b2ed1065fec0fbaa69e2 100644
|
2018-07-15 03:53:17 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTypes.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -253,6 +253,7 @@ public class EntityTypes<T extends Entity> {
|
2018-07-15 03:53:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public boolean isPersistable() { return a(); } // Paper - OBFHELPER
|
|
|
|
public boolean a() {
|
2020-08-25 04:22:08 +02:00
|
|
|
return this.bi;
|
2018-07-15 03:53:17 +02:00
|
|
|
}
|
2018-07-04 09:55:24 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/KeyedObject.java b/src/main/java/net/minecraft/server/KeyedObject.java
|
|
|
|
new file mode 100644
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..743142d0303fa25fe48a2abb07040d1228d04402
|
2018-07-04 09:55:24 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
|
2018-07-27 06:44:53 +02:00
|
|
|
@@ -0,0 +1,9 @@
|
2018-07-04 09:55:24 +02:00
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
|
|
|
+public interface KeyedObject {
|
|
|
|
+ MinecraftKey getMinecraftKey();
|
|
|
|
+ default String getMinecraftKeyString() {
|
2018-07-27 06:44:53 +02:00
|
|
|
+ MinecraftKey key = getMinecraftKey();
|
|
|
|
+ return key != null ? key.toString() : null;
|
2018-07-04 09:55:24 +02:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index 6f6f58672d882f36296bc4f65d075261fc6da912..cfbca7cfde3160e888e14c5bb3bc48267f1cb599 100644
|
2018-07-04 09:55:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -11,7 +11,7 @@ import org.bukkit.inventory.InventoryHolder;
|
2019-05-06 04:58:04 +02:00
|
|
|
// CraftBukkit end
|
2018-07-04 09:55:24 +02:00
|
|
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
|
|
|
|
|
|
|
-public abstract class TileEntity {
|
2018-07-27 06:44:53 +02:00
|
|
|
+public abstract class TileEntity implements KeyedObject { // Paper
|
2018-07-04 09:55:24 +02:00
|
|
|
|
|
|
|
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
|
2019-05-06 04:58:04 +02:00
|
|
|
// CraftBukkit start - data containers
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -19,7 +19,7 @@ public abstract class TileEntity {
|
2019-07-05 04:13:38 +02:00
|
|
|
public CraftPersistentDataContainer persistentDataContainer;
|
2019-05-06 04:58:04 +02:00
|
|
|
// CraftBukkit end
|
2019-04-25 08:53:51 +02:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2019-12-11 01:56:03 +01:00
|
|
|
- private final TileEntityTypes<?> tileType;
|
|
|
|
+ private final TileEntityTypes<?> tileType; public TileEntityTypes getTileEntityType() { return tileType; } // Paper - OBFHELPER
|
2019-04-24 03:00:24 +02:00
|
|
|
@Nullable
|
2018-07-15 03:53:17 +02:00
|
|
|
protected World world;
|
|
|
|
protected BlockPosition position;
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -33,6 +33,26 @@ public abstract class TileEntity {
|
2019-12-11 01:56:03 +01:00
|
|
|
this.tileType = tileentitytypes;
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 06:44:53 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ private String tileEntityKeyString = null;
|
|
|
|
+ private MinecraftKey tileEntityKey = null;
|
2018-07-04 09:55:24 +02:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MinecraftKey getMinecraftKey() {
|
2018-07-27 06:44:53 +02:00
|
|
|
+ if (tileEntityKey == null) {
|
|
|
|
+ tileEntityKey = TileEntityTypes.a(this.getTileEntityType());
|
|
|
|
+ tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
|
|
|
|
+ }
|
2018-07-04 09:55:24 +02:00
|
|
|
+ return tileEntityKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getMinecraftKeyString() {
|
2018-07-27 06:44:53 +02:00
|
|
|
+ getMinecraftKey(); // Try to load if it doesn't exists.
|
2018-07-04 09:55:24 +02:00
|
|
|
+ return tileEntityKeyString;
|
|
|
|
+ }
|
2018-07-15 03:53:17 +02:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Nullable
|
|
|
|
public World getWorld() {
|
|
|
|
return this.world;
|