2021-06-15 10:29:12 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: CullanP <cullanpage@gmail.com>
|
|
|
|
Date: Thu, 3 Mar 2016 02:13:38 -0600
|
|
|
|
Subject: [PATCH] Avoid hopper searches if there are no items
|
|
|
|
|
|
|
|
Hoppers searching for items and minecarts is the most expensive part of hopper ticking.
|
|
|
|
We keep track of the number of minecarts and items in a chunk.
|
|
|
|
If there are no items in the chunk, we skip searching for items.
|
|
|
|
If there are no minecarts in the chunk, we skip searching for them.
|
|
|
|
|
|
|
|
Usually hoppers aren't near items, so we can skip most item searches.
|
|
|
|
And since minecart hoppers are used _very_ rarely near we can avoid alot of searching there.
|
|
|
|
|
|
|
|
Combined, this adds up a lot.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
2022-03-01 06:43:03 +01:00
|
|
|
index bfbd1922d77602628e57326b3251459f45b1aed9..334fd625829c8e5e9c434b184f6d0084b2d6ccc8 100644
|
2021-06-15 10:29:12 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -986,7 +986,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2021-06-15 10:29:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- });
|
|
|
|
+ }, predicate == net.minecraft.world.entity.EntitySelector.CONTAINER_ENTITY_SELECTOR); // Paper
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntitySection.java b/src/main/java/net/minecraft/world/level/entity/EntitySection.java
|
2022-03-01 04:25:13 +01:00
|
|
|
index 524f3c42964eb83c9109bcc548a1075f1e295411..e9aee7d11798c3bd990466f101e9e342686de11c 100644
|
2021-06-15 10:29:12 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntitySection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntitySection.java
|
2021-11-24 10:01:27 +01:00
|
|
|
@@ -13,6 +13,10 @@ public class EntitySection<T extends EntityAccess> {
|
2022-03-01 06:43:03 +01:00
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2021-06-15 10:29:12 +02:00
|
|
|
private final ClassInstanceMultiMap<T> storage;
|
|
|
|
private Visibility chunkStatus;
|
|
|
|
+ // Paper start - track number of items and minecarts
|
|
|
|
+ public int itemCount;
|
|
|
|
+ public int inventoryEntityCount;
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public EntitySection(Class<T> entityClass, Visibility status) {
|
|
|
|
this.chunkStatus = status;
|
2021-11-24 10:01:27 +01:00
|
|
|
@@ -20,10 +24,24 @@ public class EntitySection<T extends EntityAccess> {
|
2021-06-15 10:29:12 +02:00
|
|
|
}
|
|
|
|
|
2021-11-24 23:26:32 +01:00
|
|
|
public void add(T entity) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ // Paper start
|
2021-11-24 23:26:32 +01:00
|
|
|
+ if (entity instanceof net.minecraft.world.entity.item.ItemEntity) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ this.itemCount++;
|
2021-11-24 23:26:32 +01:00
|
|
|
+ } else if (entity instanceof net.minecraft.world.Container) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ this.inventoryEntityCount++;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-11-24 23:26:32 +01:00
|
|
|
this.storage.add(entity);
|
2021-06-15 10:29:12 +02:00
|
|
|
}
|
|
|
|
|
2021-11-24 23:26:32 +01:00
|
|
|
public boolean remove(T entity) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ // Paper start
|
2021-11-24 23:26:32 +01:00
|
|
|
+ if (entity instanceof net.minecraft.world.entity.item.ItemEntity) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ this.itemCount--;
|
2021-11-24 23:26:32 +01:00
|
|
|
+ } else if (entity instanceof net.minecraft.world.Container) {
|
2021-06-15 10:29:12 +02:00
|
|
|
+ this.inventoryEntityCount--;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-11-24 23:26:32 +01:00
|
|
|
return this.storage.remove(entity);
|
2021-06-15 10:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
2022-06-03 06:26:56 +02:00
|
|
|
index 078be552dce5c02f699bad83816c3154cef2b1ec..2e873762530e8f50158886436bd76b35d91953af 100644
|
2021-06-15 10:29:12 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntitySectionStorage.java
|
2021-12-07 04:40:26 +01:00
|
|
|
@@ -111,13 +111,20 @@ public class EntitySectionStorage<T extends EntityAccess> {
|
2021-06-15 10:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void getEntities(AABB box, Consumer<T> action) {
|
|
|
|
+ // Paper start
|
2021-12-07 04:40:26 +01:00
|
|
|
+ this.getEntities(box, action, false);
|
2021-06-15 10:29:12 +02:00
|
|
|
+ }
|
|
|
|
+ public void getEntities(AABB box, Consumer<T> action, boolean isContainerSearch) {
|
|
|
|
+ // Paper end
|
2021-11-24 23:26:32 +01:00
|
|
|
this.forEachAccessibleNonEmptySection(box, (section) -> {
|
|
|
|
+ if (isContainerSearch && section.inventoryEntityCount <= 0) return; // Paper
|
|
|
|
section.getEntities(box, action);
|
2021-06-15 10:29:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public <U extends T> void getEntities(EntityTypeTest<T, U> filter, AABB box, Consumer<U> action) {
|
2021-11-24 23:26:32 +01:00
|
|
|
this.forEachAccessibleNonEmptySection(box, (section) -> {
|
|
|
|
+ if (filter.getBaseClass() == net.minecraft.world.entity.item.ItemEntity.class && section.itemCount <= 0) return; // Paper
|
|
|
|
section.getEntities(filter, box, action);
|
2021-06-15 10:29:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
|
|
index 9723a0ad61548c8c6c4c5ef20a150d5b17d80afd..da1ad0b2679e392ed81b50c15f012c63cb5c939e 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
|
|
@@ -17,6 +17,7 @@ public interface LevelEntityGetter<T extends EntityAccess> {
|
|
|
|
<U extends T> void get(EntityTypeTest<T, U> filter, Consumer<U> action);
|
|
|
|
|
|
|
|
void get(AABB box, Consumer<T> action);
|
|
|
|
+ void get(AABB box, Consumer<T> action, boolean isContainerSearch); // Paper
|
|
|
|
|
|
|
|
<U extends T> void get(EntityTypeTest<T, U> filter, AABB box, Consumer<U> action);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
|
|
index d5129c12c79eb6fe6b7e5f8eed4d24226423f5fd..3b13f6ea36a3bfecabe09221eb5c48dddab119db 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
|
|
@@ -38,7 +38,13 @@ public class LevelEntityGetterAdapter<T extends EntityAccess> implements LevelEn
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void get(AABB box, Consumer<T> action) {
|
|
|
|
- this.sectionStorage.getEntities(box, action);
|
|
|
|
+ // Paper start
|
|
|
|
+ this.get(box, action, false);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public void get(AABB box, Consumer<T> action, boolean isContainerSearch) {
|
|
|
|
+ this.sectionStorage.getEntities(box, action, isContainerSearch);
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|