If we are still in this world and dimension, return player feet, otherwise return most recently modified chunk
()
| 206 | * If we are still in this world and dimension, return player feet, otherwise return most recently modified chunk |
| 207 | */ |
| 208 | private BlockPos guessPosition() { |
| 209 | for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { |
| 210 | IWorldData data = ibaritone.getWorldProvider().getCurrentWorld(); |
| 211 | if (data != null && data.getCachedWorld() == this && ibaritone.getPlayerContext().player() != null) { |
| 212 | return ibaritone.getPlayerContext().playerFeet(); |
| 213 | } |
| 214 | } |
| 215 | CachedChunk mostRecentlyModified = null; |
| 216 | for (CachedRegion region : allRegions()) { |
| 217 | if (region == null) { |
| 218 | continue; |
| 219 | } |
| 220 | CachedChunk ch = region.mostRecentlyModified(); |
| 221 | if (ch == null) { |
| 222 | continue; |
| 223 | } |
| 224 | if (mostRecentlyModified == null || mostRecentlyModified.cacheTimestamp < ch.cacheTimestamp) { |
| 225 | mostRecentlyModified = ch; |
| 226 | } |
| 227 | } |
| 228 | if (mostRecentlyModified == null) { |
| 229 | return new BlockPos(0, 0, 0); |
| 230 | } |
| 231 | return new BlockPos((mostRecentlyModified.x << 4) + 8, 0, (mostRecentlyModified.z << 4) + 8); |
| 232 | } |
| 233 | |
| 234 | private synchronized List<CachedRegion> allRegions() { |
| 235 | return new ArrayList<>(this.cachedRegions.values()); |
no test coverage detected