geforkt von Mirrors/Paper
145 Zeilen
6.3 KiB
Diff
145 Zeilen
6.3 KiB
Diff
|
From 0000000000000000000000000000000000000000 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/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||
|
index 68cd4134cb6a00c1768100462f8e9e94f3fa6279..6943524c2dd8b12691b8ac5b08daee823ce50c3d 100644
|
||
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||
|
@@ -208,7 +208,7 @@ public class PaperCommand extends Command {
|
||
|
|
||
|
Collection<Entity> entities = world.entitiesById.values();
|
||
|
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.chunkX, e.chunkZ);
|
||
|
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 0000000000000000000000000000000000000000..500477f0d98a277145c2b0dbb4d1496e2a588542
|
||
|
--- /dev/null
|
||
|
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
|
||
|
@@ -0,0 +1,11 @@
|
||
|
+package net.minecraft.server;
|
||
|
+
|
||
|
+import net.minecraft.resources.MinecraftKey;
|
||
|
+
|
||
|
+public interface KeyedObject {
|
||
|
+ MinecraftKey getMinecraftKey();
|
||
|
+ default String getMinecraftKeyString() {
|
||
|
+ MinecraftKey key = getMinecraftKey();
|
||
|
+ return key != null ? key.toString() : null;
|
||
|
+ }
|
||
|
+}
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
index 3c8767d5fab575e61ca179b517f0bff1a38405ce..ec553e7d7595ef3652bfa3325a07483bb3c32245 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
@@ -136,7 +136,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||
|
import org.bukkit.plugin.PluginManager;
|
||
|
// CraftBukkit end
|
||
|
|
||
|
-public abstract class Entity implements INamableTileEntity, ICommandListener {
|
||
|
+public abstract class Entity implements INamableTileEntity, ICommandListener, net.minecraft.server.KeyedObject { // Paper
|
||
|
|
||
|
// CraftBukkit start
|
||
|
private static final int CURRENT_LEVEL = 2;
|
||
|
@@ -1762,12 +1762,31 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
+ // Paper start
|
||
|
+ private MinecraftKey entityKey;
|
||
|
+ private String entityKeyString;
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public MinecraftKey getMinecraftKey() {
|
||
|
+ if (entityKey == null) {
|
||
|
+ this.entityKey = EntityTypes.getName(this.getEntityType());
|
||
|
+ this.entityKeyString = this.entityKey != null ? this.entityKey.toString() : null;
|
||
|
+ }
|
||
|
+ return entityKey;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public String getMinecraftKeyString() {
|
||
|
+ getMinecraftKey(); // Try to load if it doesn't exists. see: https://github.com/PaperMC/Paper/issues/1280
|
||
|
+ return entityKeyString;
|
||
|
+ }
|
||
|
@Nullable
|
||
|
public final String getSaveID() {
|
||
|
EntityTypes<?> entitytypes = this.getEntityType();
|
||
|
MinecraftKey minecraftkey = EntityTypes.getName(entitytypes);
|
||
|
|
||
|
- return entitytypes.a() && minecraftkey != null ? minecraftkey.toString() : null;
|
||
|
+ return entitytypes != null && entitytypes.isPersistable() ? getMinecraftKeyString() : null;
|
||
|
+ // Paper end
|
||
|
}
|
||
|
|
||
|
protected abstract void loadData(NBTTagCompound nbttagcompound);
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityTypes.java b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
||
|
index ac57ab9992e141c91cf48f033148ad78433b364c..dc92b112770955f9fa49a408262da2e5bbc4bf98 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
||
|
@@ -384,6 +384,7 @@ public class EntityTypes<T extends Entity> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+ public boolean isPersistable() { return a(); } // Paper - OBFHELPER
|
||
|
public boolean a() {
|
||
|
return this.bi;
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
|
||
|
index 72d43b38de3e797a509de6591874af12fa7b9ec0..2b58ae6d91fe0d0f36eedbb78a3c8a8a66d92405 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
|
||
|
@@ -23,7 +23,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||
|
|
||
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
||
|
|
||
|
-public abstract class TileEntity {
|
||
|
+public abstract class TileEntity implements net.minecraft.server.KeyedObject { // Paper
|
||
|
|
||
|
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
|
||
|
// CraftBukkit start - data containers
|
||
|
@@ -31,7 +31,7 @@ public abstract class TileEntity {
|
||
|
public CraftPersistentDataContainer persistentDataContainer;
|
||
|
// CraftBukkit end
|
||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||
|
- private final TileEntityTypes<?> tileType;
|
||
|
+ private final TileEntityTypes<?> tileType; public TileEntityTypes getTileEntityType() { return tileType; } // Paper - OBFHELPER
|
||
|
@Nullable
|
||
|
protected World world;
|
||
|
protected BlockPosition position;
|
||
|
@@ -45,6 +45,26 @@ public abstract class TileEntity {
|
||
|
this.tileType = tileentitytypes;
|
||
|
}
|
||
|
|
||
|
+ // Paper start
|
||
|
+ private String tileEntityKeyString = null;
|
||
|
+ private MinecraftKey tileEntityKey = null;
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public MinecraftKey getMinecraftKey() {
|
||
|
+ if (tileEntityKey == null) {
|
||
|
+ tileEntityKey = TileEntityTypes.a(this.getTileEntityType());
|
||
|
+ tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
|
||
|
+ }
|
||
|
+ return tileEntityKey;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public String getMinecraftKeyString() {
|
||
|
+ getMinecraftKey(); // Try to load if it doesn't exists.
|
||
|
+ return tileEntityKeyString;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
+
|
||
|
@Nullable
|
||
|
public World getWorld() {
|
||
|
return this.world;
|