Skip to content

Commit

Permalink
Add missing entity predicate test when getting mob collisions
Browse files Browse the repository at this point in the history
Affected auto-jumping on dead shulkers (easiest demo found so far)
Probably affected some modded entities #578
  • Loading branch information
2No2Name committed Nov 11, 2024
1 parent 8ed54ef commit a12c844
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public static class NoDragonClassGroup extends EntityClassGroup {
public static final NoDragonClassGroup BOAT_SHULKER_LIKE_COLLISION; //aka entities that other entities will do block-like collisions with when moving

static {
String remapped_isCollidable = PlatformMappingInformation.INSTANCE.mapMethodName("intermediary", "net.minecraft.class_1297", "method_30948", "()Z", "canBeCollidedWith");
String remapped_canBeCollidedWith = PlatformMappingInformation.INSTANCE.mapMethodName("intermediary", "net.minecraft.class_1297", "method_30948", "()Z", "canBeCollidedWith");
BOAT_SHULKER_LIKE_COLLISION = new NoDragonClassGroup(
(Class<?> entityClass) -> ReflectionUtil.hasMethodOverride(entityClass, Entity.class, true, remapped_isCollidable));
(Class<?> entityClass) -> ReflectionUtil.hasMethodOverride(entityClass, Entity.class, true, remapped_canBeCollidedWith));

if ((!BOAT_SHULKER_LIKE_COLLISION.contains(Shulker.class))) {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ public static List<Entity> getEntitiesForCollision(EntityGetter entityView, AABB
EntitySectionStorage<Entity> cache = getEntityCacheOrNull(world);
if (cache != null) {
Profiler.get().incrementCounter("getEntities");
return getEntitiesOfClassGroup(cache, collidingEntity, EntityClassGroup.NoDragonClassGroup.BOAT_SHULKER_LIKE_COLLISION, box);
return getEntitiesOfClassGroup(cache, collidingEntity, EntityClassGroup.NoDragonClassGroup.BOAT_SHULKER_LIKE_COLLISION, box, null);
}
}
//use vanilla code in case the shortcut is not applicable
// due to the reference entity implementing special collision or the mixin being disabled in the config
return entityView.getEntities(collidingEntity, box);
}

public static List<Entity> getOtherEntitiesForCollision(EntityGetter entityView, AABB box, @Nullable Entity collidingEntity, Predicate<? super Entity> entityPredicate) {
public static List<Entity> getOtherEntitiesForCollision(EntityGetter entityView, AABB box, @Nullable Entity collidingEntity, Predicate<? super Entity> entityFilter) {
if (!CUSTOM_TYPE_FILTERABLE_LIST_DISABLED && entityView instanceof Level world) {
if (collidingEntity == null || !EntityClassGroup.CUSTOM_COLLIDE_LIKE_MINECART_BOAT_WINDCHARGE.contains(collidingEntity.getClass())) {
EntitySectionStorage<Entity> cache = getEntityCacheOrNull(world);
if (cache != null) {
Profiler.get().incrementCounter("getEntities");
return getEntitiesOfClassGroup(cache, collidingEntity, EntityClassGroup.NoDragonClassGroup.BOAT_SHULKER_LIKE_COLLISION, box);
return getEntitiesOfClassGroup(cache, collidingEntity, EntityClassGroup.NoDragonClassGroup.BOAT_SHULKER_LIKE_COLLISION, box, entityFilter);
}
}
}
//use vanilla code in case the shortcut is not applicable
// due to the reference entity implementing special collision or the mixin being disabled in the config
return entityView.getEntities(collidingEntity, box, entityPredicate);
return entityView.getEntities(collidingEntity, box, entityFilter);
}


Expand All @@ -81,7 +81,7 @@ public static EntitySectionStorage<Entity> getEntityCacheOrNull(Level world) {
return null;
}

public static List<Entity> getEntitiesOfClassGroup(EntitySectionStorage<Entity> cache, Entity collidingEntity, EntityClassGroup.NoDragonClassGroup entityClassGroup, AABB box) {
public static List<Entity> getEntitiesOfClassGroup(EntitySectionStorage<Entity> cache, Entity collidingEntity, EntityClassGroup.NoDragonClassGroup entityClassGroup, AABB box, Predicate<? super Entity> entityFilter) {
ArrayList<Entity> entities = new ArrayList<>();
cache.forEachAccessibleNonEmptySection(box, section -> {
//noinspection unchecked
Expand All @@ -90,7 +90,7 @@ public static List<Entity> getEntitiesOfClassGroup(EntitySectionStorage<Entity>
Collection<Entity> entitiesOfType = ((ClassGroupFilterableList<Entity>) allEntities).lithium$getAllOfGroupType(entityClassGroup);
if (!entitiesOfType.isEmpty()) {
for (Entity entity : entitiesOfType) {
if (entity.getBoundingBox().intersects(box) && !entity.isSpectator() && entity != collidingEntity) {
if (entity.getBoundingBox().intersects(box) && !entity.isSpectator() && entity != collidingEntity && (entityFilter == null || entityFilter.test(entity))) {
//skip the dragon piece check without issues by only allowing EntityClassGroup.NoDragonClassGroup as type
entities.add(entity);
}
Expand Down

0 comments on commit a12c844

Please sign in to comment.