diff --git a/src/main/java/mekanism/common/tile/machine/TileEntityDigitalMiner.java b/src/main/java/mekanism/common/tile/machine/TileEntityDigitalMiner.java index 3570735d39c..57e6a2b0fd9 100644 --- a/src/main/java/mekanism/common/tile/machine/TileEntityDigitalMiner.java +++ b/src/main/java/mekanism/common/tile/machine/TileEntityDigitalMiner.java @@ -21,11 +21,13 @@ import mekanism.api.Action; import mekanism.api.AutomationType; import mekanism.api.IContentsListener; +import mekanism.api.MekanismAPI; import mekanism.api.RelativeSide; import mekanism.api.SerializationConstants; import mekanism.api.Upgrade; import mekanism.api.inventory.IInventorySlot; import mekanism.common.CommonWorldTickHandler; +import mekanism.common.Mekanism; import mekanism.common.attachments.FilterAware; import mekanism.common.attachments.OverflowAware; import mekanism.common.base.MekFakePlayer; @@ -473,9 +475,8 @@ private void tryMineBlock() { target = chunk; } BlockPos pos = getOffsetForIndex(startingPos, diameter, index); - Optional blockState = WorldUtils.getBlockState(level, pos); - if (blockState.isPresent()) { - BlockState state = blockState.get(); + BlockState state = WorldUtils.getBlockStateIfLoaded(level, pos); + if (state != null) { if (!state.isAir() && !state.is(MekanismTags.Blocks.MINER_BLACKLIST)) { //Make sure the block is loaded and is not air, and is not in the blacklist of blocks the miner can break // then check if the block matches one of our filters @@ -517,8 +518,14 @@ private void tryMineBlock() { } //Exit out. We either mined the block or don't have room so there is no reason to continue checking return; + } else if (MekanismAPI.debug) { + Mekanism.logger.error("Filter failed or can't mine: {} @ {} {}", state, getWorldNN().dimension().location(), pos); } + } else if (MekanismAPI.debug) { + Mekanism.logger.error("State was air or was blacklisted (mismatch between search and runtime): {} @ {} {}", state, getWorldNN().dimension().location(), pos); } + } else if (MekanismAPI.debug) { + Mekanism.logger.debug("Block was not loaded {} {}", getWorldNN().dimension().location(), pos); } //If we failed to mine the block, because it isn't loaded, is air, or we shouldn't mine it // remove the block from our list of blocks to mine, and reduce the number of blocks we have to mine @@ -579,6 +586,9 @@ private boolean canMine(BlockState state, BlockPos pos) { MekFakePlayer dummy = MekFakePlayer.setupFakePlayer((ServerLevel) level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()); dummy.setEmulatingUUID(getOwnerUUID());//pretend to be the owner boolean canMine = !NeoForge.EVENT_BUS.post(new BlockEvent.BreakEvent(level, pos, state, dummy)).isCanceled(); + if (MekanismAPI.debug) { + Mekanism.logger.debug("Denied mining block: {} @ {} {}", state, level.dimension().location(), pos); + } dummy.cleanupFakePlayer((ServerLevel) level); return canMine; } diff --git a/src/main/java/mekanism/common/util/WorldUtils.java b/src/main/java/mekanism/common/util/WorldUtils.java index 91048f9093a..ef65ab02cd9 100644 --- a/src/main/java/mekanism/common/util/WorldUtils.java +++ b/src/main/java/mekanism/common/util/WorldUtils.java @@ -256,6 +256,23 @@ public static Optional getBlockState(@Nullable BlockGetter world, @N return Optional.of(world.getBlockState(pos)); } + /** + * Gets a blockstate if the location is loaded + * + * @param world world + * @param pos position + * + * @return the blockstate if found, null if not loaded + */ + @Nullable + public static BlockState getBlockStateIfLoaded(@Nullable BlockGetter world, @NotNull BlockPos pos) { + if (!isBlockLoaded(world, pos)) { + //If the world is null, or it is a world reader and the block is not loaded, return empty + return null; + } + return world.getBlockState(pos); + } + /** * Gets a fluidstate if the location is loaded by getting the chunk from the passed in cache of chunks rather than directly using the world. We then store our chunk * we found back in the cache to more quickly be able to look up chunks if we are doing lots of lookups at once (For example multiblock structure validation)