Do crystal-portal proximity check before entity lookup

This adds a very cheap distance check when an end crystal is placed.

Attempting to respawn the dragon, which involves looking up the end crystal
entities near the portal, every time an end crystal is placed, can be slow on
some servers that have players placing end crystals as a style of combat.

The very cheap distance check prevents running the entity lookup every time.
This commit is contained in:
Martijn Muijsers
2023-08-15 21:04:55 +02:00
parent d66a2c4c26
commit cdc3b28062
2 changed files with 54 additions and 10 deletions

View File

@@ -1,6 +1,15 @@
--- a/net/minecraft/world/item/EndCrystalItem.java
+++ b/net/minecraft/world/item/EndCrystalItem.java
@@ -47,6 +47,12 @@
@@ -30,7 +30,7 @@
if (!iblockdata.is(Blocks.OBSIDIAN) && !iblockdata.is(Blocks.BEDROCK)) {
return InteractionResult.FAIL;
} else {
- BlockPos blockposition1 = blockposition.above();
+ BlockPos blockposition1 = blockposition.above(); final BlockPos aboveBlockPosition = blockposition1; // Paper - OBFHELPER
if (!world.isEmptyBlock(blockposition1)) {
return InteractionResult.FAIL;
@@ -47,12 +47,18 @@
EndCrystal entityendercrystal = new EndCrystal(world, d0 + 0.5D, d1, d2 + 0.5D);
entityendercrystal.setShowBottom(false);
@@ -13,3 +22,10 @@
world.addFreshEntity(entityendercrystal);
world.gameEvent((Entity) context.getPlayer(), (Holder) GameEvent.ENTITY_PLACE, blockposition1);
EndDragonFight enderdragonbattle = ((ServerLevel) world).getDragonFight();
if (enderdragonbattle != null) {
- enderdragonbattle.tryRespawn();
+ enderdragonbattle.tryRespawn(aboveBlockPosition); // Paper - Perf: Do crystal-portal proximity check before entity lookup
}
}