From 05b905b988e7b6553ec31fdfef0293fb5b03dc6d Mon Sep 17 00:00:00 2001 From: Electroblob <35599699+Electroblob77@users.noreply.github.com> Date: Tue, 5 Jun 2018 14:12:33 +0100 Subject: [PATCH] Fix light level detection for petrified creatures breaking out --- .../wizardry/tileentity/TileEntityStatue.java | 4 ++-- .../wizardry/util/WizardryUtilities.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java index 06866ecc..f93c7851 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityStatue.java @@ -1,5 +1,6 @@ package electroblob.wizardry.tileentity; +import electroblob.wizardry.util.WizardryUtilities; import net.minecraft.block.Block; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; @@ -107,8 +108,7 @@ public class TileEntityStatue extends TileEntity implements ITickable { // Breaks the block at light levels of 7 or below, with a higher chance the lower the light level. // The chance is (8 - light level)/12, so at light 0 the chance is 3/4 and at light 7 the chance is 1/12. if(!this.world.isRemote && this.timer % 200 == 0 && this.timer > lifetime && !this.isIce && this.position == 1){ - // TESTME: There are about 10 different light-related methods in world now... is this the right one? - if(this.world.getLight(pos) < this.world.rand.nextInt(12) - 3){ + if(WizardryUtilities.getLightLevel(world, pos) < this.world.rand.nextInt(12) - 3){ // This is all that is needed because destroyBlock invokes the breakBlock function in // BlockPetrifiedStone // and that function handles all the spawning and stuff. diff --git a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java b/src/main/java/electroblob/wizardry/util/WizardryUtilities.java index e919603c..41301101 100644 --- a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java +++ b/src/main/java/electroblob/wizardry/util/WizardryUtilities.java @@ -98,6 +98,26 @@ public final class WizardryUtilities { // SECTION Block/Entity/World Utilities // =============================================================================================================== + /** + * Returns the actual light level, taking natural light (skylight) and artificial light (block light) into account. + * This uses the same logic as mob spawning. + * + * @return The light level, from 0 (pitch darkness) to 15 (full daylight/at a torch). + */ + public static int getLightLevel(World world, BlockPos pos){ + + int i = world.getLightFromNeighbors(pos); + + if(world.isThundering()){ + int j = world.getSkylightSubtracted(); + world.setSkylightSubtracted(10); + i = world.getLightFromNeighbors(pos); + world.setSkylightSubtracted(j); + } + + return i; + } + /** * Returns whether the block at the given coordinates can be replaced by another one (works as if a block is being * placed by a player). True for air, liquids, vines, tall grass and snow layers but not for flowers, signs etc.