2019-05-27 14:14:14 +08:00
|
|
|
From 1f5d2fdb86b5f80245f453099885feb063f1af22 Mon Sep 17 00:00:00 2001
|
2018-07-04 15:55:24 +08: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 09:53:17 +08:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2019-05-26 09:56:30 +08:00
|
|
|
index b5f318c00d..ce190d88d6 100644
|
2018-07-15 09:53:17 +08:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2019-04-05 12:35:59 +08:00
|
|
|
@@ -175,7 +175,7 @@ public class PaperCommand extends Command {
|
2018-07-15 09:53:17 +08:00
|
|
|
|
2019-05-09 22:23:52 +08:00
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
2018-07-15 09:53:17 +08:00
|
|
|
entities.forEach(e -> {
|
|
|
|
- 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()));
|
|
|
|
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ());
|
2018-07-04 15:55:24 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-26 09:56:30 +08:00
|
|
|
index ed4253a490..84ba4798f7 100644
|
2018-07-04 15:55:24 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-06 10:58:04 +08:00
|
|
|
@@ -49,7 +49,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
2018-07-04 15:55:24 +08:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2018-07-15 09:53:17 +08:00
|
|
|
-public abstract class Entity implements INamableTileEntity, ICommandListener {
|
|
|
|
+public abstract class Entity implements INamableTileEntity, ICommandListener, KeyedObject { // Paper
|
2018-07-04 15:55:24 +08:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
private static final int CURRENT_LEVEL = 2;
|
2019-05-26 09:56:30 +08:00
|
|
|
@@ -1682,12 +1682,31 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
2018-07-04 15:55:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
2018-07-27 12:44:53 +08:00
|
|
|
+ private MinecraftKey entityKey;
|
|
|
|
+ private String entityKeyString;
|
2018-07-04 15:55:24 +08:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MinecraftKey getMinecraftKey() {
|
2018-07-27 12:44:53 +08:00
|
|
|
+ if (entityKey == null) {
|
|
|
|
+ this.entityKey = EntityTypes.getName(this.getEntityType());
|
|
|
|
+ this.entityKeyString = this.entityKey != null ? this.entityKey.toString() : null;
|
|
|
|
+ }
|
2018-07-04 15:55:24 +08:00
|
|
|
+ return entityKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getMinecraftKeyString() {
|
2018-07-27 12:44:53 +08:00
|
|
|
+ getMinecraftKey(); // Try to load if it doesn't exists. see: https://github.com/PaperMC/Paper/issues/1280
|
2018-07-04 15:55:24 +08:00
|
|
|
+ return entityKeyString;
|
|
|
|
+ }
|
|
|
|
@Nullable
|
|
|
|
public final String getSaveID() {
|
2019-04-24 09:00:24 +08:00
|
|
|
EntityTypes<?> entitytypes = this.getEntityType();
|
|
|
|
MinecraftKey minecraftkey = EntityTypes.getName(entitytypes);
|
|
|
|
|
2018-07-15 09:53:17 +08:00
|
|
|
- return entitytypes.a() && minecraftkey != null ? minecraftkey.toString() : null;
|
2019-04-24 09:00:24 +08:00
|
|
|
+ return entitytypes != null && entitytypes.isPersistable() ? getMinecraftKeyString() : null;
|
2018-07-04 15:55:24 +08:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void a(NBTTagCompound nbttagcompound);
|
2018-07-15 09:53:17 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
|
2019-05-26 09:56:30 +08:00
|
|
|
index 56a2d7df5e..98eb0d24cc 100644
|
2018-07-15 09:53:17 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTypes.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
|
2019-04-24 09:00:24 +08:00
|
|
|
@@ -238,6 +238,7 @@ public class EntityTypes<T extends Entity> {
|
2018-07-15 09:53:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public boolean isPersistable() { return a(); } // Paper - OBFHELPER
|
|
|
|
public boolean a() {
|
2019-04-24 09:00:24 +08:00
|
|
|
return this.bb;
|
2018-07-15 09:53:17 +08:00
|
|
|
}
|
2018-07-04 15:55:24 +08: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
|
2019-05-26 09:56:30 +08:00
|
|
|
index 0000000000..743142d030
|
2018-07-04 15:55:24 +08:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
|
2018-07-27 12:44:53 +08:00
|
|
|
@@ -0,0 +1,9 @@
|
2018-07-04 15:55:24 +08:00
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
|
|
|
+public interface KeyedObject {
|
|
|
|
+ MinecraftKey getMinecraftKey();
|
|
|
|
+ default String getMinecraftKeyString() {
|
2018-07-27 12:44:53 +08:00
|
|
|
+ MinecraftKey key = getMinecraftKey();
|
|
|
|
+ return key != null ? key.toString() : null;
|
2018-07-04 15:55:24 +08:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
2019-05-26 09:56:30 +08:00
|
|
|
index 8d868d84ca..b511fe263f 100644
|
2018-07-04 15:55:24 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
2019-05-14 10:20:58 +08:00
|
|
|
@@ -11,7 +11,7 @@ import org.bukkit.inventory.InventoryHolder;
|
2019-05-06 10:58:04 +08:00
|
|
|
// CraftBukkit end
|
2018-07-04 15:55:24 +08:00
|
|
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
|
|
|
|
|
|
|
-public abstract class TileEntity {
|
2018-07-27 12:44:53 +08:00
|
|
|
+public abstract class TileEntity implements KeyedObject { // Paper
|
2018-07-04 15:55:24 +08:00
|
|
|
|
|
|
|
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
|
2019-05-06 10:58:04 +08:00
|
|
|
// CraftBukkit start - data containers
|
2019-05-14 10:20:58 +08:00
|
|
|
@@ -19,7 +19,7 @@ public abstract class TileEntity {
|
2019-05-06 10:58:04 +08:00
|
|
|
public final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
|
|
|
|
// CraftBukkit end
|
2019-04-25 14:53:51 +08:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2019-04-24 09:00:24 +08:00
|
|
|
- private final TileEntityTypes<?> b;
|
|
|
|
+ private final TileEntityTypes<?> b; public TileEntityTypes getTileEntityType() { return b; } // Paper - OBFHELPER
|
|
|
|
@Nullable
|
2018-07-15 09:53:17 +08:00
|
|
|
protected World world;
|
|
|
|
protected BlockPosition position;
|
2019-05-14 10:20:58 +08:00
|
|
|
@@ -33,6 +33,26 @@ public abstract class TileEntity {
|
2019-04-24 09:00:24 +08:00
|
|
|
this.b = tileentitytypes;
|
2018-07-04 15:55:24 +08:00
|
|
|
}
|
|
|
|
|
2018-07-27 12:44:53 +08:00
|
|
|
+ // Paper start
|
|
|
|
+ private String tileEntityKeyString = null;
|
|
|
|
+ private MinecraftKey tileEntityKey = null;
|
2018-07-04 15:55:24 +08:00
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MinecraftKey getMinecraftKey() {
|
2018-07-27 12:44:53 +08:00
|
|
|
+ if (tileEntityKey == null) {
|
|
|
|
+ tileEntityKey = TileEntityTypes.a(this.getTileEntityType());
|
|
|
|
+ tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
|
|
|
|
+ }
|
2018-07-04 15:55:24 +08:00
|
|
|
+ return tileEntityKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getMinecraftKeyString() {
|
2018-07-27 12:44:53 +08:00
|
|
|
+ getMinecraftKey(); // Try to load if it doesn't exists.
|
2018-07-04 15:55:24 +08:00
|
|
|
+ return tileEntityKeyString;
|
|
|
|
+ }
|
2018-07-15 09:53:17 +08:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Nullable
|
|
|
|
public World getWorld() {
|
|
|
|
return this.world;
|
2018-07-04 15:55:24 +08:00
|
|
|
--
|
2019-04-05 12:35:59 +08:00
|
|
|
2.21.0
|
2018-07-04 15:55:24 +08:00
|
|
|
|