2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-07-23 01:39:56 +02:00
From: Aikar <aikar@aikar.co>
Date: Sun, 8 Mar 2015 22:55:25 -0600
2018-07-15 03:53:17 +02:00
Subject: [PATCH] Optimize TileEntity Ticking
2020-06-26 14:04:38 +02:00
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
2020-08-25 04:22:08 +02:00
index 1441d096d44ea653539ba20ccda94eb62ffc32df..fb7c0d45765e36181c809b250ba4eee5d21c5894 100644
2020-06-26 14:04:38 +02:00
--- a/src/main/java/net/minecraft/server/BlockChest.java
+++ b/src/main/java/net/minecraft/server/BlockChest.java
2020-08-25 04:22:08 +02:00
@@ -10,8 +10,8 @@ import javax.annotation.Nullable;
public class BlockChest extends BlockChestAbstract<TileEntityChest> implements IBlockWaterlogged {
2020-06-26 14:04:38 +02:00
public static final BlockStateDirection FACING = BlockFacingHorizontal.FACING;
2020-08-25 04:22:08 +02:00
- public static final BlockStateEnum<BlockPropertyChestType> c = BlockProperties.aF;
2020-06-26 14:04:38 +02:00
- public static final BlockStateBoolean d = BlockProperties.C;
2020-08-25 04:22:08 +02:00
+ public static final BlockStateEnum<BlockPropertyChestType> c = BlockProperties.aF; public static final BlockStateEnum<BlockPropertyChestType> CHEST_TYPE_PROPERTY = c; // Paper - OBFHELPER
2020-06-26 14:04:38 +02:00
+ 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);
2020-08-25 04:22:08 +02:00
diff --git a/src/main/java/net/minecraft/server/IBlockDataHolder.java b/src/main/java/net/minecraft/server/IBlockDataHolder.java
index 98616f0db75d0e2b2e960dbf88289c87ba426ab6..b19c694cf01bc868dd7c4ec6432b613d19f2ca40 100644
--- a/src/main/java/net/minecraft/server/IBlockDataHolder.java
+++ b/src/main/java/net/minecraft/server/IBlockDataHolder.java
@@ -83,6 +83,7 @@ public abstract class IBlockDataHolder<O, S> {
return Collections.unmodifiableCollection(this.b.keySet());
}
+ public <T extends Comparable<T>> boolean contains(IBlockState<T> iblockstate) { return this.b(iblockstate); } // Paper - OBFHELPER
public <T extends Comparable<T>> boolean b(IBlockState<T> iblockstate) {
return this.b.containsKey(iblockstate);
}
2018-07-15 03:53:17 +02:00
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java
2020-08-25 04:22:08 +02:00
index d4b8daf1f064bff25ef5566b0288dad0087e379e..52f64460ba1bfb298f343f71a923c8f34de9e39d 100644
2018-07-15 03:53:17 +02:00
--- 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;
2020-07-29 21:50:16 +02:00
@@ -85,14 +85,20 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2019-04-24 03:00:24 +02:00
return nbttagcompound;
}
- @Override
public void tick() {
int i = this.position.getX();
int j = this.position.getY();
2018-07-15 03:53:17 +02:00
int k = this.position.getZ();
2019-04-24 03:00:24 +02:00
++this.j;
2019-08-05 18:35:40 +02:00
- this.viewingCount = a(this.world, this, this.j, i, j, k, this.viewingCount);
2018-07-15 03:53:17 +02:00
+ }
2019-04-24 03:00:24 +02:00
+
+ public void doOpenLogic() {
2018-07-15 03:53:17 +02:00
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
2019-04-24 03:00:24 +02:00
+
2019-08-05 18:35:40 +02:00
+ //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
2019-04-24 03:00:24 +02:00
this.b = this.a;
float f = 0.1F;
2019-08-05 18:35:40 +02:00
2020-07-29 21:50:16 +02:00
@@ -106,8 +112,11 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2019-04-24 03:00:24 +02:00
if (this.viewingCount > 0 && this.a == 0.0F) {
2020-08-25 04:22:08 +02:00
this.playOpenSound(SoundEffects.BLOCK_CHEST_OPEN);
2018-07-15 03:53:17 +02:00
}
+ }
2019-04-24 03:00:24 +02:00
- 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
2018-07-15 03:53:17 +02:00
float f1 = this.a;
2018-07-23 01:39:56 +02:00
2019-04-24 03:00:24 +02:00
if (this.viewingCount > 0) {
2020-07-29 21:50:16 +02:00
@@ -123,8 +132,11 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2018-07-23 01:39:56 +02:00
float f2 = 0.5F;
if (this.a < 0.5F && f1 >= 0.5F) {
2020-08-25 04:22:08 +02:00
+ */
2019-04-24 03:00:24 +02:00
+ MCUtil.scheduleTask(10, () -> {
2020-08-25 04:22:08 +02:00
this.playOpenSound(SoundEffects.BLOCK_CHEST_CLOSE);
- }
2020-06-09 09:17:25 +02:00
+ }, "Chest Sounds");
2019-04-24 03:00:24 +02:00
+ //} // Paper end
2018-07-23 01:39:56 +02:00
if (this.a < 0.0F) {
this.a = 0.0F;
2020-07-29 21:50:16 +02:00
@@ -163,6 +175,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2019-05-27 06:36:37 +02:00
}
2020-08-25 04:22:08 +02:00
public void playOpenSound(SoundEffect soundeffect) {
+ if (!this.getBlock().contains(BlockChest.CHEST_TYPE_PROPERTY)) { return; } // Paper - this can be delayed, double check exists - Fixes GH-2074
2019-12-11 01:56:03 +01:00
BlockPropertyChestType blockpropertychesttype = (BlockPropertyChestType) this.getBlock().get(BlockChest.c);
2019-05-27 06:36:37 +02:00
if (blockpropertychesttype != BlockPropertyChestType.LEFT) {
2020-07-29 21:50:16 +02:00
@@ -201,6 +214,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2018-07-15 03:53:17 +02:00
2019-04-24 03:00:24 +02:00
++this.viewingCount;
2018-07-15 03:53:17 +02:00
if (this.world == null) return; // CraftBukkit
+ doOpenLogic(); // Paper
// CraftBukkit start - Call redstone event
2019-04-24 03:00:24 +02:00
if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
2020-07-29 21:50:16 +02:00
@@ -223,6 +237,7 @@ public class TileEntityChest extends TileEntityLootable implements ITickable {
2019-04-24 03:00:24 +02:00
--this.viewingCount;
2018-07-15 03:53:17 +02:00
// CraftBukkit start - Call redstone event
+ doCloseLogic(); // Paper
2019-04-24 03:00:24 +02:00
if (this.getBlock().getBlock() == Blocks.TRAPPED_CHEST) {
int newPower = Math.max(0, Math.min(15, this.viewingCount));
2018-07-15 03:53:17 +02:00
diff --git a/src/main/java/net/minecraft/server/TileEntityEnderChest.java b/src/main/java/net/minecraft/server/TileEntityEnderChest.java
2020-08-25 04:22:08 +02:00
index 4ee3520882df2f6f358f3f61dc42c20129984b72..80440aa24f546dd151e89b705322d9c3e906b139 100644
2018-07-15 03:53:17 +02:00
--- 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
2019-01-01 04:15:55 +01:00
2018-07-15 03:53:17 +02:00
public float a;
2019-04-24 03:00:24 +02:00
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);
2018-07-15 03:53:17 +02:00
}
2019-04-24 03:00:24 +02:00
this.b = this.a;
+ /* // Paper
2018-07-15 03:53:17 +02:00
int i = this.position.getX();
int j = this.position.getY();
int k = this.position.getZ();
2019-01-01 04:15:55 +01:00
float f = 0.1F;
double d0;
2018-07-15 03:53:17 +02:00
+ // Paper start
2019-04-24 03:00:24 +02:00
+ */
2018-07-15 03:53:17 +02:00
+ }
2019-04-24 03:00:24 +02:00
+
2018-07-15 03:53:17 +02:00
+ private void doOpenLogic() {
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
2019-04-24 03:00:24 +02:00
+ double d0;
2018-07-15 03:53:17 +02:00
+ // Paper end
2019-01-01 04:15:55 +01:00
2019-04-24 03:00:24 +02:00
if (this.c > 0 && this.a == 0.0F) {
double d1 = (double) i + 0.5D;
2019-06-16 15:00:08 +02:00
@@ -30,8 +40,17 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
2019-04-24 03:00:24 +02:00
d0 = (double) k + 0.5D;
2019-07-20 06:01:24 +02:00
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);
2018-07-15 03:53:17 +02:00
}
+ // Paper start
+ }
2019-04-24 03:00:24 +02:00
2019-06-16 15:00:08 +02:00
- if (this.c == 0 && this.a > 0.0F || this.c > 0 && this.a < 1.0F) {
2018-07-15 03:53:17 +02:00
+ private void doCloseLogic() {
+ int i = this.position.getX();
+ int j = this.position.getY();
+ int k = this.position.getZ();
+ double d0;
2019-06-16 15:00:08 +02:00
+
+ if (this.c == 0) { /* && this.a > 0.0F || this.c > 0 && this.a < 1.0F) {
2018-07-15 03:53:17 +02:00
+ // Paper end
2019-01-01 04:15:55 +01:00
float f1 = this.a;
2019-06-16 15:00:08 +02:00
if (this.c > 0) {
2019-07-20 06:01:24 +02:00
@@ -47,11 +66,14 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
2019-06-16 15:00:08 +02:00
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, () -> {
2019-07-20 06:01:24 +02:00
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);
2019-06-16 15:00:08 +02:00
- }
2020-06-09 09:17:25 +02:00
+ }, "Chest Sounds");
2019-06-16 15:00:08 +02:00
if (this.a < 0.0F) {
this.a = 0.0F;
2019-07-20 06:01:24 +02:00
@@ -79,11 +101,13 @@ public class TileEntityEnderChest extends TileEntity implements ITickable {
2019-05-28 01:01:45 +02:00
public void d() {
2019-04-24 03:00:24 +02:00
++this.c;
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.c);
2018-07-15 03:53:17 +02:00
+ doOpenLogic(); // Paper
}
2019-05-28 01:01:45 +02:00
public void f() {
2019-04-24 03:00:24 +02:00
--this.c;
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.c);
2018-07-15 03:53:17 +02:00
+ doCloseLogic(); // Paper
}
public boolean a(EntityHuman entityhuman) {