use of org.spongepowered.api.world.teleport.TeleportHelperFilter in project SpongeCommon by SpongePowered.
the class SpongeTeleportHelper method getSafeLocation.
@Override
public Optional<Location<World>> getSafeLocation(Location<World> location, int height, int width, int distanceToDrop, TeleportHelperFilter filter, TeleportHelperFilter... additionalFilters) {
final World world = location.getExtent();
final Set<TeleportHelperFilter> filters = Sets.newHashSet(additionalFilters);
filters.add(filter);
if (SpongeImpl.getGlobalConfig().getConfig().getTeleportHelper().isForceBlacklistOn()) {
// Always force this into the set if the user has requested it.
filters.add(TeleportHelperFilters.CONFIG);
}
IMixinChunkProviderServer chunkProviderServer = (IMixinChunkProviderServer) ((net.minecraft.world.WorldServer) world).getChunkProvider();
chunkProviderServer.setForceChunkRequests(true);
try {
// Get the vectors to check, and get the block types with them.
// The vectors should be sorted by distance from the centre of the checking region, so
// this makes it easier to try to get close, because we can just iterate and get progressively further out.
Optional<Vector3i> result = getSafeLocation(world, getBlockLocations(location, height, width), distanceToDrop, filters);
return result.map(vector3i -> new Location<>(world, vector3i.toDouble().add(0.5, 0, 0.5)));
} finally {
// Just in case some exception occurs, we want this to disable again.
chunkProviderServer.setForceChunkRequests(false);
}
}
Aggregations