2021-08-27 11:14:09 +02:00
--- a/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
2021-09-01 10:55:18 +02:00
@@ -32,6 +32,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.chunk.storage.EntityStorage;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class PersistentEntitySectionManager<T extends EntityAccess> implements AutoCloseable {
static final Logger LOGGER = LogManager.getLogger();
@@ -55,6 +60,12 @@
this.entityGetter = new LevelEntityGetterAdapter<>(this.visibleEntityStorage, this.sectionStorage);
}
+ // CraftBukkit start - add method to get all entities in chunk
+ public List<Entity> getEntities(ChunkCoordIntPair chunkCoordIntPair) {
+ return sectionStorage.b(chunkCoordIntPair.pair()).flatMap(EntitySection::b).map(entiy -> (Entity) entiy).collect(Collectors.toList());
+ }
+ // CraftBukkit end
+
void a(long i, EntitySection<T> entitysection) {
if (entitysection.a()) {
this.sectionStorage.e(i);
@@ -82,7 +93,7 @@
2021-08-27 11:14:09 +02:00
long i = SectionPosition.c(t0.getChunkCoordinates());
EntitySection<T> entitysection = this.sectionStorage.c(i);
- entitysection.a((Object) t0);
+ entitysection.a(t0); // CraftBukkit - decompile error
t0.a(new PersistentEntitySectionManager.a(t0, i, entitysection));
if (!flag) {
this.callbacks.f(t0);
2021-09-01 10:55:18 +02:00
@@ -186,7 +197,7 @@
});
}
- private void b(long i) {
+ public void b(long i) { // PAIL private -> public, rename scheduleEntityLoading
PersistentEntitySectionManager.b persistententitysectionmanager_b = (PersistentEntitySectionManager.b) this.chunkLoadStatuses.get(i);
if (persistententitysectionmanager_b == PersistentEntitySectionManager.b.FRESH) {
@@ -196,6 +207,12 @@
}
private boolean a(long i, Consumer<T> consumer) {
+ // CraftBukkit start - add boolean for event call
+ return a(i, consumer, false);
+ }
+
+ private boolean a(long i, Consumer<T> consumer, boolean callEvent) {
+ // CraftBukkit end
PersistentEntitySectionManager.b persistententitysectionmanager_b = (PersistentEntitySectionManager.b) this.chunkLoadStatuses.get(i);
if (persistententitysectionmanager_b == PersistentEntitySectionManager.b.PENDING) {
@@ -207,6 +224,7 @@
if (list.isEmpty()) {
if (persistententitysectionmanager_b == PersistentEntitySectionManager.b.LOADED) {
+ if (callEvent) CraftEventFactory.callEntitiesUnloadEvent(((EntityStorage) permanentStorage).level, new ChunkCoordIntPair(i), ImmutableList.of()); // CraftBukkit
this.permanentStorage.a(new ChunkEntities<>(new ChunkCoordIntPair(i), ImmutableList.of()));
}
@@ -215,6 +233,7 @@
this.c(i);
return false;
} else {
+ if (callEvent) CraftEventFactory.callEntitiesUnloadEvent(((EntityStorage) permanentStorage).level, new ChunkCoordIntPair(i), list.stream().map(entity -> (Entity) entity).collect(Collectors.toList())); // CraftBukkit
this.permanentStorage.a(new ChunkEntities<>(new ChunkCoordIntPair(i), list));
list.forEach(consumer);
return true;
@@ -238,7 +257,7 @@
private boolean d(long i) {
boolean flag = this.a(i, (entityaccess) -> {
entityaccess.cD().forEach(this::g);
- });
+ }, true); // CraftBukkit - add boolean for event call
if (!flag) {
return false;
@@ -254,19 +273,23 @@
2021-08-27 11:14:09 +02:00
}
private void f() {
- this.chunksToUnload.removeIf((i) -> {
+ this.chunksToUnload.removeIf((java.util.function.LongPredicate) (i) -> { // CraftBukkit - decompile error
return this.chunkVisibility.get(i) != Visibility.HIDDEN ? true : this.d(i);
});
}
private void g() {
- ChunkEntities chunkentities;
+ ChunkEntities<T> chunkentities; // CraftBukkit - decompile error
while ((chunkentities = (ChunkEntities) this.loadingInbox.poll()) != null) {
chunkentities.b().forEach((entityaccess) -> {
2021-09-01 10:55:18 +02:00
this.a(entityaccess, true);
});
this.chunkLoadStatuses.put(chunkentities.a().pair(), PersistentEntitySectionManager.b.LOADED);
+ // CraftBukkit start - call entity load event
+ List<Entity> entities = getEntities(chunkentities.a()); // PAIL rename getChunkPos
+ CraftEventFactory.callEntitiesLoadEvent(((EntityStorage) permanentStorage).level, chunkentities.a(), entities);
+ // CraftBukkit end
}
}
@@ -292,7 +315,7 @@
2021-08-27 11:14:09 +02:00
}
public void b() {
- this.h().forEach((i) -> {
+ this.h().forEach((java.util.function.LongConsumer) (i) -> { // CraftBukkit - decompile error
boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN;
if (flag) {
2021-09-01 10:55:18 +02:00
@@ -311,7 +334,7 @@
2021-08-27 11:14:09 +02:00
while (!longset.isEmpty()) {
this.permanentStorage.a(false);
this.g();
- longset.removeIf((i) -> {
+ longset.removeIf((java.util.function.LongPredicate) (i) -> { // CraftBukkit - decompile error
boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN;
return flag ? this.d(i) : this.a(i, (entityaccess) -> {
2021-09-01 10:55:18 +02:00
@@ -323,7 +346,15 @@
2021-08-27 11:14:09 +02:00
}
public void close() throws IOException {
- this.c();
+ // CraftBukkit start - add save boolean
+ close(true);
+ }
+
+ public void close(boolean save) throws IOException {
+ if (save) {
+ this.c(); // PAIL rename saveAll
+ }
+ // CraftBukkit end
this.permanentStorage.close();
}
2021-09-01 10:55:18 +02:00
@@ -350,7 +381,7 @@
2021-08-27 11:14:09 +02:00
public void a(Writer writer) throws IOException {
CSVWriter csvwriter = CSVWriter.a().a("x").a("y").a("z").a("visibility").a("load_status").a("entity_count").a(writer);
- this.sectionStorage.a().forEach((i) -> {
+ this.sectionStorage.a().forEach((java.util.function.LongConsumer) (i) -> { // CraftBukkit - decompile error
PersistentEntitySectionManager.b persistententitysectionmanager_b = (PersistentEntitySectionManager.b) this.chunkLoadStatuses.get(i);
this.sectionStorage.a(i).forEach((j) -> {
2021-09-01 10:55:18 +02:00
@@ -389,7 +420,7 @@
2021-08-27 11:14:09 +02:00
private EntitySection<T> currentSection;
a(EntityAccess entityaccess, long i, EntitySection entitysection) {
- this.entity = entityaccess;
+ this.entity = (T) entityaccess; // CraftBukkit - decompile error
this.currentSectionKey = i;
this.currentSection = entitysection;
}
2021-09-01 10:55:18 +02:00
@@ -409,7 +440,7 @@
2021-08-27 11:14:09 +02:00
PersistentEntitySectionManager.this.a(this.currentSectionKey, this.currentSection);
EntitySection<T> entitysection = PersistentEntitySectionManager.this.sectionStorage.c(i);
- entitysection.a((Object) this.entity);
+ entitysection.a(this.entity); // CraftBukkit - decompile error
this.currentSection = entitysection;
this.currentSectionKey = i;
this.a(visibility, entitysection.c());