3
3
import net .caffeinemc .mods .lithium .common .client .ClientWorldAccessor ;
4
4
import net .caffeinemc .mods .lithium .common .entity .EntityClassGroup ;
5
5
import net .caffeinemc .mods .lithium .common .entity .pushable .EntityPushablePredicate ;
6
+ import net .caffeinemc .mods .lithium .common .services .PlatformEntityAccess ;
6
7
import net .caffeinemc .mods .lithium .common .world .chunk .ClassGroupFilterableList ;
7
8
import net .caffeinemc .mods .lithium .mixin .util .accessors .EntitySectionAccessor ;
8
9
import net .caffeinemc .mods .lithium .mixin .util .accessors .PersistentEntitySectionManagerAccessor ;
@@ -45,7 +46,7 @@ public static List<Entity> getEntitiesForCollision(EntityGetter entityView, AABB
45
46
EntitySectionStorage <Entity > cache = getEntityCacheOrNull (world );
46
47
if (cache != null ) {
47
48
Profiler .get ().incrementCounter ("getEntities" );
48
- return getEntitiesOfEntityGroup (cache , collidingEntity , EntityClassGroup .NoDragonClassGroup .BOAT_SHULKER_LIKE_COLLISION , box , null );
49
+ return getEntitiesOfEntityGroupWithoutDragonPieces (cache , collidingEntity , EntityClassGroup .NoDragonClassGroup .BOAT_SHULKER_LIKE_COLLISION , box , null );
49
50
}
50
51
}
51
52
//use vanilla code in case the shortcut is not applicable
@@ -59,7 +60,7 @@ public static List<Entity> getOtherEntitiesForCollision(EntityGetter entityView,
59
60
EntitySectionStorage <Entity > cache = getEntityCacheOrNull (world );
60
61
if (cache != null ) {
61
62
Profiler .get ().incrementCounter ("getEntities" );
62
- return getEntitiesOfEntityGroup (cache , collidingEntity , EntityClassGroup .NoDragonClassGroup .BOAT_SHULKER_LIKE_COLLISION , box , entityFilter );
63
+ return getEntitiesOfEntityGroupWithoutDragonPieces (cache , collidingEntity , EntityClassGroup .NoDragonClassGroup .BOAT_SHULKER_LIKE_COLLISION , box , entityFilter );
63
64
}
64
65
}
65
66
}
@@ -73,15 +74,21 @@ public static List<Entity> getOtherEntitiesForCollision(EntityGetter entityView,
73
74
public static EntitySectionStorage <Entity > getEntityCacheOrNull (Level world ) {
74
75
if (world instanceof ClientWorldAccessor ) {
75
76
//noinspection unchecked
76
- return ((TransientEntitySectionManagerAccessor <Entity >) ((ClientWorldAccessor ) world ).lithium$getEntityManager ()).getCache ();
77
+ TransientEntitySectionManagerAccessor <Entity > entityManager = (TransientEntitySectionManagerAccessor <Entity >) ((ClientWorldAccessor ) world ).lithium$getEntityManager ();
78
+ if (entityManager != null ) {
79
+ return entityManager .getCache ();
80
+ }
77
81
} else if (world instanceof ServerLevelAccessor ) {
78
82
//noinspection unchecked
79
- return ((PersistentEntitySectionManagerAccessor <Entity >) ((ServerLevelAccessor ) world ).getEntityManager ()).getCache ();
83
+ PersistentEntitySectionManagerAccessor <Entity > entityManager = (PersistentEntitySectionManagerAccessor <Entity >) ((ServerLevelAccessor ) world ).getEntityManager ();
84
+ if (entityManager != null ) {
85
+ return entityManager .getCache ();
86
+ }
80
87
}
81
88
return null ;
82
89
}
83
90
84
- public static List <Entity > getEntitiesOfEntityGroup (EntitySectionStorage <Entity > cache , Entity collidingEntity , EntityClassGroup . NoDragonClassGroup entityClassGroup , AABB box , Predicate <? super Entity > entityFilter ) {
91
+ public static ArrayList <Entity > getEntitiesOfEntityGroupWithoutDragonPieces (EntitySectionStorage <Entity > cache , Entity excludedEntity , EntityClassGroup entityClassGroup , AABB box , Predicate <? super Entity > entityFilter ) {
85
92
ArrayList <Entity > entities = new ArrayList <>();
86
93
cache .forEachAccessibleNonEmptySection (box , section -> {
87
94
//noinspection unchecked
@@ -90,8 +97,7 @@ public static List<Entity> getEntitiesOfEntityGroup(EntitySectionStorage<Entity>
90
97
Collection <Entity > entitiesOfType = ((ClassGroupFilterableList <Entity >) allEntities ).lithium$getAllOfGroupType (entityClassGroup );
91
98
if (!entitiesOfType .isEmpty ()) {
92
99
for (Entity entity : entitiesOfType ) {
93
- if (entity .getBoundingBox ().intersects (box ) && !entity .isSpectator () && entity != collidingEntity && (entityFilter == null || entityFilter .test (entity ))) {
94
- //skip the dragon piece check without issues by only allowing EntityClassGroup.NoDragonClassGroup as type
100
+ if (entity .getBoundingBox ().intersects (box ) && !entity .isSpectator () && entity != excludedEntity && (entityFilter == null || entityFilter .test (entity ))) {
95
101
entities .add (entity );
96
102
}
97
103
}
@@ -101,6 +107,14 @@ public static List<Entity> getEntitiesOfEntityGroup(EntitySectionStorage<Entity>
101
107
return entities ;
102
108
}
103
109
110
+ public static List <Entity > getEntitiesOfEntityGroupPlusDragonPieces (Level level , EntitySectionStorage <Entity > cache , Entity excludedEntity , EntityClassGroup entityClassGroup , AABB box , Predicate <? super Entity > entityFilter ) {
111
+ ArrayList <Entity > entities = getEntitiesOfEntityGroupWithoutDragonPieces (cache , excludedEntity , entityClassGroup , box , entityFilter );
112
+ if (!level .dragonParts ().isEmpty ()) {
113
+ PlatformEntityAccess .INSTANCE .addEnderDragonParts (level , excludedEntity , box , entityFilter , entities );
114
+ }
115
+ return entities ;
116
+ }
117
+
104
118
public static List <Entity > getPushableEntities (Level world , EntitySectionStorage <Entity > cache , Entity except , AABB box , EntityPushablePredicate <? super Entity > entityPushablePredicate ) {
105
119
ArrayList <Entity > entities = new ArrayList <>();
106
120
cache .forEachAccessibleNonEmptySection (box , section -> ((ClimbingMobCachingSection ) section ).lithium$collectPushableEntities (world , except , box , entityPushablePredicate , entities ));
0 commit comments