Skip to content

Commit

Permalink
add some debugging for Serhan's digital miner
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Sep 2, 2024
1 parent b2072ca commit acfba9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -473,9 +475,8 @@ private void tryMineBlock() {
target = chunk;
}
BlockPos pos = getOffsetForIndex(startingPos, diameter, index);
Optional<BlockState> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/mekanism/common/util/WorldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ public static Optional<BlockState> 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)
Expand Down

0 comments on commit acfba9f

Please sign in to comment.