Skip to content

Commit

Permalink
MixinWorld : Fix cannot be cast to EntityLiving
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin452 committed Jan 19, 2024
1 parent da37935 commit e4ed451
Showing 1 changed file with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -899,34 +899,9 @@ public void spawnParticle(String particleName, double x, double y, double z, dou

@Overwrite
public int countEntities(Class<?> entityClass) {
AtomicInteger count = optimizationsAndTweaks$initializeCounter();
optimizationsAndTweaks$processEntityList(entityClass, count);
return optimizationsAndTweaks$getCount(count);

}
@Unique
AtomicInteger optimizationsAndTweaks$initializeCounter() {
return new AtomicInteger(0);
}
@Unique
void optimizationsAndTweaks$processEntityList(Class<?> entityClass, AtomicInteger count) {
this.loadedEntityList.forEach(entity -> {
if(optimizationsAndTweaks$matchesEntity(entity, entityClass)) {
count.incrementAndGet();
}
});
}
@Unique
boolean optimizationsAndTweaks$matchesEntity(Object entity, Class<?> entityClass) {
return entityClass.isInstance(entity) && !optimizationsAndTweaks$isDespawned((EntityLiving)entity);
}
@Unique
boolean optimizationsAndTweaks$isDespawned(EntityLiving entity) {
return entity.isNoDespawnRequired();
}
@Unique
int optimizationsAndTweaks$getCount(AtomicInteger count) {
return count.get();
return (int) this.loadedEntityList.stream()
.filter(entity -> entityClass.isInstance(entity) && (!(entity instanceof EntityLiving) || !((EntityLiving) entity).isNoDespawnRequired()))
.count();
}

@Inject(method = "tick", at = @At(value = "INVOKE"))
Expand Down

0 comments on commit e4ed451

Please sign in to comment.