diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java index 44eadad2b9..075ce7cb0d 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java @@ -11,6 +11,7 @@ package vazkii.botania.common.brew.potion; import java.util.List; +import java.util.stream.Collectors; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.player.EntityPlayer; @@ -31,17 +32,20 @@ public PotionBloodthirst() { super(ConfigHandler.potionIDBloodthirst, LibPotionNames.BLOODTHIRST, false, 0xC30000, 3); MinecraftForge.EVENT_BUS.register(this); } - @SubscribeEvent public void onSpawn(LivingSpawnEvent.CheckSpawn event) { - if(event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { - List players = event.world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(event.x - RANGE, event.y - RANGE, event.z - RANGE, event.x + RANGE, event.y + RANGE, event.z + RANGE)); - for(EntityPlayer player : players) + if (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { + double rangeSq = RANGE * RANGE; + List players = (List) event.world.playerEntities.stream() + .filter(player -> ((EntityPlayer) player).getDistanceSq(event.x, event.y, event.z) <= rangeSq) + .map(player -> (EntityPlayer) player) + .collect(Collectors.toList()); + for (EntityPlayer player : players) { if(hasEffect(player) && !hasEffect(player, ModPotions.emptiness)) { event.setResult(Result.ALLOW); return; } + } } } - } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java index 6d2b77ea0c..3217a3d43c 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java @@ -11,6 +11,7 @@ package vazkii.botania.common.brew.potion; import java.util.List; +import java.util.stream.Collectors; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.player.EntityPlayer; @@ -33,14 +34,18 @@ public PotionEmptiness() { @SubscribeEvent public void onSpawn(LivingSpawnEvent.CheckSpawn event) { - if(event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { - List players = event.world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(event.x - RANGE, event.y - RANGE, event.z - RANGE, event.x + RANGE, event.y + RANGE, event.z + RANGE)); - for(EntityPlayer player : players) - if(hasEffect(player)) { + if (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { + double rangeSq = RANGE * RANGE; + List players = (List) event.world.playerEntities.stream() + .filter(player -> ((EntityPlayer) player).getDistanceSq(event.x, event.y, event.z) <= rangeSq) + .map(player -> (EntityPlayer) player) + .collect(Collectors.toList()); + for (EntityPlayer player : players) { + if (hasEffect(player)) { event.setResult(Result.DENY); return; } + } } } - }