|
1 | 1 | package birsy.clinker.common.world.entity.system.chainlightning; |
2 | 2 |
|
3 | 3 | import birsy.clinker.client.particle.ChainLightningParticle; |
| 4 | +import net.minecraft.Util; |
4 | 5 | import net.minecraft.core.particles.ParticleTypes; |
5 | 6 | import net.minecraft.server.level.ServerLevel; |
6 | 7 | import net.minecraft.util.Mth; |
7 | 8 | import net.minecraft.world.entity.Entity; |
8 | 9 | import net.minecraft.world.entity.LivingEntity; |
| 10 | +import net.minecraft.world.entity.ai.behavior.ShufflingList; |
9 | 11 | import net.minecraft.world.phys.Vec3; |
10 | 12 | import net.tslat.smartbrainlib.util.EntityRetrievalUtil; |
| 13 | +import net.tslat.smartbrainlib.util.RandomUtil; |
11 | 14 |
|
12 | 15 | import java.util.*; |
13 | 16 | import java.util.function.BiConsumer; |
@@ -57,10 +60,10 @@ void tick() { |
57 | 60 | if (conductionRadius <= 0.01) return true; |
58 | 61 |
|
59 | 62 | List<Entity> nearbyEntities = EntityRetrievalUtil.getEntities(entity, conductionRadius, e -> !visitedEntities.contains(e)); |
60 | | - nearbyEntities.sort(Comparator.comparingDouble(e -> e.distanceTo(entity))); |
61 | 63 |
|
62 | | - // we can shock a maximum of five neighbors. |
63 | | - int entitiesToIterate = Math.min(5, nearbyEntities.size()); |
| 64 | + int maximumShockableNeighbors = 3; |
| 65 | + if (nearbyEntities.size() > maximumShockableNeighbors) Util.shuffle(nearbyEntities, level.getRandom()); |
| 66 | + int entitiesToIterate = Math.min(maximumShockableNeighbors, nearbyEntities.size()); |
64 | 67 | for (int i = 0; i < entitiesToIterate; i++) { |
65 | 68 | Entity nearby = nearbyEntities.get(i); |
66 | 69 | entitiesToShock.add(nearby); |
|
0 commit comments