2021-06-13 13:40:34 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 6 Apr 2019 10:16:48 -0400
|
2024-01-21 12:53:04 +01:00
|
|
|
Subject: [PATCH] Optimize Captured BlockEntity Lookup
|
2021-06-13 13:40:34 +02:00
|
|
|
|
|
|
|
upstream was doing a containsKey/get pattern, and always doing it at that.
|
|
|
|
that scenario is only even valid if were in the middle of a block place.
|
|
|
|
|
|
|
|
Optimize to check if the captured list even has values in it, and also to
|
|
|
|
just do a get call since the value can never be null.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
2024-08-31 20:29:50 +02:00
|
|
|
index 4c4449f7dee8695a362f83b9356e5754244fff18..60b04a16c6cb0a7109bda5c16e23c1d56ab7afad 100644
|
2021-06-13 13:40:34 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2024-06-13 22:14:13 +02:00
|
|
|
@@ -912,9 +912,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2021-06-13 13:40:34 +02:00
|
|
|
|
|
|
|
@Nullable
|
2021-11-24 04:42:31 +01:00
|
|
|
public BlockEntity getBlockEntity(BlockPos blockposition, boolean validate) {
|
2021-06-13 13:40:34 +02:00
|
|
|
- if (this.capturedTileEntities.containsKey(blockposition)) {
|
|
|
|
- return this.capturedTileEntities.get(blockposition);
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper start - Perf: Optimize capturedTileEntities lookup
|
2021-06-13 13:40:34 +02:00
|
|
|
+ net.minecraft.world.level.block.entity.BlockEntity blockEntity;
|
|
|
|
+ if (!this.capturedTileEntities.isEmpty() && (blockEntity = this.capturedTileEntities.get(blockposition)) != null) {
|
|
|
|
+ return blockEntity;
|
|
|
|
}
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper end - Perf: Optimize capturedTileEntities lookup
|
2021-06-13 13:40:34 +02:00
|
|
|
// CraftBukkit end
|
2024-01-24 13:07:40 +01:00
|
|
|
return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, LevelChunk.EntityCreationType.IMMEDIATE));
|
2021-06-13 13:40:34 +02:00
|
|
|
}
|