From 7ad82f0bb270b8f00953d91bbd872c3071373454 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 26 Dec 2021 10:48:01 +0200 Subject: [PATCH] Fixed crash with spellcast entities accessing lighting buffers when they mustn't (TODO: make this better somehow) --- .../unicopia/entity/CastSpellEntity.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java index 605dbf61..20e90914 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java @@ -4,6 +4,7 @@ import java.util.Optional; import java.util.UUID; import com.minelittlepony.unicopia.Affinity; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Levelled; import com.minelittlepony.unicopia.ability.magic.SpellContainer; @@ -84,13 +85,19 @@ public class CastSpellEntity extends Entity implements Caster { if (world.isClient) { BlockPos currentPos = getBlockPos(); - world.getLightingProvider().addLightSource(currentPos, 11); + if (world.isChunkLoaded(currentPos)) { + try { + world.getLightingProvider().addLightSource(currentPos, 11); - if (lastPos != null && !currentPos.equals(lastPos)) { - world.getLightingProvider().checkBlock(lastPos); + if (lastPos != null && !currentPos.equals(lastPos)) { + world.getLightingProvider().checkBlock(lastPos); + } + } catch (Exception e) { + Unicopia.LOGGER.error("Error updating lighting", e); + } + + lastPos = currentPos; } - - lastPos = currentPos; } LivingEntity master = getMaster(); @@ -170,7 +177,6 @@ public class CastSpellEntity extends Entity implements Caster { dataTracker.get(SPELL).ifPresent(spellId -> { tag.putUuid("spellId", spellId); }); - } @Override