Yatopia/patches/server/0065-Tile-Entity-optimizations.patch
Ivan Pekov 784079fc31
optimizations (#297)
* Drop useless stuff

* Faster Random

* TE opts

* Patches.md

* More Faster Random

* Fix Build

* More Opts

* AirplaneLite

* Update README.md

removed TIC-TACS and adding AirplaneLite

* Add AirplaneLite to the update script

* Rebuild patches

* Make enchanting table ticking configurable

* AirplaneLite to commitUpstream.sh

* Use FastRandom on more places

Co-authored-by: Bud Gidiere <sgidiere@gmail.com>
Co-authored-by: Simon Gardling <Titaniumtown@gmail.com>
2020-11-30 20:08:41 -06:00

110 lines
6.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mykyta Komarnytskyy <nkomarn@hotmail.com>
Date: Fri, 30 Oct 2020 20:13:08 -0700
Subject: [PATCH] Tile Entity optimizations
This patch includes various tile entity optimizations. Normally, these aren't going to improve performance much, but can be useful if you have loads of tile entities or they are being used as building blocks.
diff --git a/src/main/java/net/minecraft/server/TileEntityBeehive.java b/src/main/java/net/minecraft/server/TileEntityBeehive.java
index a60e0872d51aeb330bd5334e35f18ad0ed63834e..40bde90306106534e73d6845caf956514e5dcf88 100644
--- a/src/main/java/net/minecraft/server/TileEntityBeehive.java
+++ b/src/main/java/net/minecraft/server/TileEntityBeehive.java
@@ -286,6 +286,7 @@ public class TileEntityBeehive extends TileEntity implements ITickable {
@Override
public void tick() {
+ if (this.bees.size() == 0) return; // Yatopia - TE optimizations
if (!this.world.isClientSide) {
this.y();
BlockPosition blockposition = this.getPosition();
diff --git a/src/main/java/net/minecraft/server/TileEntityEnchantTable.java b/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
index de597d053fcdb983b9b08f0628e4708e6149ffab..2400860b70cec7e1c875c0c6abd589f67b8f8146 100644
--- a/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
+++ b/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
@@ -43,6 +43,7 @@ public class TileEntityEnchantTable extends TileEntity implements INamableTileEn
@Override
public void tick() {
+ if (!net.yatopia.server.YatopiaConfig.shouldTickEnchantingTables) { return; } // Yatopia - TE optimizations
this.j = this.i;
this.l = this.k;
EntityHuman entityhuman = this.world.a((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D, 3.0D, false);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 7431bfc335dadfb5f5f83ccba6d8923c15756dc1..1f7449175329adae4bfc8eacb58b22830720a8b4 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -917,13 +917,18 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
if (!tileentity.isRemoved() && tileentity.hasWorld()) {
BlockPosition blockposition = tileentity.getPosition();
- if (this.getChunkProvider().a(blockposition) && this.getWorldBorder().a(blockposition)) {
+ // Yatopia start - TE optimizations
+ Chunk chunk = tileentity.getCurrentChunk();
+ PlayerChunk playerchunk = chunk == null ? null : chunk.playerChunk;
+ if (playerchunk == null) continue;
+ if (playerchunk.isTickingReady() && this.getWorldBorder().a(blockposition)) {
try {
gameprofilerfiller.a(() -> {
return String.valueOf(TileEntityTypes.a(tileentity.getTileType()));
});
tileentity.tickTimer.startTiming(); // Spigot
- if (tileentity.getTileType().isValidBlock(this.getType(blockposition).getBlock())) {
+ if (tileentity.getTileType().isValidBlock(chunk.getType(blockposition).getBlock())) {
+ // Yatopia end
((ITickable) tileentity).tick();
} else {
tileentity.w();
@@ -957,9 +962,12 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
this.tileEntityListTick.remove(tileTickPosition--);
// Spigot end
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
- if (this.isLoaded(tileentity.getPosition())) {
- this.getChunkAtWorldCoords(tileentity.getPosition()).removeTileEntity(tileentity.getPosition());
- }
+ // Yatopia start - TE optimizations
+ Chunk chunk = tileentity.getCurrentChunk();
+ if (chunk == null) continue;
+ // if (this.isLoaded(tileentity.getPosition())) {
+ chunk.removeTileEntity(tileentity.getPosition());
+ // } // Yatopia end
}
}
@@ -978,8 +986,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
}
// CraftBukkit end */
- if (this.isLoaded(tileentity1.getPosition())) {
- Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
+ // Yatopia start - TE optimizations
+ Chunk chunk = tileentity1.getCurrentChunk();
+ if (chunk == null) continue;
+ // if (this.isLoaded(tileentity1.getPosition())) {
+ // Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
IBlockData iblockdata = chunk.getType(tileentity1.getPosition());
chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
@@ -990,7 +1001,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
this.a(tileentity1);
}
// CraftBukkit end
- }
+ // } // Yatopia end
}
}
diff --git a/src/main/java/net/yatopia/server/YatopiaConfig.java b/src/main/java/net/yatopia/server/YatopiaConfig.java
index 5139279822b1fdc4a60de5abc76e81c75fe2e6bb..d33dd43747afc17dd80472c87e99b5cb409b40e9 100644
--- a/src/main/java/net/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/net/yatopia/server/YatopiaConfig.java
@@ -283,4 +283,9 @@ public class YatopiaConfig {
checkVehicleMovedQuickly = getBoolean("settings.checks.vehicle-moved-quickly", checkVehicleMovedQuickly);
checkVehicleMovedWrongly = getBoolean("settings.checks.vehicle-moved-wrongly", checkVehicleMovedWrongly);
}
+
+ public static boolean shouldTickEnchantingTables = false;
+ private static void tickEnchantingTables() {
+ shouldTickEnchantingTables = getBoolean("settings.tick.enchanting-tables", shouldTickEnchantingTables);
+ }
}