Start update to 1.21.4

Remove the EnderDragon entity retrieval inside ChunkEntitySlices
and move it to PlatformHooks#addToGetEntities for fabric (neoforge
already did this).
This commit is contained in:
Spottedleaf
2024-12-03 10:43:48 -08:00
parent 93b908350e
commit 7f08c11a11
6 changed files with 65 additions and 328 deletions

View File

@@ -15,6 +15,7 @@ import net.minecraft.server.level.GenerationChunkHolder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
@@ -27,6 +28,7 @@ import net.minecraft.world.level.chunk.status.ChunkStatusTasks;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.AABB;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
@@ -111,13 +113,43 @@ public final class FabricHooks implements PlatformHooks {
@Override
public void addToGetEntities(final Level world, final Entity entity, final AABB boundingBox, final Predicate<? super Entity> predicate,
final List<Entity> into) {
final Collection<EnderDragonPart> parts = world.dragonParts();
if (parts.isEmpty()) {
return;
}
for (final EnderDragonPart part : parts) {
if (part != entity && part.getBoundingBox().intersects(boundingBox) && (predicate == null || predicate.test(part))) {
into.add(part);
}
}
}
@Override
public <T extends Entity> void addToGetEntities(final Level world, final EntityTypeTest<Entity, T> entityTypeTest, final AABB boundingBox,
final Predicate<? super T> predicate, final List<? super T> into, final int maxCount) {
if (into.size() >= maxCount) {
// fix neoforge issue: do not add if list is already full
return;
}
final Collection<EnderDragonPart> parts = world.dragonParts();
if (parts.isEmpty()) {
return;
}
for (final EnderDragonPart part : parts) {
if (!part.getBoundingBox().intersects(boundingBox)) {
continue;
}
final T casted = (T)entityTypeTest.tryCast(part);
if (casted != null && (predicate == null || predicate.test(casted))) {
into.add(casted);
if (into.size() >= maxCount) {
break;
}
}
}
}
@Override

View File

@@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.3
loader_version=0.16.7
supported_minecraft_versions=1.21.3
neoforge_version=21.3.31-beta
fabric_api_version=0.107.0+1.21.3
minecraft_version=1.21.4
loader_version=0.16.9
supported_minecraft_versions=1.21.4
neoforge_version=21.4.0-beta
fabric_api_version=0.110.5+1.21.4
snakeyaml_version=2.3
concurrentutil_version=0.0.2-SNAPSHOT
yamlconfig_version=1.0.2-SNAPSHOT

View File

@@ -34,6 +34,7 @@ import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
import net.neoforged.neoforge.event.level.ChunkDataEvent;
import net.neoforged.neoforge.event.level.ChunkEvent;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
@@ -114,7 +115,12 @@ public final class NeoForgeHooks implements PlatformHooks {
@Override
public void addToGetEntities(final Level world, final Entity entity, final AABB boundingBox, final Predicate<? super Entity> predicate,
final List<Entity> into) {
for (final PartEntity<?> part : world.getPartEntities()) {
final Collection<PartEntity<?>> parts = world.dragonParts();
if (parts.isEmpty()) {
return;
}
for (final PartEntity<?> part : parts) {
if (part != entity && part.getBoundingBox().intersects(boundingBox) && (predicate == null || predicate.test(part))) {
into.add(part);
}
@@ -129,9 +135,18 @@ public final class NeoForgeHooks implements PlatformHooks {
return;
}
for (final PartEntity<?> part : world.getPartEntities()) {
final Collection<PartEntity<?>> parts = world.dragonParts();
if (parts.isEmpty()) {
return;
}
for (final PartEntity<?> part : parts) {
if (!part.getBoundingBox().intersects(boundingBox)) {
continue;
}
final T casted = (T)entityTypeTest.tryCast(part);
if (casted != null && casted.getBoundingBox().intersects(boundingBox) && (predicate == null || predicate.test(casted))) {
if (casted != null && (predicate == null || predicate.test(casted))) {
into.add(casted);
if (into.size() >= maxCount) {
break;

View File

@@ -24,7 +24,7 @@ pluginManagement {
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("xyz.jpenilla.quiet-architectury-loom") version "1.7.300" apply false
id("xyz.jpenilla.quiet-architectury-loom") version "1.7.310" apply false
id 'com.gradleup.shadow' version '8.3.0' apply false
}

View File

@@ -291,21 +291,12 @@ public final class ChunkEntitySlices {
}
public void getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate) {
this.allEntities.getEntitiesWithEnderDragonParts(except, box, into, predicate);
}
public void getEntitiesWithoutDragonParts(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate) {
this.allEntities.getEntities(except, box, into, predicate);
}
public boolean getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
final int maxCount) {
return this.allEntities.getEntitiesWithEnderDragonPartsLimited(except, box, into, predicate, maxCount);
}
public boolean getEntitiesWithoutDragonParts(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
final int maxCount) {
final int maxCount) {
return this.allEntities.getEntitiesLimited(except, box, into, predicate, maxCount);
}
@@ -319,7 +310,7 @@ public final class ChunkEntitySlices {
}
public <T extends Entity> boolean getEntities(final EntityType<?> type, final AABB box, final List<? super T> into,
final Predicate<? super T> predicate, final int maxCount) {
final Predicate<? super T> predicate, final int maxCount) {
final EntityCollectionBySection byType = this.entitiesByType.get(type);
if (byType != null) {
@@ -356,21 +347,21 @@ public final class ChunkEntitySlices {
final Predicate<? super T> predicate) {
EntityCollectionBySection collection = this.entitiesByClass.get(clazz);
if (collection != null) {
collection.getEntitiesWithEnderDragonParts(except, clazz, box, (List)into, (Predicate)predicate);
collection.getEntities(except, box, (List)into, (Predicate)predicate);
} else {
this.entitiesByClass.put(clazz, collection = this.initClass(clazz));
collection.getEntitiesWithEnderDragonParts(except, clazz, box, (List)into, (Predicate)predicate);
collection.getEntities(except, box, (List)into, (Predicate)predicate);
}
}
public <T extends Entity> boolean getEntities(final Class<? extends T> clazz, final Entity except, final AABB box, final List<? super T> into,
final Predicate<? super T> predicate, final int maxCount) {
final Predicate<? super T> predicate, final int maxCount) {
EntityCollectionBySection collection = this.entitiesByClass.get(clazz);
if (collection != null) {
return collection.getEntitiesWithEnderDragonPartsLimited(except, clazz, box, (List)into, (Predicate)predicate, maxCount);
return collection.getEntitiesLimited(except, box, (List)into, (Predicate)predicate, maxCount);
} else {
this.entitiesByClass.put(clazz, collection = this.initClass(clazz));
return collection.getEntitiesWithEnderDragonPartsLimited(except, clazz, box, (List)into, (Predicate)predicate, maxCount);
return collection.getEntitiesLimited(except, box, (List)into, (Predicate)predicate, maxCount);
}
}
@@ -574,225 +565,5 @@ public final class ChunkEntitySlices {
return false;
}
public void getEntitiesWithEnderDragonParts(final Entity except, final AABB box, final List<Entity> into,
final Predicate<? super Entity> predicate) {
if (this.count == 0) {
return;
}
final int minSection = this.slices.minSection;
final int maxSection = this.slices.maxSection;
final int min = Mth.clamp(Mth.floor(box.minY - 2.0) >> 4, minSection, maxSection);
final int max = Mth.clamp(Mth.floor(box.maxY + 2.0) >> 4, minSection, maxSection);
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
if (list == null) {
continue;
}
final Entity[] storage = list.storage;
for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
final Entity entity = storage[i];
if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
continue;
}
if (predicate == null || predicate.test(entity)) {
into.add(entity);
} // else: continue to test the ender dragon parts
if (entity instanceof EnderDragon) {
for (final EnderDragonPart part : ((EnderDragon)entity).getSubEntities()) {
if (part == except || !part.getBoundingBox().intersects(box)) {
continue;
}
if (predicate != null && !predicate.test(part)) {
continue;
}
into.add(part);
}
}
}
}
}
public boolean getEntitiesWithEnderDragonPartsLimited(final Entity except, final AABB box, final List<Entity> into,
final Predicate<? super Entity> predicate, final int maxCount) {
if (this.count == 0) {
return false;
}
final int minSection = this.slices.minSection;
final int maxSection = this.slices.maxSection;
final int min = Mth.clamp(Mth.floor(box.minY - 2.0) >> 4, minSection, maxSection);
final int max = Mth.clamp(Mth.floor(box.maxY + 2.0) >> 4, minSection, maxSection);
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
if (list == null) {
continue;
}
final Entity[] storage = list.storage;
for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
final Entity entity = storage[i];
if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
continue;
}
if (predicate == null || predicate.test(entity)) {
into.add(entity);
if (into.size() >= maxCount) {
return true;
}
} // else: continue to test the ender dragon parts
if (entity instanceof EnderDragon) {
for (final EnderDragonPart part : ((EnderDragon)entity).getSubEntities()) {
if (part == except || !part.getBoundingBox().intersects(box)) {
continue;
}
if (predicate != null && !predicate.test(part)) {
continue;
}
into.add(part);
if (into.size() >= maxCount) {
return true;
}
}
}
}
}
return false;
}
public void getEntitiesWithEnderDragonParts(final Entity except, final Class<?> clazz, final AABB box, final List<Entity> into,
final Predicate<? super Entity> predicate) {
if (this.count == 0) {
return;
}
final int minSection = this.slices.minSection;
final int maxSection = this.slices.maxSection;
final int min = Mth.clamp(Mth.floor(box.minY - 2.0) >> 4, minSection, maxSection);
final int max = Mth.clamp(Mth.floor(box.maxY + 2.0) >> 4, minSection, maxSection);
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
if (list == null) {
continue;
}
final Entity[] storage = list.storage;
for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
final Entity entity = storage[i];
if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
continue;
}
if (predicate == null || predicate.test(entity)) {
into.add(entity);
} // else: continue to test the ender dragon parts
if (entity instanceof EnderDragon) {
for (final EnderDragonPart part : ((EnderDragon)entity).getSubEntities()) {
if (part == except || !part.getBoundingBox().intersects(box) || !clazz.isInstance(part)) {
continue;
}
if (predicate != null && !predicate.test(part)) {
continue;
}
into.add(part);
}
}
}
}
}
public boolean getEntitiesWithEnderDragonPartsLimited(final Entity except, final Class<?> clazz, final AABB box, final List<Entity> into,
final Predicate<? super Entity> predicate, final int maxCount) {
if (this.count == 0) {
return false;
}
final int minSection = this.slices.minSection;
final int maxSection = this.slices.maxSection;
final int min = Mth.clamp(Mth.floor(box.minY - 2.0) >> 4, minSection, maxSection);
final int max = Mth.clamp(Mth.floor(box.maxY + 2.0) >> 4, minSection, maxSection);
final BasicEntityList<Entity>[] entitiesBySection = this.entitiesBySection;
for (int section = min; section <= max; ++section) {
final BasicEntityList<Entity> list = entitiesBySection[section - minSection];
if (list == null) {
continue;
}
final Entity[] storage = list.storage;
for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
final Entity entity = storage[i];
if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
continue;
}
if (predicate == null || predicate.test(entity)) {
into.add(entity);
if (into.size() >= maxCount) {
return true;
}
} // else: continue to test the ender dragon parts
if (entity instanceof EnderDragon) {
for (final EnderDragonPart part : ((EnderDragon)entity).getSubEntities()) {
if (part == except || !part.getBoundingBox().intersects(box) || !clazz.isInstance(part)) {
continue;
}
if (predicate != null && !predicate.test(part)) {
continue;
}
into.add(part);
if (into.size() >= maxCount) {
return true;
}
}
}
}
}
return false;
}
}
}

