Paper/Spigot-Server-Patches/0022-Optimize-TileEntity-Ticking.patch
Mariell Hoversholm 0b33230f2d Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
eeb1042f #491: Add support to change block's lid state

CraftBukkit Changes:
8fb65851 #660: Add support to change block's lid state
2020-07-29 16:01:09 -04:00

222 Zeilen
10 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 8 Mar 2015 22:55:25 -0600
Subject: [PATCH] Optimize TileEntity Ticking
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
index d4ebcf8f66197299256bd6b65710a1488c90ea41..c9164dfdb27ddf3709129c8aec54903a1df121ff 100644
--- a/src/main/java/co/aikar/timings/TimingsExport.java
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
@@ -109,7 +109,7 @@ public class TimingsExport extends Thread {
pair("end", System.currentTimeMillis() / 1000),
pair("online-mode", Bukkit.getServer().getOnlineMode()),
pair("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000),
- pair("datapacks", toArrayMapper(MinecraftServer.getServer().getResourcePackRepository().d(), pack -> {
+ pair("datapacks", toArrayMapper(MinecraftServer.getServer().getResourcePackRepository().e(), pack -> {
// Don't feel like obf helper'ing these, non fatal if its temp missed.
return ChatColor.stripColor(CraftChatMessage.fromComponent(pack.a(true)));
}))
@@ -148,8 +148,8 @@ public class TimingsExport extends Thread {
);
parent.put("worlds", toObjectMapper(MinecraftServer.getServer().getWorlds(), world -> {
- if (world.getWorldData().getName().equals("worldeditregentempworld")) return null;
- return pair(world.getWorldData().getName(), createObject(
+ if (world.getWorld().getName().equals("worldeditregentempworld")) return null;
+ return pair(world.getWorld().getName(), createObject(
pair("gamerules", toObjectMapper(world.getWorld().getGameRules(), rule -> {
return pair(rule, world.getWorld().getGameRuleValue(rule));
})),
diff --git a/src/main/java/net/minecraft/server/BlockChest.java b/src/main/java/net/minecraft/server/BlockChest.java
index 1441d096d44ea653539ba20ccda94eb62ffc32df..b9d0d2d42850c3a5d093429cd0d02ac47848f04b 100644
--- a/src/main/java/net/minecraft/server/BlockChest.java
+++ b/src/main/java/net/minecraft/server/BlockChest.java
@@ -11,7 +11,7 @@ public class BlockChest extends BlockChestAbstract<TileEntityChest> implements I
public static final BlockStateDirection FACING = BlockFacingHorizontal.FACING;
public static final BlockStateEnum<BlockPropertyChestType> c = BlockProperties.aF;
- public static final BlockStateBoolean d = BlockProperties.C;
+ public static final BlockStateBoolean d = BlockProperties.C; public static final BlockStateBoolean waterlogged() { return d; } // Paper OBFHELPER
protected static final VoxelShape e = Block.a(1.0D, 0.0D, 0.0D, 15.0D, 14.0D, 15.0D);
protected static final VoxelShape f = Block.a(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 16.0D);
protected static final VoxelShape g = Block.a(0.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java
index 0a22bdbac4c627502e609166590a3936f3372161..47ed08c414dca46720a3d4808ea71f999232e70c 100644
--- a/src/main/java/net/minecraft/server/TileEntityChest.java
+++ b/src/main/java/net/minecraft/server/TileEntityChest.java
@@ -7,7 +7,7 @@ import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
// CraftBukkit end
-public class TileEntityChest extends TileEntityLootable implements ITickable {
+public class TileEntityChest extends TileEntityLootable { // Paper - Remove ITickable
private NonNullList<ItemStack> items;
protected float a;
@@ -85,14 +85,20 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
return nbttagcompound;
}
- @Override
public void tick() {
int i = this.position.getX();
int j = this.position.getY();
int k = this.position.getZ();
++this.j;
- this.viewingCount = a(this.world, this, this.j, i, j, k, this.viewingCount);
+ }
+
+ public void doOpenLogic() {
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
+
+ //this.viewingCount = a(this.world, this, this.j, i, j, k, this.viewingCount); // Paper - check is faulty given our logic is called before active container set
this.b = this.a;
float f = 0.1F;
@@ -106,8 +112,11 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
if (this.viewingCount > 0 && this.a == 0.0F) {
this.a(SoundEffects.BLOCK_CHEST_OPEN);
}
+ }
- if (this.viewingCount == 0 && this.a > 0.0F || this.viewingCount > 0 && this.a < 1.0F) {
+ public void doCloseLogic() {
+ if (this.viewingCount == 0 /* && this.a > 0.0F || this.viewingCount > 0 && this.a < 1.0F */) { // Paper - disable all but player count check
+ /* // Paper - disable animation stuff
float f1 = this.a;
if (this.viewingCount > 0) {
@@ -123,8 +132,11 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
float f2 = 0.5F;
if (this.a < 0.5F && f1 >= 0.5F) {
- this.a(SoundEffects.BLOCK_CHEST_CLOSE);
- }
+ */
+ MCUtil.scheduleTask(10, () -> {
+ this.a(SoundEffects.BLOCK_CHEST_CLOSE);
+ }, "Chest Sounds");
+ //} // Paper end
if (this.a < 0.0F) {
this.a = 0.0F;
@@ -163,6 +175,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
}
public void a(SoundEffect soundeffect) { // PAIL private -> public, rename playSound
+ if (!this.getBlock().b(BlockChest.c)) { return; } // Paper - this can be delayed, double check exists - Fixes GH-2074
BlockPropertyChestType blockpropertychesttype = (BlockPropertyChestType) this.getBlock().get(BlockChest.c);
if (blockpropertychesttype != BlockPropertyChestType.LEFT) {
@@ -201,6 +214,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
++this.viewingCount;
if (this.world == null) return; // CraftBukkit
+ doOpenLogic(); // Paper
// CraftBukkit start - Call redstone event
if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
@@ -223,6 +237,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
--this.viewingCount;
// CraftBukkit start - Call redstone event
+ doCloseLogic(); // Paper
if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
int newPower = Math.max(0, Math.min(15, this.viewingCount));
diff --git a/src/main/java/net/minecraft/server/TileEntityEnderChest.java b/src/main/java/net/minecraft/server/TileEntityEnderChest.java
index b37a705e49f64b46c2256a1b6b077c67fa240b0f..9d03a9ae7fe85fdd0550f737246eef2688a51c8e 100644
--- a/src/main/java/net/minecraft/server/TileEntityEnderChest.java
+++ b/src/main/java/net/minecraft/server/TileEntityEnderChest.java
@@ -1,6 +1,6 @@
package net.minecraft.server;
-public class TileEntityEnderChest extends TileEntity implements ITickable {
+public class TileEntityEnderChest extends TileEntity { // Paper - Remove ITickable
public float a;
public float b;
@@ -11,18 +11,28 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
super(TileEntityTypes.ENDER_CHEST);
}
- @Override
public void tick() {
if (++this.g % 20 * 4 == 0) {
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.c);
}
this.b = this.a;
+ /* // Paper
int i = this.position.getX();
int j = this.position.getY();
int k = this.position.getZ();
float f = 0.1F;
double d0;
+ // Paper start
+ */
+ }
+
+ private void doOpenLogic() {
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
+ double d0;
+ // Paper end
if (this.c > 0 && this.a == 0.0F) {
double d1 = (double) i + 0.5D;
@@ -30,8 +40,17 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
d0 = (double) k + 0.5D;
this.world.playSound((EntityHuman) null, d1, (double) j + 0.5D, d0, SoundEffects.BLOCK_ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
+ // Paper start
+ }
- if (this.c == 0 && this.a > 0.0F || this.c > 0 && this.a < 1.0F) {
+ private void doCloseLogic() {
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
+ double d0;
+
+ if (this.c == 0) { /* && this.a > 0.0F || this.c > 0 && this.a < 1.0F) {
+ // Paper end
float f1 = this.a;
if (this.c > 0) {
@@ -47,11 +66,14 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
float f2 = 0.5F;
if (this.a < 0.5F && f1 >= 0.5F) {
+ // Paper start
+ */
d0 = (double) i + 0.5D;
double d2 = (double) k + 0.5D;
+ MCUtil.scheduleTask(10, () -> {
this.world.playSound((EntityHuman) null, d0, (double) j + 0.5D, d2, SoundEffects.BLOCK_ENDER_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
- }
+ }, "Chest Sounds");
if (this.a < 0.0F) {
this.a = 0.0F;
@@ -79,11 +101,13 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
public void d() {
++this.c;
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.c);
+ doOpenLogic(); // Paper
}
public void f() {
--this.c;
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.c);
+ doCloseLogic(); // Paper
}
public boolean a(EntityHuman entityhuman) {