3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/server/0008-Add-MinecraftKey-Information-to-Objects.patch

146 Zeilen
6.4 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-06-11 14:02:28 +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
index 0000000000000000000000000000000000000000..d02bd109399d6b32cbbb5e6f9ec7e650e8299a26
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
@@ -0,0 +1,12 @@
2021-06-11 14:02:28 +02:00
+package net.minecraft.server;
+
+import net.minecraft.resources.ResourceLocation;
+
+// TODO(Mariell Hoversholm): Move stupid ass class
2021-06-11 14:02:28 +02:00
+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 f62223f11e4be40350ca0ff0beb46fa68a1582fe..b494980b4a3303b2f19002d44f81a2707e6916a5 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
@@ -146,7 +146,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 {
+public abstract class Entity implements Nameable, EntityAccess, CommandSource, net.minecraft.server.KeyedObject { // Paper
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
@@ -1954,12 +1954,31 @@ 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;
+ }
@Nullable
public final String getEncodeId() {
EntityType<?> entitytypes = this.getType();
ResourceLocation minecraftkey = EntityType.getKey(entitytypes);
- return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
+ return entitytypes != null && entitytypes.isPersistable() ? getMinecraftKeyString() : null;
+ // 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/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 89e7d02b88404ac5dce06595432ae95c9a4e5015..3ffaeb72be8cda7a2b9398b8909db5c220e8b6c9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -398,6 +398,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
}
}
+ public boolean isPersistable() { return canSerialize(); } // Paper - OBFHELPER
public boolean canSerialize() {
return this.serialize;
}
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 33884161de688c47c90a7b86196234acc80f9434..e4601134598e509a158ceacec6099a78bbabe89d 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
@@ -20,7 +20,7 @@ import org.bukkit.inventory.InventoryHolder;
2021-06-11 14:02:28 +02:00
import org.spigotmc.CustomTimingsHandler; // Spigot
-public abstract class BlockEntity {
+public abstract class BlockEntity implements net.minecraft.server.KeyedObject { // Paper
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
// CraftBukkit start - data containers
@@ -28,7 +28,7 @@ public abstract class BlockEntity {
2021-06-11 14:02:28 +02:00
public CraftPersistentDataContainer persistentDataContainer;
// CraftBukkit end
private static final Logger LOGGER = LogManager.getLogger();
- private final BlockEntityType<?> type;
+ private final BlockEntityType<?> type; public BlockEntityType getTileEntityType() { return type; } // Paper - OBFHELPER
@Nullable
protected Level level;
protected final BlockPos worldPosition;
@@ -41,6 +41,26 @@ public abstract class BlockEntity {
this.blockState = state;
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) {
+ tileEntityKey = BlockEntityType.getKey(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 Level getLevel() {
return this.level;