View File

@@ -209,7 +209,7 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
@Override
public void get(final AABB box, final Consumer<Entity> action) {
List<Entity> entities = new ArrayList<>();
this.getEntitiesWithoutDragonParts(null, box, entities, null);
this.getEntities((Entity)null, box, entities, null);
for (int i = 0, len = entities.size(); i < len; ++i) {
action.accept(entities.get(i));
}
@@ -218,7 +218,7 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
@Override
public <U extends Entity> void get(final EntityTypeTest<Entity, U> filter, final AABB box, final AbortableIterationConsumer<U> action) {
List<Entity> entities = new ArrayList<>();
this.getEntitiesWithoutDragonParts(null, box, entities, null);
this.getEntities((Entity)null, box, entities, null);
for (int i = 0, len = entities.size(); i < len; ++i) {
final U casted = filter.tryCast(entities.get(i));
if (casted != null && action.accept(casted).shouldAbort()) {
@@ -560,45 +560,6 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
return slices;
}
public void getEntitiesWithoutDragonParts(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate) {
final int minChunkX = (Mth.floor(box.minX) - 2) >> 4;
final int minChunkZ = (Mth.floor(box.minZ) - 2) >> 4;
final int maxChunkX = (Mth.floor(box.maxX) + 2) >> 4;
final int maxChunkZ = (Mth.floor(box.maxZ) + 2) >> 4;
final int minRegionX = minChunkX >> REGION_SHIFT;
final int minRegionZ = minChunkZ >> REGION_SHIFT;
final int maxRegionX = maxChunkX >> REGION_SHIFT;
final int maxRegionZ = maxChunkZ >> REGION_SHIFT;
for (int currRegionZ = minRegionZ; currRegionZ <= maxRegionZ; ++currRegionZ) {
final int minZ = currRegionZ == minRegionZ ? minChunkZ & REGION_MASK : 0;
final int maxZ = currRegionZ == maxRegionZ ? maxChunkZ & REGION_MASK : REGION_MASK;
for (int currRegionX = minRegionX; currRegionX <= maxRegionX; ++currRegionX) {
final ChunkSlicesRegion region = this.getRegion(currRegionX, currRegionZ);
if (region == null) {
continue;
}
final int minX = currRegionX == minRegionX ? minChunkX & REGION_MASK : 0;
final int maxX = currRegionX == maxRegionX ? maxChunkX & REGION_MASK : REGION_MASK;
for (int currZ = minZ; currZ <= maxZ; ++currZ) {
for (int currX = minX; currX <= maxX; ++currX) {
final ChunkEntitySlices chunk = region.get(currX | (currZ << REGION_SHIFT));
if (chunk == null || !chunk.status.isOrAfter(FullChunkStatus.FULL)) {
continue;
}
chunk.getEntitiesWithoutDragonParts(except, box, into, predicate);
}
}
}
}
}
public void getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate) {
final int minChunkX = (Mth.floor(box.minX) - 2) >> 4;
final int minChunkZ = (Mth.floor(box.minZ) - 2) >> 4;
@@ -759,48 +720,6 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
//////// Limited ////////
public void getEntitiesWithoutDragonParts(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
final int maxCount) {
final int minChunkX = (Mth.floor(box.minX) - 2) >> 4;
final int minChunkZ = (Mth.floor(box.minZ) - 2) >> 4;
final int maxChunkX = (Mth.floor(box.maxX) + 2) >> 4;
final int maxChunkZ = (Mth.floor(box.maxZ) + 2) >> 4;
final int minRegionX = minChunkX >> REGION_SHIFT;
final int minRegionZ = minChunkZ >> REGION_SHIFT;
final int maxRegionX = maxChunkX >> REGION_SHIFT;
final int maxRegionZ = maxChunkZ >> REGION_SHIFT;
for (int currRegionZ = minRegionZ; currRegionZ <= maxRegionZ; ++currRegionZ) {
final int minZ = currRegionZ == minRegionZ ? minChunkZ & REGION_MASK : 0;
final int maxZ = currRegionZ == maxRegionZ ? maxChunkZ & REGION_MASK : REGION_MASK;
for (int currRegionX = minRegionX; currRegionX <= maxRegionX; ++currRegionX) {
final ChunkSlicesRegion region = this.getRegion(currRegionX, currRegionZ);
if (region == null) {
continue;
}
final int minX = currRegionX == minRegionX ? minChunkX & REGION_MASK : 0;
final int maxX = currRegionX == maxRegionX ? maxChunkX & REGION_MASK : REGION_MASK;
for (int currZ = minZ; currZ <= maxZ; ++currZ) {
for (int currX = minX; currX <= maxX; ++currX) {
final ChunkEntitySlices chunk = region.get(currX | (currZ << REGION_SHIFT));
if (chunk == null || !chunk.status.isOrAfter(FullChunkStatus.FULL)) {
continue;
}
if (chunk.getEntitiesWithoutDragonParts(except, box, into, predicate, maxCount)) {
return;
}
}
}
}
}
}
public void getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
final int maxCount) {
final int minChunkX = (Mth.floor(box.minX) - 2) >> 4;