Skip to content

Commit a8ae6b9

Browse files
committed
Fixed thread locks cuz of heal event
1 parent 48e0937 commit a8ae6b9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/main/java/it/hurts/sskirillss/relics/effects/AntiHealEffect.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.hurts.sskirillss.relics.init.EffectRegistry;
44
import it.hurts.sskirillss.relics.utils.Reference;
5+
import net.minecraft.core.BlockPos;
56
import net.minecraft.world.effect.MobEffect;
67
import net.minecraft.world.effect.MobEffectCategory;
78
import net.minecraft.world.entity.LivingEntity;
@@ -18,7 +19,17 @@ public AntiHealEffect() {
1819
public static class Events {
1920
@SubscribeEvent
2021
public static void onLivingHeal(LivingHealEvent event) {
21-
LivingEntity entity = event.getEntity();
22+
var entity = event.getEntity();
23+
var level = entity.level();
24+
25+
var box = entity.getBoundingBox();
26+
27+
var min = BlockPos.containing(Math.floor(box.minX) - 1, Math.floor(box.minY), Math.floor(box.minZ) - 1);
28+
var max = BlockPos.containing(Math.floor(box.maxX) + 1, Math.floor(entity.getEyeY()) + 1, Math.floor(box.maxZ) + 1);
29+
30+
// WHY!? (cuz of thread locks lol)
31+
if (!level.hasChunksAt(min, max))
32+
return;
2233

2334
if (entity.hasEffect(EffectRegistry.ANTI_HEAL.get()))
2435
event.setCanceled(true);

src/main/java/it/hurts/sskirillss/relics/items/relics/necklace/HolyLocketItem.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.minecraft.client.renderer.entity.ItemRenderer;
3838
import net.minecraft.client.renderer.entity.RenderLayerParent;
3939
import net.minecraft.client.renderer.texture.OverlayTexture;
40+
import net.minecraft.core.BlockPos;
4041
import net.minecraft.server.level.ServerLevel;
4142
import net.minecraft.server.level.ServerPlayer;
4243
import net.minecraft.util.Mth;
@@ -276,18 +277,29 @@ public static void onLivingHurt(LivingHurtEvent event) {
276277

277278
@SubscribeEvent
278279
public static void onLivingHeal(LivingHealEvent event) {
280+
var entity = event.getEntity();
281+
var level = entity.level();
282+
283+
var box = entity.getBoundingBox();
284+
285+
var min = BlockPos.containing(Math.floor(box.minX) - 1, Math.floor(box.minY), Math.floor(box.minZ) - 1);
286+
var max = BlockPos.containing(Math.floor(box.maxX) + 1, Math.floor(entity.getEyeY()) + 1, Math.floor(box.maxZ) + 1);
287+
288+
// WHY!? (cuz of thread locks lol)
289+
if (!level.hasChunksAt(min, max))
290+
return;
291+
279292
if (event.getAmount() <= 0.5F)
280293
return;
281294

282295
if (event.getEntity() instanceof Player player) {
283296
ItemStack stack = EntityUtils.findEquippedCurio(player, ItemRegistry.HOLY_LOCKET.get());
284-
Level level = player.getCommandSenderWorld();
285297

286298
if (!(stack.getItem() instanceof HolyLocketItem relic) || NBTUtils.getBoolean(stack, TAG_TOGGLED, true))
287299
return;
288300

289301
for (LivingEntity target : level.getEntitiesOfClass(LivingEntity.class, player.getBoundingBox().inflate(relic.getAbilityValue(stack, "belief", "radius"))).stream()
290-
.filter(player::hasLineOfSight).sorted(Comparator.comparing(entity -> entity.position().distanceTo(player.position()))).limit((int) relic.getAbilityValue(stack, "belief", "count")).toList()) {
302+
.filter(player::hasLineOfSight).sorted(Comparator.comparing(possibleTarget -> possibleTarget.position().distanceTo(player.position()))).limit((int) relic.getAbilityValue(stack, "belief", "count")).toList()) {
291303
if (target.getStringUUID().equals(player.getStringUUID()))
292304
continue;
293305

@@ -309,9 +321,6 @@ public static void onLivingHeal(LivingHealEvent event) {
309321
relic.addCharge(stack, 1);
310322
}
311323
} else {
312-
LivingEntity entity = event.getEntity();
313-
Level level = entity.getCommandSenderWorld();
314-
315324
for (ServerPlayer playerSearched : level.getEntitiesOfClass(ServerPlayer.class, event.getEntity().getBoundingBox().inflate(32))) {
316325
ItemStack stack = EntityUtils.findEquippedCurio(playerSearched, ItemRegistry.HOLY_LOCKET.get());
317326

0 commit comments

Comments
 (0)