2015-01-29 21:26:20 +00:00
|
|
|
From f3f9681b466aa0d0682a67e293c06ba928ffad9f Mon Sep 17 00:00:00 2001
|
2014-08-25 02:19:36 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
2014-11-28 01:17:45 +00:00
|
|
|
Date: Fri, 28 Nov 2014 04:14:14 -0600
|
2014-08-25 02:19:36 +00:00
|
|
|
Subject: [PATCH] Optimize TileEntity Ticking
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
2014-11-28 01:17:45 +00:00
|
|
|
index 7cf38ea..76cdc7e 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -56,6 +56,12 @@ public abstract class TileEntity {
|
2014-08-25 02:19:36 +00:00
|
|
|
}
|
2014-11-28 01:17:45 +00:00
|
|
|
// Spigot end
|
|
|
|
|
|
|
|
+ // PaperSpigot start - Optimized TileEntity Tick changes
|
2014-08-25 02:19:36 +00:00
|
|
|
+ private static int tileEntityCounter = 0;
|
|
|
|
+ public boolean isAdded = false;
|
|
|
|
+ public int tileId = tileEntityCounter++;
|
2014-11-28 01:17:45 +00:00
|
|
|
+ // PaperSpigot end
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
2014-11-28 01:17:45 +00:00
|
|
|
public TileEntity() {
|
|
|
|
this.position = BlockPosition.ZERO;
|
|
|
|
this.h = -1;
|
2014-08-25 02:19:36 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityBeacon.java b/src/main/java/net/minecraft/server/TileEntityBeacon.java
|
2015-01-29 21:26:20 +00:00
|
|
|
index 6bfde41..35d82ab 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityBeacon.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityBeacon.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -48,7 +48,7 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay
|
2014-08-25 02:19:36 +00:00
|
|
|
public TileEntityBeacon() {}
|
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
public void c() {
|
2014-08-25 02:19:36 +00:00
|
|
|
- if (this.world.getTime() % 80L == 0L) {
|
2014-11-28 01:17:45 +00:00
|
|
|
+ if (true || this.world.getTime() % 80L == 0L) { // PaperSpigot - controlled by Improved Tick Handling
|
|
|
|
this.m();
|
2014-08-25 02:19:36 +00:00
|
|
|
}
|
2014-11-28 01:17:45 +00:00
|
|
|
|
2014-08-25 02:19:36 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java
|
2014-11-28 01:17:45 +00:00
|
|
|
index 7444f4f..0f29365 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityChest.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityChest.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -246,7 +246,7 @@ public class TileEntityChest extends TileEntityContainer implements IUpdatePlaye
|
|
|
|
++this.n;
|
2014-08-25 02:19:36 +00:00
|
|
|
float f;
|
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
- if (!this.world.isStatic && this.l != 0 && (this.n + i + j + k) % 200 == 0) {
|
|
|
|
+ if (!this.world.isStatic && this.l != 0 && (this.n + i + j + k) % 10 == 0) { // PaperSpigot Reduced 200 -> 10 interval due to reduced tick rate from Improved Tick Handling
|
|
|
|
this.l = 0;
|
2014-08-25 02:19:36 +00:00
|
|
|
f = 5.0F;
|
2014-11-28 01:17:45 +00:00
|
|
|
List list = this.world.a(EntityHuman.class, new AxisAlignedBB((double) ((float) i - f), (double) ((float) j - f), (double) ((float) k - f), (double) ((float) (i + 1) + f), (double) ((float) (j + 1) + f), (double) ((float) (k + 1) + f)));
|
2014-08-25 02:19:36 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityEnderChest.java b/src/main/java/net/minecraft/server/TileEntityEnderChest.java
|
2014-11-28 01:17:45 +00:00
|
|
|
index 794cdc8..218b801 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityEnderChest.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityEnderChest.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -10,7 +10,7 @@ public class TileEntityEnderChest extends TileEntity implements IUpdatePlayerLis
|
|
|
|
public TileEntityEnderChest() {}
|
2014-08-25 02:19:36 +00:00
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
public void c() {
|
|
|
|
- if (++this.h % 20 * 4 == 0) {
|
|
|
|
+ if (++this.h % 4 == 0) { // PaperSpigot Reduced (20 * 4) -> 4 interval due to reduced tick rate from Improved Tick Handling
|
|
|
|
this.world.playBlockAction(this.position, Blocks.ENDER_CHEST, 1, this.g);
|
2014-08-25 02:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityLightDetector.java b/src/main/java/net/minecraft/server/TileEntityLightDetector.java
|
2014-11-28 01:17:45 +00:00
|
|
|
index 7b6f8ae..c6b593f 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityLightDetector.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityLightDetector.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -5,7 +5,7 @@ public class TileEntityLightDetector extends TileEntity implements IUpdatePlayer
|
2014-08-25 02:19:36 +00:00
|
|
|
public TileEntityLightDetector() {}
|
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
public void c() {
|
2014-08-25 02:19:36 +00:00
|
|
|
- if (this.world != null && !this.world.isStatic && this.world.getTime() % 20L == 0L) {
|
|
|
|
+ if (this.world != null && !this.world.isStatic /*&& this.world.getTime() % 20L == 0L*/) { // PaperSpigot - interval controlled by Improved Tick Handling
|
2014-11-28 01:17:45 +00:00
|
|
|
this.e = this.w();
|
|
|
|
if (this.e instanceof BlockDaylightDetector) {
|
|
|
|
((BlockDaylightDetector) this.e).d(this.world, this.position);
|
2014-08-25 02:19:36 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2015-01-29 21:26:20 +00:00
|
|
|
index fa68938..7507580 100644
|
2014-08-25 02:19:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2014-11-28 01:17:45 +00:00
|
|
|
@@ -3,13 +3,7 @@ package net.minecraft.server;
|
|
|
|
import com.google.common.base.Predicate;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Calendar;
|
|
|
|
-import java.util.Collection;
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Random;
|
|
|
|
-import java.util.UUID;
|
|
|
|
+import java.util.*;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
@@ -59,7 +53,7 @@ public abstract class World implements IBlockAccess {
|
2014-08-25 02:19:36 +00:00
|
|
|
// Spigot end
|
2014-11-28 01:17:45 +00:00
|
|
|
protected final List g = Lists.newArrayList();
|
|
|
|
public final List h = Lists.newArrayList();
|
|
|
|
- public final List tileEntityList = Lists.newArrayList();
|
|
|
|
+ public final Set tileEntityList = new org.github.paperspigot.WorldTileEntityList(this); // PaperSpigot
|
|
|
|
private final List a = Lists.newArrayList();
|
|
|
|
private final List b = Lists.newArrayList();
|
|
|
|
public final List players = Lists.newArrayList();
|
|
|
|
diff --git a/src/main/java/org/github/paperspigot/WorldTileEntityList.java b/src/main/java/org/github/paperspigot/WorldTileEntityList.java
|
2014-08-25 02:19:36 +00:00
|
|
|
new file mode 100644
|
2014-11-28 01:17:45 +00:00
|
|
|
index 0000000..1a53e94
|
2014-08-25 02:19:36 +00:00
|
|
|
--- /dev/null
|
2014-11-28 01:17:45 +00:00
|
|
|
+++ b/src/main/java/org/github/paperspigot/WorldTileEntityList.java
|
|
|
|
@@ -0,0 +1,175 @@
|
|
|
|
+package org.github.paperspigot;
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
|
|
|
+import com.google.common.collect.ArrayListMultimap;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+import com.google.common.collect.Multimap;
|
|
|
|
+import net.minecraft.server.*;
|
2014-11-28 01:17:45 +00:00
|
|
|
+import gnu.trove.map.hash.TObjectIntHashMap;
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+public class WorldTileEntityList extends HashSet<TileEntity> {
|
|
|
|
+ private static final TObjectIntHashMap<Class<? extends TileEntity>> tileEntityTickIntervals =
|
2014-11-28 01:17:45 +00:00
|
|
|
+ new TObjectIntHashMap<Class<? extends TileEntity>>() {{
|
|
|
|
+ // Use -1 for no ticking
|
|
|
|
+ // These TE's have empty tick methods, doing nothing. Never bother ticking them.
|
|
|
|
+ for (Class<? extends TileEntity> ignored : new Class[]{
|
|
|
|
+ TileEntityChest.class, // PaperSpigot - Don't tick chests either
|
|
|
|
+ TileEntityEnderChest.class, // PaperSpigot - Don't tick chests either
|
|
|
|
+ TileEntityRecordPlayer.class,
|
|
|
|
+ TileEntityDispenser.class,
|
|
|
|
+ TileEntityDropper.class,
|
|
|
|
+ TileEntitySign.class,
|
|
|
|
+ TileEntityNote.class,
|
|
|
|
+ TileEntityEnderPortal.class,
|
|
|
|
+ TileEntityCommand.class,
|
|
|
|
+ TileEntitySkull.class,
|
|
|
|
+ TileEntityComparator.class,
|
|
|
|
+ TileEntityFlowerPot.class
|
|
|
|
+ }) {
|
|
|
|
+ put(ignored, -1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // does findPlayer lookup, so this helps performance to slow down
|
|
|
|
+ put(TileEntityEnchantTable.class, 20);
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
2014-11-28 01:17:45 +00:00
|
|
|
+ // Slow things down that players won't notice due to craftbukkit "wall time" patches.
|
|
|
|
+ // These need to be investigated further before they can be safely used here
|
|
|
|
+ //put(TileEntityFurnace.class, 20);
|
|
|
|
+ //put(TileEntityBrewingStand.class, 10);
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
2014-11-28 01:17:45 +00:00
|
|
|
+ // Vanilla controlled values - These are checks already done in vanilla, so don't tick on ticks we know
|
|
|
|
+ // won't do anything anyways
|
|
|
|
+ put(TileEntityBeacon.class, 80);
|
|
|
|
+ put(TileEntityLightDetector.class, 20);
|
|
|
|
+ }};
|
2014-08-25 02:19:36 +00:00
|
|
|
+
|
|
|
|
+ private static int getInterval(Class<? extends TileEntity> cls) {
|
|
|
|
+ int tickInterval = tileEntityTickIntervals.get(cls);
|
|
|
|
+ return tickInterval != 0 ? tickInterval : 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static int getBucketId(TileEntity entity, Integer interval) {
|
|
|
|
+ return entity.tileId % interval;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private final Map<Integer, Multimap<Integer, TileEntity>> tickList = Maps.newHashMap();
|
|
|
|
+ private final WorldServer world;
|
|
|
|
+
|
|
|
|
+ public WorldTileEntityList(World world) {
|
|
|
|
+ this.world = (WorldServer) world;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private Multimap<Integer, TileEntity> getBucket(int interval) {
|
|
|
|
+ Multimap<Integer, TileEntity> intervalBucket = tickList.get(interval);
|
|
|
|
+ if (intervalBucket == null) {
|
|
|
|
+ intervalBucket = ArrayListMultimap.create();
|
|
|
|
+ tickList.put(interval, intervalBucket);
|
|
|
|
+ }
|
|
|
|
+ return intervalBucket;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Adds the TileEntity to the tick list only if it is expected to tick
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean add(TileEntity entity) {
|
|
|
|
+ if (entity.isAdded) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int interval = getInterval(entity.getClass());
|
|
|
|
+ if (interval > 0) {
|
|
|
|
+ entity.isAdded = true;
|
|
|
|
+ int bucket = getBucketId(entity, interval);
|
|
|
|
+ Multimap<Integer, TileEntity> typeBucket = getBucket(interval);
|
|
|
|
+ return typeBucket.put(bucket, entity);
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean remove(Object o) {
|
|
|
|
+ if (!(o instanceof TileEntity)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ TileEntity entity = (TileEntity) o;
|
|
|
|
+ if (!entity.isAdded) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ entity.isAdded = false;
|
|
|
|
+ int interval = getInterval(entity.getClass());
|
|
|
|
+ int bucket = getBucketId(entity, interval);
|
|
|
|
+ Multimap<Integer, TileEntity> typeBucket = getBucket(interval);
|
|
|
|
+ return typeBucket.remove(bucket, entity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Iterator iterator() {
|
|
|
|
+ return new WorldTileEntityIterator();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean contains(Object o) {
|
|
|
|
+ return o instanceof TileEntity && ((TileEntity) o).isAdded;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private class WorldTileEntityIterator implements Iterator<TileEntity> {
|
|
|
|
+ private final Iterator<Map.Entry<Integer, Multimap<Integer, TileEntity>>> intervalIterator;
|
|
|
|
+ private Map.Entry<Integer, Multimap<Integer, TileEntity>> intervalMap = null;
|
|
|
|
+ private Iterator<TileEntity> listIterator = null;
|
|
|
|
+
|
|
|
|
+ protected WorldTileEntityIterator() {
|
|
|
|
+ intervalIterator = tickList.entrySet().iterator();
|
|
|
|
+ nextInterval();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean nextInterval() {
|
|
|
|
+ listIterator = null;
|
|
|
|
+ if (intervalIterator.hasNext()) {
|
|
|
|
+ intervalMap = intervalIterator.next();
|
|
|
|
+
|
|
|
|
+ final Integer interval = intervalMap.getKey();
|
|
|
|
+ final Multimap<Integer, TileEntity> buckets = intervalMap.getValue();
|
|
|
|
+
|
|
|
|
+ int bucket = (int) (world.getTime() % interval);
|
|
|
|
+
|
|
|
|
+ if (!buckets.isEmpty() && buckets.containsKey(bucket)) {
|
|
|
|
+ final Collection<TileEntity> tileList = buckets.get(bucket);
|
|
|
|
+
|
|
|
|
+ if (tileList != null && !tileList.isEmpty()) {
|
|
|
|
+ listIterator = tileList.iterator();
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean hasNext() {
|
|
|
|
+ do {
|
|
|
|
+ if (listIterator != null && listIterator.hasNext()) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } while (nextInterval());
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public TileEntity next() {
|
|
|
|
+ return listIterator.next();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void remove() {
|
|
|
|
+ listIterator.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
2014-11-28 01:17:45 +00:00
|
|
|
\ No newline at end of file
|
2014-08-25 02:19:36 +00:00
|
|
|
--
|
2015-01-29 21:26:20 +00:00
|
|
|
1.9.5.msysgit.0
|
2014-08-25 02:19:36 +00:00
|
|
|
|