3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00
Paper/patches/server/0009-Add-MinecraftKey-Information-to-Objects.patch

125 Zeilen
5.3 KiB
Diff

2021-06-11 14:02:28 +02:00
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 bee2fa2bfbb61209381f24ed6508d3d1c73a344a..1fa190e098079522e0fe3593fa261c1b7ad4e24b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -207,7 +207,7 @@ public class PaperCommand extends Command {
ServerChunkCache chunkProviderServer = world.getChunkSource();
2021-06-11 14:02:28 +02:00
world.getAllEntities().forEach(e -> {
2021-06-11 14:02:28 +02:00
- ResourceLocation key = new ResourceLocation(""); // TODO: update in next patch
+ ResourceLocation key = e.getMinecraftKey();
MutablePair<Integer, Map<ChunkPos, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
ChunkPos chunk = e.chunkPosition();
2021-11-23 11:51:25 +01:00
diff --git a/src/main/java/io/papermc/paper/util/KeyedObject.java b/src/main/java/io/papermc/paper/util/KeyedObject.java
2021-06-11 14:02:28 +02:00
new file mode 100644
2021-11-23 11:51:25 +01:00
index 0000000000000000000000000000000000000000..9f0c7fd903f085e70db1785fb8bcdb5456e6ca51
2021-06-11 14:02:28 +02:00
--- /dev/null
2021-11-23 11:51:25 +01:00
+++ b/src/main/java/io/papermc/paper/util/KeyedObject.java
@@ -0,0 +1,11 @@
+package io.papermc.paper.util;
2021-06-11 14:02:28 +02:00
+
+import net.minecraft.resources.ResourceLocation;
+
+public interface KeyedObject {
+ ResourceLocation getMinecraftKey();
+ default String getMinecraftKeyString() {
+ ResourceLocation 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 600cebdb6688ffef448d126233a329a6931ce37a..fdf607c91ee31206839b14212a20ee81ec751776 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -145,7 +145,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
2021-06-11 14:02:28 +02:00
import org.bukkit.plugin.PluginManager;
// CraftBukkit end
-public abstract class Entity implements Nameable, EntityAccess, CommandSource {
2021-11-23 11:51:25 +01:00
+public abstract class Entity implements Nameable, EntityAccess, CommandSource, io.papermc.paper.util.KeyedObject { // Paper
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
@@ -1949,12 +1949,32 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
2021-06-11 14:02:28 +02:00
return true;
}
+ // Paper start
+ private ResourceLocation entityKey;
+ private String entityKeyString;
+
+ @Override
+ public ResourceLocation getMinecraftKey() {
+ if (entityKey == null) {
+ this.entityKey = EntityType.getKey(this.getType());
+ 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;
+ }
2021-11-23 11:51:25 +01:00
+
2021-06-11 14:02:28 +02:00
@Nullable
public final String getEncodeId() {
EntityType<?> entitytypes = this.getType();
ResourceLocation minecraftkey = EntityType.getKey(entitytypes);
- return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
2021-06-16 19:48:25 +02:00
+ return entitytypes != null && entitytypes.canSerialize() ? getMinecraftKeyString() : null;
2021-06-11 14:02:28 +02:00
+ // Paper end
}
protected abstract void readAdditionalSaveData(CompoundTag nbt);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
index 30adcc82bc4e2e7145d29b64fde952d694cdf1e1..d33c2d2ec285179614d21a255cea394682e4cc2c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
2021-11-23 11:51:25 +01:00
@@ -23,7 +23,7 @@ import org.bukkit.inventory.InventoryHolder;
2021-06-11 14:02:28 +02:00
import org.spigotmc.CustomTimingsHandler; // Spigot
-public abstract class BlockEntity {
2021-11-23 11:51:25 +01:00
+public abstract class BlockEntity implements io.papermc.paper.util.KeyedObject { // Paper
2021-06-11 14:02:28 +02:00
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
// CraftBukkit start - data containers
2021-11-23 11:51:25 +01:00
@@ -48,6 +48,26 @@ public abstract class BlockEntity {
return new BlockPos(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ private String tileEntityKeyString = null;
+ private ResourceLocation tileEntityKey = null;
+
+ @Override
+ public ResourceLocation getMinecraftKey() {
+ if (tileEntityKey == null) {
2021-06-12 18:56:13 +02:00
+ tileEntityKey = BlockEntityType.getKey(this.type);
2021-06-11 14:02:28 +02:00
+ 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 Level getLevel() {
return this.level;